XSupportedLocale gives false negatives due to bad default $LANG and bad locale.alias file
The xlib function XSupportedLocale uses the /usr/share/X11/locale/locale.alias file to map the string returned by setlocale to a set of locale names xlib is aware of, and returns false if it does not find one. I suspect (but have not confirmed) that it also chooses its idea of the locale’s character encoding based on the name that results from this mapping.
The default $LANG from /etc/profile is malformed (en.utf8) and is probably cruft from the uClibc days. It is not recognized by the locale.alias file, so it breaks programs that rely on xlib locale functionality.
Previously, musl ignored the locale name passed to setlocale (except for LC_MESSAGES) and just returned “C.UTF-8” as the current locale name. The locale.alias file provides a suitable mapping for this name, so everything roughly worked. With recent additions to musl’s locale functionality, the locale name passed by the application or from the environment is saved and returned by setlocale. Therefore, xlib now sees “en.utf8” and breaks.
The bad default should just be removed from /etc/profile. In the absence of any locale env vars, musl will use C.UTF-8, as desired.
But I think the locale.alias file should also be patched. Right now it maps any locale name without an explicit charset after the dot to a Latin-1 (ISO8859-1) version of the locale, which is wrong. If xlib is using the resulting name to assume Latin-1 encoding, bad things will likely happen in programs which use the X locale system/XInput.
I think locale.alias should be patched to remove all lines with explicit non-UTF-8 locale names (these are not valid) and to map all names without explicit charsets to the “.UTF-8” variant. Even better would be to remove locale.alias entirely and have xlib query nl_langinfo(CODESET) to determine the encoding rather than hard-coding assumptions about locales based on their names. This patch would be appropriate for upstreaming.
(from redmine: issue id 4428, created on 2015-07-05)
- Changesets:
- Revision ee65d272 by Natanael Copa on 2015-07-10T06:37:28Z:
main/alpine-baselayout: misc fixes
- suggest the setup-alpine command in motd
- fix sysctl location and contents
put sysctl to /etc/sysctl.d with 00 prefix so later sysctl.d files can
override it if needed.
also remove ip_forward, it default to zero in kernel, and is controlled
by iptables init.d or quagga.
- mkmntdirs: add missing header
string.h is needed for strcmp definition
- profile: remove LANG. ref #4428
- Revision 88bc7e08 by Natanael Copa on 2015-07-10T11:06:06Z:
main/alpine-baselayout: misc fixes
- suggest the setup-alpine command in motd
- fix sysctl location and contents
put sysctl to /etc/sysctl.d with 00 prefix so later sysctl.d files can
override it if needed.
also remove ip_forward, it default to zero in kernel, and is controlled
by iptables init.d or quagga.
- mkmntdirs: add missing header
string.h is needed for strcmp definition
- profile: remove LANG. ref #4428
(cherry picked from commit ee65d272cda3aee4ac47ac67433ee7853d35702a)