The format of locale data can be incompatible between libc versions, and
loading incompatible data can lead to 'setlocale' returning EINVAL at best
or triggering an assertion failure at worst. See
https://lists.gnu.org/archive/html/guix-devel/2015-09/msg00717.html
for background information.
To address that, this patch changes libc to honor a new 'GUIX_LOCPATH'
variable, and to look for locale data in version-specific sub-directories of
that variable. So, if GUIX_LOCPATH=/foo:/bar, locale data is searched for in
/foo/X.Y and /bar/X.Y, where X.Y is the libc version number.
That way, a single 'GUIX_LOCPATH' setting can work even if different libc
versions coexist on the system.
--- a/locale/newlocale.c
+++ b/locale/newlocale.c
@@ -30,6 +30,7 @@
/* Lock for protecting global data. */
__libc_rwlock_define (extern , __libc_setlocale_lock attribute_hidden)
+extern error_t compute_locale_search_path (char **, size_t *);
/* Use this when we come along an error. */
#define ERROR_RETURN \
@@ -48,7 +49,6 @@ __newlocale (int category_mask, const char *locale, __locale_t base)
__locale_t result_ptr;
char *locale_path;
size_t locale_path_len;
- const char *locpath_var;
int cnt;
size_t names_len;
@@ -102,17 +102,8 @@ __newlocale (int category_mask, const char *locale, __locale_t base)
locale_path = NULL;
locale_path_len = 0;
- locpath_var = getenv ("LOCPATH");
- if (locpath_var != NULL && locpath_var[0] != '\0')
- {
- if (__argz_create_sep (locpath_var, ':',
- &locale_path, &locale_path_len) != 0)
- return NULL;
-
- if (__argz_add_sep (&locale_path, &locale_path_len,
- _nl_default_locale_path, ':') != 0)
- return NULL;
- }
+ if (compute_locale_search_path (&locale_path, &locale_path_len) != 0)
+ return NULL;
/* Get the names for the locales we are interested in. We either
allow a composite name or a single name. */
diff --git a/locale/setlocale.c b/locale/setlocale.c
index ead030d..0c0e314 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -215,12 +215,65 @@ setdata (int category, struct __locale_data *data)
}
}
+/* Return in *LOCALE_PATH and *LOCALE_PATH_LEN the locale data search path as
+ a colon-separated list. Return ENOMEN on error, zero otherwise. */
+error_t
+compute_locale_search_path (char **locale_path, size_t *locale_path_len)
+{
+ char* guix_locpath_var = getenv ("GUIX_LOCPATH");
+ char *locpath_var = getenv ("LOCPATH");
+
+ if (guix_locpath_var != NULL && guix_locpath_var[0] != '\0')
+ {
+ /* Entries in 'GUIX_LOCPATH' take precedence over 'LOCPATH'. These
+ entries are systematically prefixed with "/X.Y" where "X.Y" is the
+ libc version. */
+ if (__argz_create_sep (guix_locpath_var, ':',
+ locale_path, locale_path_len) != 0
+ || __argz_suffix_entries (locale_path, locale_path_len,
+ "/" VERSION) != 0)
+ goto bail_out;
+ }
+
+ if (locpath_var != NULL && locpath_var[0] != '\0')
+ {
+ char *reg_locale_path = NULL;
+ size_t reg_locale_path_len = 0;
+
+ if (__argz_create_sep (locpath_var, ':',
+ ®_locale_path, ®_locale_path_len) != 0)
+ goto bail_out;
+
+ if (__argz_append (locale_path, locale_path_len,
+ reg_locale_path, reg_locale_path_len) != 0)
+ goto bail_out;
+
+ free (reg_locale_path);
+ }
+
+ if (*locale_path != NULL)
+ {
+ /* Append the system default locale directory. */
+ if (__argz_add_sep (locale_path, locale_path_len,
+ _nl_default_locale_path, ':') != 0)
+ goto bail_out;
+ }
+
+ return 0;
+
+ bail_out:
+ free (*locale_path);
+ *locale_path = NULL;
+ *locale_path_len = 0;
+
+ return ENOMEM;
+}
+
char *
setlocale (int category, const char *locale)
{
char *locale_path;
size_t locale_path_len;
- const char *locpath_var;
char *composite;
/* Sanity check for CATEGORY argument. */
@@ -251,17 +304,10 @@ setlocale (int category, const char *locale)
locale_path = NULL;
locale_path_len = 0;
- locpath_var = getenv ("LOCPATH");
- if (locpath_var != NULL && locpath_var[0] != '\0')
+ if (compute_locale_search_path (&locale_path, &locale_path_len) != 0)
{
- if (
index 6a6a94b7ce..f1f3c25391 100644
--- a/gnu/packages/wm.scm
+++ b/gnu/packages/wm.scm