X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Flocale-setup.c;h=276deb9dc10d89d01176cb69ca0cc5bda1cce51e;hp=48b59bf4486fc60efd53f2506c2ca726d40f69a1;hb=0e7be1293fe70eed47b20f70f74a2a67fc87be17;hpb=46a2911bf2780f616396df5671dd901cc7cb54fd diff --git a/src/core/locale-setup.c b/src/core/locale-setup.c index 48b59bf44..276deb9dc 100644 --- a/src/core/locale-setup.c +++ b/src/core/locale-setup.c @@ -27,6 +27,9 @@ #include "util.h" #include "macro.h" #include "virt.h" +#include "fileio.h" +#include "strv.h" +#include "env-util.h" enum { /* We don't list LC_ALL here on purpose. People should be @@ -66,12 +69,11 @@ static const char * const variable_names[_VARIABLE_MAX] = { [VARIABLE_LC_IDENTIFICATION] = "LC_IDENTIFICATION" }; -int locale_setup(void) { - char *variables[_VARIABLE_MAX]; +int locale_setup(char ***environment) { + char **add; + char *variables[_VARIABLE_MAX] = {}; int r = 0, i; - zero(variables); - if (detect_container(NULL) <= 0) { r = parse_env_file("/proc/cmdline", WHITESPACE, "locale.LANG", &variables[VARIABLE_LANG], @@ -118,27 +120,44 @@ int locale_setup(void) { log_warning("Failed to read /etc/locale.conf: %s", strerror(-r)); } - if (!variables[VARIABLE_LANG]) { - variables[VARIABLE_LANG] = strdup("C"); - if (!variables[VARIABLE_LANG]) { + add = NULL; + for (i = 0; i < _VARIABLE_MAX; i++) { + char *s; + + if (!variables[i]) + continue; + + s = strjoin(variable_names[i], "=", variables[i], NULL); + if (!s) { + r = -ENOMEM; + goto finish; + } + + if (strv_push(&add, s) < 0) { + free(s); r = -ENOMEM; goto finish; } } - for (i = 0; i < _VARIABLE_MAX; i++) { - if (variables[i]) { - if (setenv(variable_names[i], variables[i], 1) < 0) { - r = -errno; - goto finish; - } - } else - unsetenv(variable_names[i]); + if (!strv_isempty(add)) { + char **e; + + e = strv_env_merge(2, *environment, add); + if (!e) { + r = -ENOMEM; + goto finish; + } + + strv_free(*environment); + *environment = e; } r = 0; finish: + strv_free(add); + for (i = 0; i < _VARIABLE_MAX; i++) free(variables[i]);