1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 #include "locale-setup.h"
31 /* We don't list LC_ALL here on purpose. People should be
32 * using LANG instead. */
44 VARIABLE_LC_TELEPHONE,
45 VARIABLE_LC_MEASUREMENT,
46 VARIABLE_LC_IDENTIFICATION,
50 static const char * const variable_names[_VARIABLE_MAX] = {
51 [VARIABLE_LANG] = "LANG",
52 [VARIABLE_LC_CTYPE] = "LC_CTYPE",
53 [VARIABLE_LC_NUMERIC] = "LC_NUMERIC",
54 [VARIABLE_LC_TIME] = "TIME",
55 [VARIABLE_LC_COLLATE] = "COLLATE",
56 [VARIABLE_LC_MONETARY] = "MONETARY",
57 [VARIABLE_LC_MESSAGES] = "MESSAGE",
58 [VARIABLE_LC_PAPER] = "PAPER",
59 [VARIABLE_LC_NAME] = "NAME",
60 [VARIABLE_LC_ADDRESS] = "ADDRESS",
61 [VARIABLE_LC_TELEPHONE] = "TELEPHONE",
62 [VARIABLE_LC_MEASUREMENT] = "MEASUREMENT",
63 [VARIABLE_LC_IDENTIFICATION] = "IDENTIFICATION"
66 int locale_setup(void) {
67 char *variables[_VARIABLE_MAX];
72 if ((r = parse_env_file("/proc/cmdline", WHITESPACE,
74 "LANG", &variables[VARIABLE_LANG],
76 "locale.LANG", &variables[VARIABLE_LANG],
77 "locale.LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
78 "locale.LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
79 "locale.LC_TIME", &variables[VARIABLE_LC_TIME],
80 "locale.LC_COLLATE", &variables[VARIABLE_LC_COLLATE],
81 "locale.LC_MONETARY", &variables[VARIABLE_LC_MONETARY],
82 "locale.LC_MESSAGES", &variables[VARIABLE_LC_MESSAGES],
83 "locale.LC_PAPER", &variables[VARIABLE_LC_PAPER],
84 "locale.LC_NAME", &variables[VARIABLE_LC_NAME],
85 "locale.LC_ADDRESS", &variables[VARIABLE_LC_ADDRESS],
86 "locale.LC_TELEPHONE", &variables[VARIABLE_LC_TELEPHONE],
87 "locale.LC_MEASUREMENT", &variables[VARIABLE_LC_MEASUREMENT],
88 "locale.LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
92 log_warning("Failed to read /proc/cmdline: %s", strerror(-r));
95 /* Hmm, nothing set on the kernel cmd line? Then let's
96 * try /etc/locale.conf */
98 (r = parse_env_file("/etc/locale.conf", NEWLINE,
99 "LANG", &variables[VARIABLE_LANG],
100 "LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
101 "LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
102 "LC_TIME", &variables[VARIABLE_LC_TIME],
103 "LC_COLLATE", &variables[VARIABLE_LC_COLLATE],
104 "LC_MONETARY", &variables[VARIABLE_LC_MONETARY],
105 "LC_MESSAGES", &variables[VARIABLE_LC_MESSAGES],
106 "LC_PAPER", &variables[VARIABLE_LC_PAPER],
107 "LC_NAME", &variables[VARIABLE_LC_NAME],
108 "LC_ADDRESS", &variables[VARIABLE_LC_ADDRESS],
109 "LC_TELEPHONE", &variables[VARIABLE_LC_TELEPHONE],
110 "LC_MEASUREMENT", &variables[VARIABLE_LC_MEASUREMENT],
111 "LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
115 log_warning("Failed to read /etc/locale.conf: %s", strerror(-r));
120 (r = parse_env_file("/etc/sysconfig/i18n", NEWLINE,
121 "LANG", &variables[VARIABLE_LANG],
125 log_warning("Failed to read /etc/sysconfig/i18n: %s", strerror(-r));
128 #elif defined(TARGET_SUSE)
130 (r = parse_env_file("/etc/sysconfig/language", NEWLINE,
131 "RC_LANG", &variables[VARIABLE_LANG],
135 log_warning("Failed to read /etc/sysconfig/language: %s", strerror(-r));
138 #elif defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU)
140 (r = parse_env_file("/etc/default/locale", NEWLINE,
141 "LANG", &variables[VARIABLE_LANG],
145 log_warning("Failed to read /etc/default/locale: %s", strerror(-r));
148 #elif defined(TARGET_ARCH)
150 (r = parse_env_file("/etc/rc.conf", NEWLINE,
151 "LOCALE", &variables[VARIABLE_LANG],
155 log_warning("Failed to read /etc/rc.conf: %s", strerror(-r));
158 #elif defined(TARGET_GENTOO)
159 /* Gentoo's openrc expects locale variables in /etc/env.d/
160 * These files are later compiled by env-update into shell
161 * export commands at /etc/profile.env, with variables being
162 * exported by openrc's runscript (so /etc/init.d/)
165 (r = parse_env_file("/etc/profile.env", NEWLINE,
166 "export LANG", &variables[VARIABLE_LANG],
167 "export LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
168 "export LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
169 "export LC_TIME", &variables[VARIABLE_LC_TIME],
170 "export LC_COLLATE", &variables[VARIABLE_LC_COLLATE],
171 "export LC_MONETARY", &variables[VARIABLE_LC_MONETARY],
172 "export LC_MESSAGES", &variables[VARIABLE_LC_MESSAGES],
173 "export LC_PAPER", &variables[VARIABLE_LC_PAPER],
174 "export LC_NAME", &variables[VARIABLE_LC_NAME],
175 "export LC_ADDRESS", &variables[VARIABLE_LC_ADDRESS],
176 "export LC_TELEPHONE", &variables[VARIABLE_LC_TELEPHONE],
177 "export LC_MEASUREMENT", &variables[VARIABLE_LC_MEASUREMENT],
178 "export LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
182 log_warning("Failed to read /etc/profile.env: %s", strerror(-r));
186 if (!variables[VARIABLE_LANG]) {
187 if (!(variables[VARIABLE_LANG] = strdup("C"))) {
193 for (i = 0; i < _VARIABLE_MAX; i++) {
196 if (setenv(variable_names[i], variables[i], 1) < 0) {
201 unsetenv(variable_names[i]);
207 for (i = 0; i < _VARIABLE_MAX; i++)