1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-25 06:03:40 +03:00

Merge pull request #25602 from fbuihuu/fix-TEST-73-LOCALE

localed: reload PID1 configuration after modifying /etc/locale.conf
This commit is contained in:
Yu Watanabe 2022-12-15 17:47:05 +09:00 committed by GitHub
commit 62650f4258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 12 deletions

View File

@ -32,7 +32,7 @@
#include "strv.h"
#include "user-util.h"
static int locale_update_system_manager(sd_bus *bus, char **l_set, char **l_unset) {
static int reload_system_manager(sd_bus *bus) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int r;
@ -43,21 +43,13 @@ static int locale_update_system_manager(sd_bus *bus, char **l_set, char **l_unse
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"UnsetAndSetEnvironment");
if (r < 0)
return bus_log_create_error(r);
r = sd_bus_message_append_strv(m, l_unset);
if (r < 0)
return bus_log_create_error(r);
r = sd_bus_message_append_strv(m, l_set);
"Reload");
if (r < 0)
return bus_log_create_error(r);
r = sd_bus_call(bus, m, 0, &error, NULL);
if (r < 0)
return log_error_errno(r, "Failed to update the manager environment: %s", bus_error_message(&error, r));
return log_error_errno(r, "Failed to reload system manager: %s", bus_error_message(&error, r));
return 0;
}
@ -393,7 +385,11 @@ static int method_set_locale(sd_bus_message *m, void *userdata, sd_bus_error *er
return sd_bus_error_set_errnof(error, r, "Failed to set locale: %m");
}
(void) locale_update_system_manager(sd_bus_message_get_bus(m), l_set, l_unset);
/* Since we just updated the locale configuration file, ask the system manager to read it again to
* update its default locale settings. It's important to not use UnsetAndSetEnvironment or a similar
* method because in this case unsetting variables means restoring them to PID1 default values, which
* may be outdated, since locale.conf has just changed and PID1 hasn't read it */
(void) reload_system_manager(sd_bus_message_get_bus(m));
if (!strv_isempty(l_set)) {
_cleanup_free_ char *line = NULL;

View File

@ -92,6 +92,19 @@ test_locale() {
return
fi
# start with a known default environment and make sure to also give a
# default value to LC_CTYPE= since we're about to also set/unset it. We
# also reload PID1 configuration to make sure that PID1 environment itself
# is updated as it's not always been the case.
assert_rc 0 localectl set-locale "LANG=en_US.UTF-8" "LC_CTYPE=C"
systemctl daemon-reload
output=$(localectl)
assert_in "System Locale: LANG=en_US.UTF-8" "$output"
assert_in "LC_CTYPE=C" "$output"
output=$(systemctl show-environment)
assert_in "LANG=en_US.UTF-8" "$output"
assert_in "LC_CTYPE=C" "$output"
# warn when kernel command line has locale settings
output=$(SYSTEMD_PROC_CMDLINE="locale.LANG=C.UTF-8 locale.LC_CTYPE=ja_JP.UTF-8" localectl 2>&1)
assert_in "Warning:" "$output"