1diff --git a/locale/loadarchive.c b/locale/loadarchive.c
2index 452e3eb6e3..e2016a8aab 100644
3--- a/locale/loadarchive.c
4+++ b/locale/loadarchive.c
5@@ -123,6 +123,25 @@ calculate_head_size (const struct locarhead *h)
6 return MAX (namehash_end, MAX (string_end, locrectab_end));
7 }
8
9+static int
10+open_locale_archive (void)
11+{
12+ int fd = -1;
13+ char *versioned_path = secure_getenv ("LOCALE_ARCHIVE_2_27");
14+ char *path = secure_getenv ("LOCALE_ARCHIVE");
15+ if (versioned_path)
16+ fd = __open_nocancel (versioned_path, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
17+ if (path && fd < 0)
18+ fd = __open_nocancel (path, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
19+ if (fd < 0)
20+ fd = __open_nocancel("/run/current-system/sw/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE|O_CLOEXEC);
21+ if (fd < 0)
22+ fd = __open_nocancel ("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE|O_CLOEXEC);
23+ if (fd < 0)
24+ fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
25+ return fd;
26+}
27+
28
29 /* Find the locale *NAMEP in the locale archive, and return the
30 internalized data structure for its CATEGORY data. If this locale has
31@@ -202,7 +221,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
32 archmapped = &headmap;
33
34 /* The archive has never been opened. */
35- fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
36+ fd = open_locale_archive ();
37 if (fd < 0)
38 /* Cannot open the archive, for whatever reason. */
39 return NULL;
40@@ -397,8 +416,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
41 if (fd == -1)
42 {
43 struct __stat64_t64 st;
44- fd = __open_nocancel (archfname,
45- O_RDONLY|O_LARGEFILE|O_CLOEXEC);
46+ fd = open_locale_archive();
47 if (fd == -1)
48 /* Cannot open the archive, for whatever reason. */
49 return NULL;
50diff --git a/locale/programs/locale.c b/locale/programs/locale.c
51index c7ee1874e8..af20fbac3e 100644
52--- a/locale/programs/locale.c
53+++ b/locale/programs/locale.c
54@@ -632,6 +632,26 @@ nameentcmp (const void *a, const void *b)
55 }
56
57
58+static int
59+open_locale_archive (void)
60+{
61+ int fd = -1;
62+ char *versioned_path = secure_getenv ("LOCALE_ARCHIVE_2_27");
63+ char *path = secure_getenv ("LOCALE_ARCHIVE");
64+ if (versioned_path)
65+ fd = open64 (versioned_path, O_RDONLY);
66+ if (path && fd < 0)
67+ fd = open64 (path, O_RDONLY);
68+ if (fd < 0)
69+ fd = open64 ("/run/current-system/sw/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE|O_CLOEXEC);
70+ if (fd < 0)
71+ fd = open64 ("/usr/lib/locale/locale-archive", O_RDONLY);
72+ if (fd < 0)
73+ fd = open64 (ARCHIVE_NAME, O_RDONLY);
74+ return fd;
75+}
76+
77+
78 static int
79 write_archive_locales (void **all_datap, char *linebuf)
80 {
81@@ -644,7 +664,7 @@ write_archive_locales (void **all_datap, char *linebuf)
82 int fd, ret = 0;
83 uint32_t cnt;
84
85- fd = open64 (ARCHIVE_NAME, O_RDONLY);
86+ fd = open_locale_archive ();
87 if (fd < 0)
88 return 0;
89
90diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
91index 8d79a1b6d1..93118c52e3 100644
92--- a/locale/programs/locarchive.c
93+++ b/locale/programs/locarchive.c
94@@ -116,6 +116,22 @@ prepare_address_space (int fd, size_t total, size_t *reserved, int *xflags,
95 }
96
97
98+static int
99+open_locale_archive (const char * archivefname, int flags)
100+{
101+ int fd = -1;
102+ char *versioned_path = secure_getenv ("LOCALE_ARCHIVE_2_27");
103+ char *path = secure_getenv ("LOCALE_ARCHIVE");
104+ if (versioned_path)
105+ fd = open64 (versioned_path, flags);
106+ if (path && fd < 0)
107+ fd = open64 (path, flags);
108+ if (fd < 0)
109+ fd = open64 (archivefname, flags);
110+ return fd;
111+}
112+
113+
114 static void
115 create_archive (const char *archivefname, struct locarhandle *ah)
116 {
117@@ -577,7 +593,7 @@ open_archive (struct locarhandle *ah, bool readonly)
118 while (1)
119 {
120 /* Open the archive. We must have exclusive write access. */
121- fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
122+ fd = open_locale_archive (archivefname, readonly ? O_RDONLY : O_RDWR);
123 if (fd == -1)
124 {
125 /* Maybe the file does not yet exist? If we are opening