From 8ca9e92c742602b8bcd431001e6f5b78c28c184f Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 28 Dec 2018 07:38:36 -0500 Subject: [PATCH 1/2] Make default locale a compile time option Default to a locale that's guaranteed to exist everywhere, but let distros override this with something more exotic if they choose to. Closes #11259. --- meson.build | 6 +++++- meson_options.txt | 2 ++ src/core/locale-setup.c | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 1964b1aa87b..9ca3b72e4d5 100644 --- a/meson.build +++ b/meson.build @@ -828,6 +828,9 @@ ntp_servers = get_option('ntp-servers') conf.set_quoted('NTP_SERVERS', ntp_servers) substs.set('NTP_SERVERS', ntp_servers) +default_locale = get_option('default-locale') +conf.set_quoted('SYSTEMD_DEFAULT_LOCALE', default_locale) + conf.set_quoted('GETTEXT_PACKAGE', meson.project_name()) substs.set('SUSHELL', get_option('debug-shell')) @@ -3096,7 +3099,8 @@ status = [ 'default DNS-over-TLS mode: @0@'.format(default_dns_over_tls), 'default cgroup hierarchy: @0@'.format(default_hierarchy), 'default net.naming-scheme setting: @0@'.format(default_net_naming_scheme), - 'default KillUserProcesses setting: @0@'.format(kill_user_processes)] + 'default KillUserProcesses setting: @0@'.format(kill_user_processes), + 'default locale: @0@'.format(default_locale)] alt_dns_servers = '\n '.join(dns_servers.split(' ')) alt_ntp_servers = '\n '.join(ntp_servers.split(' ')) diff --git a/meson_options.txt b/meson_options.txt index 1423b8998e5..7a75f380f9d 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -195,6 +195,8 @@ option('default-kill-user-processes', type : 'boolean', description : 'the default value for KillUserProcesses= setting') option('gshadow', type : 'boolean', description : 'support for shadow group') +option('default-locale', type : 'string', value : 'C', + description : 'default locale used when /etc/locale.conf does not exist') option('default-dnssec', type : 'combo', description : 'default DNSSEC mode', diff --git a/src/core/locale-setup.c b/src/core/locale-setup.c index 584fb220a10..aa4a89c17ab 100644 --- a/src/core/locale-setup.c +++ b/src/core/locale-setup.c @@ -74,9 +74,9 @@ int locale_setup(char ***environment) { } if (strv_isempty(add)) { - /* If no locale is configured then default to C.UTF-8. */ + /* If no locale is configured then default to compile-time default. */ - add = strv_new("LANG=C.UTF-8"); + add = strv_new("LANG=" SYSTEMD_DEFAULT_LOCALE); if (!add) return -ENOMEM; } From 03475e2232d655e9a1c584080ca4ed592b1bd623 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 29 Dec 2018 22:00:07 +0900 Subject: [PATCH 2/2] meson: check whether C.UTF-8 exists or not and use it if exists If C.UTF-8 does not exist, then fallback to en_US.UTF-8 or C. --- meson.build | 4 ++++ meson_options.txt | 2 +- tools/choose-default-locale.sh | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 tools/choose-default-locale.sh diff --git a/meson.build b/meson.build index 9ca3b72e4d5..f74a0bf3b2d 100644 --- a/meson.build +++ b/meson.build @@ -829,6 +829,10 @@ conf.set_quoted('NTP_SERVERS', ntp_servers) substs.set('NTP_SERVERS', ntp_servers) default_locale = get_option('default-locale') +if default_locale == '' + choose_default_locale_sh = find_program('tools/choose-default-locale.sh') + default_locale = run_command(choose_default_locale_sh).stdout().strip() +endif conf.set_quoted('SYSTEMD_DEFAULT_LOCALE', default_locale) conf.set_quoted('GETTEXT_PACKAGE', meson.project_name()) diff --git a/meson_options.txt b/meson_options.txt index 7a75f380f9d..3474265bd35 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -195,7 +195,7 @@ option('default-kill-user-processes', type : 'boolean', description : 'the default value for KillUserProcesses= setting') option('gshadow', type : 'boolean', description : 'support for shadow group') -option('default-locale', type : 'string', value : 'C', +option('default-locale', type : 'string', value : '', description : 'default locale used when /etc/locale.conf does not exist') option('default-dnssec', type : 'combo', diff --git a/tools/choose-default-locale.sh b/tools/choose-default-locale.sh new file mode 100755 index 00000000000..43087980a94 --- /dev/null +++ b/tools/choose-default-locale.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +# Fedora uses C.utf8 but Debian uses C.UTF-8 +if locale -a | grep -xq -E 'C\.(utf8|UTF-8)'; then + echo 'C.UTF-8' +elif locale -a | grep -xqF 'en_US.utf8'; then + echo 'en_US.UTF-8' +else + echo 'C' +fi