summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/locale-setup.c101
-rw-r--r--src/util.c6
2 files changed, 56 insertions, 51 deletions
diff --git a/src/locale-setup.c b/src/locale-setup.c
index 8ead9fdd9d..cf0d3e556f 100644
--- a/src/locale-setup.c
+++ b/src/locale-setup.c
@@ -69,8 +69,56 @@ int locale_setup(void) {
zero(variables);
+ if ((r = parse_env_file("/proc/cmdline", WHITESPACE,
+#ifdef TARGET_FEDORA
+ "LANG", &variables[VARIABLE_LANG],
+#endif
+ "locale.LANG", &variables[VARIABLE_LANG],
+ "locale.LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
+ "locale.LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
+ "locale.LC_TIME", &variables[VARIABLE_LC_TIME],
+ "locale.LC_COLLATE", &variables[VARIABLE_LC_COLLATE],
+ "locale.LC_MONETARY", &variables[VARIABLE_LC_MONETARY],
+ "locale.LC_MESSAGES", &variables[VARIABLE_LC_MESSAGES],
+ "locale.LC_PAPER", &variables[VARIABLE_LC_PAPER],
+ "locale.LC_NAME", &variables[VARIABLE_LC_NAME],
+ "locale.LC_ADDRESS", &variables[VARIABLE_LC_ADDRESS],
+ "locale.LC_TELEPHONE", &variables[VARIABLE_LC_TELEPHONE],
+ "locale.LC_MEASUREMENT", &variables[VARIABLE_LC_MEASUREMENT],
+ "locale.LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
+ NULL)) < 0) {
+
+ if (r != -ENOENT)
+ log_warning("Failed to read /proc/cmdline: %s", strerror(-r));
+ }
+
+ /* Hmm, nothing set on the kernel cmd line? Then let's
+ * try /etc/locale */
+
+ if (r <= 0 &&
+ (r = parse_env_file("/etc/locale", NEWLINE,
+ "LANG", &variables[VARIABLE_LANG],
+ "LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
+ "LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
+ "LC_TIME", &variables[VARIABLE_LC_TIME],
+ "LC_COLLATE", &variables[VARIABLE_LC_COLLATE],
+ "LC_MONETARY", &variables[VARIABLE_LC_MONETARY],
+ "LC_MESSAGES", &variables[VARIABLE_LC_MESSAGES],
+ "LC_PAPER", &variables[VARIABLE_LC_PAPER],
+ "LC_NAME", &variables[VARIABLE_LC_NAME],
+ "LC_ADDRESS", &variables[VARIABLE_LC_ADDRESS],
+ "LC_TELEPHONE", &variables[VARIABLE_LC_TELEPHONE],
+ "LC_MEASUREMENT", &variables[VARIABLE_LC_MEASUREMENT],
+ "LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
+ NULL)) < 0) {
+
+ if (r != -ENOENT)
+ log_warning("Failed to read /etc/locale: %s", strerror(-r));
+ }
+
#ifdef TARGET_FEDORA
- if ((r = parse_env_file("/etc/sysconfig/i18n", NEWLINE,
+ if (r <= 0 &&
+ (r = parse_env_file("/etc/sysconfig/i18n", NEWLINE,
"LANG", &variables[VARIABLE_LANG],
NULL)) < 0) {
@@ -78,7 +126,8 @@ int locale_setup(void) {
log_warning("Failed to read /etc/sysconfig/i18n: %s", strerror(-r));
}
#elif defined(TARGET_ARCH)
- if ((r = parse_env_file("/etc/rc.conf", NEWLINE,
+ if (r <= 0 &&
+ (r = parse_env_file("/etc/rc.conf", NEWLINE,
"LOCALE", &variables[VARIABLE_LANG],
NULL)) < 0) {
@@ -91,7 +140,8 @@ int locale_setup(void) {
* export commands at /etc/profile.env, with variables being
* exported by openrc's runscript (so /etc/init.d/)
*/
- if ((r = parse_env_file("/etc/profile.env", NEWLINE,
+ if (r <= 0 &&
+ (r = parse_env_file("/etc/profile.env", NEWLINE,
"export LANG", &variables[VARIABLE_LANG],
"export LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
"export LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
@@ -112,51 +162,6 @@ int locale_setup(void) {
}
#endif
- /* Override distribution-specific options with the
- * distribution-independent configuration */
- if ((r = parse_env_file("/etc/locale", NEWLINE,
- "LANG", &variables[VARIABLE_LANG],
- "LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
- "LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
- "LC_TIME", &variables[VARIABLE_LC_TIME],
- "LC_COLLATE", &variables[VARIABLE_LC_COLLATE],
- "LC_MONETARY", &variables[VARIABLE_LC_MONETARY],
- "LC_MESSAGES", &variables[VARIABLE_LC_MESSAGES],
- "LC_PAPER", &variables[VARIABLE_LC_PAPER],
- "LC_NAME", &variables[VARIABLE_LC_NAME],
- "LC_ADDRESS", &variables[VARIABLE_LC_ADDRESS],
- "LC_TELEPHONE", &variables[VARIABLE_LC_TELEPHONE],
- "LC_MEASUREMENT", &variables[VARIABLE_LC_MEASUREMENT],
- "LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
- NULL)) < 0) {
-
- if (r != -ENOENT)
- log_warning("Failed to read /etc/locale: %s", strerror(-r));
- }
-
- if ((r = parse_env_file("/proc/cmdline", WHITESPACE,
-#ifdef TARGET_FEDORA
- "LANG", &variables[VARIABLE_LANG],
-#endif
- "locale.LANG", &variables[VARIABLE_LANG],
- "locale.LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
- "locale.LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
- "locale.LC_TIME", &variables[VARIABLE_LC_TIME],
- "locale.LC_COLLATE", &variables[VARIABLE_LC_COLLATE],
- "locale.LC_MONETARY", &variables[VARIABLE_LC_MONETARY],
- "locale.LC_MESSAGES", &variables[VARIABLE_LC_MESSAGES],
- "locale.LC_PAPER", &variables[VARIABLE_LC_PAPER],
- "locale.LC_NAME", &variables[VARIABLE_LC_NAME],
- "locale.LC_ADDRESS", &variables[VARIABLE_LC_ADDRESS],
- "locale.LC_TELEPHONE", &variables[VARIABLE_LC_TELEPHONE],
- "locale.LC_MEASUREMENT", &variables[VARIABLE_LC_MEASUREMENT],
- "locale.LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
- NULL)) < 0) {
-
- if (r != -ENOENT)
- log_warning("Failed to read /proc/cmdline: %s", strerror(-r));
- }
-
if (!variables[VARIABLE_LANG]) {
if (!(variables[VARIABLE_LANG] = strdup("C"))) {
r = -ENOMEM;
diff --git a/src/util.c b/src/util.c
index bdc194e80c..0939ea9456 100644
--- a/src/util.c
+++ b/src/util.c
@@ -602,7 +602,7 @@ int parse_env_file(
const char *fname,
const char *seperator, ...) {
- int r;
+ int r = 0;
char *contents, *p;
assert(fname);
@@ -657,6 +657,8 @@ int parse_env_file(
*value = v;
p += n;
+
+ r ++;
break;
}
va_end(ap);
@@ -666,8 +668,6 @@ int parse_env_file(
p += strcspn(p, seperator);
}
- r = 0;
-
fail:
free(contents);
return r;