[systemd-devel] [PATCH] localed: search locale settings on kernel cmdline first
Michal Sekletar
msekleta at redhat.com
Mon Jun 2 09:03:52 PDT 2014
systemd spawns services with locale settings taken from kernel
cmdline. If it doesn't find anything there, then it proceeds with
parsing settings from /etc/locale.conf. localed should do the same and
look at kernel cmdline first.
---
src/locale/localed.c | 80 ++++++++++++++++++++++++++++++++++------------------
1 file changed, 53 insertions(+), 27 deletions(-)
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 358f6c2..111f1a7 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -38,6 +38,7 @@
#include "bus-error.h"
#include "bus-message.h"
#include "event-util.h"
+#include "virt.h"
enum {
/* We don't list LC_ALL here on purpose. People should be
@@ -149,41 +150,66 @@ static void locale_simplify(Context *c) {
}
static int locale_read_data(Context *c) {
- int r;
+ int r = 0;
context_free_locale(c);
- r = parse_env_file("/etc/locale.conf", NEWLINE,
- "LANG", &c->locale[LOCALE_LANG],
- "LANGUAGE", &c->locale[LOCALE_LANGUAGE],
- "LC_CTYPE", &c->locale[LOCALE_LC_CTYPE],
- "LC_NUMERIC", &c->locale[LOCALE_LC_NUMERIC],
- "LC_TIME", &c->locale[LOCALE_LC_TIME],
- "LC_COLLATE", &c->locale[LOCALE_LC_COLLATE],
- "LC_MONETARY", &c->locale[LOCALE_LC_MONETARY],
- "LC_MESSAGES", &c->locale[LOCALE_LC_MESSAGES],
- "LC_PAPER", &c->locale[LOCALE_LC_PAPER],
- "LC_NAME", &c->locale[LOCALE_LC_NAME],
- "LC_ADDRESS", &c->locale[LOCALE_LC_ADDRESS],
- "LC_TELEPHONE", &c->locale[LOCALE_LC_TELEPHONE],
- "LC_MEASUREMENT", &c->locale[LOCALE_LC_MEASUREMENT],
- "LC_IDENTIFICATION", &c->locale[LOCALE_LC_IDENTIFICATION],
- NULL);
-
- if (r == -ENOENT) {
- int p;
+ if (detect_container <= 0) {
+ r = parse_env_file("/proc/cmdline", WHITESPACE,
+ "locale.LANG", &c->locale[LOCALE_LANG],
+ "locale.LANGUAGE", &c->locale[LOCALE_LANGUAGE],
+ "locale.LC_CTYPE", &c->locale[LOCALE_LC_CTYPE],
+ "locale.LC_NUMERIC", &c->locale[LOCALE_LC_NUMERIC],
+ "locale.LC_TIME", &c->locale[LOCALE_LC_TIME],
+ "locale.LC_COLLATE", &c->locale[LOCALE_LC_COLLATE],
+ "locale.LC_MONETARY", &c->locale[LOCALE_LC_MONETARY],
+ "locale.LC_MESSAGES", &c->locale[LOCALE_LC_MESSAGES],
+ "locale.LC_PAPER", &c->locale[LOCALE_LC_PAPER],
+ "locale.LC_NAME", &c->locale[LOCALE_LC_NAME],
+ "locale.LC_ADDRESS", &c->locale[LOCALE_LC_ADDRESS],
+ "locale.LC_TELEPHONE", &c->locale[LOCALE_LC_TELEPHONE],
+ "locale.LC_MEASUREMENT", &c->locale[LOCALE_LC_MEASUREMENT],
+ "locale.LC_IDENTIFICATION", &c->locale[LOCALE_LC_IDENTIFICATION],
+ NULL);
+
+ if (r < 0 && r != -ENOENT)
+ log_warning("Failed to read /proc/cmdline: %s", strerror(-r));
+ }
- /* Fill in what we got passed from systemd. */
- for (p = 0; p < _LOCALE_MAX; p++) {
- assert(names[p]);
+ if (r <= 0) {
+ r = parse_env_file("/etc/locale.conf", NEWLINE,
+ "LANG", &c->locale[LOCALE_LANG],
+ "LANGUAGE", &c->locale[LOCALE_LANGUAGE],
+ "LC_CTYPE", &c->locale[LOCALE_LC_CTYPE],
+ "LC_NUMERIC", &c->locale[LOCALE_LC_NUMERIC],
+ "LC_TIME", &c->locale[LOCALE_LC_TIME],
+ "LC_COLLATE", &c->locale[LOCALE_LC_COLLATE],
+ "LC_MONETARY", &c->locale[LOCALE_LC_MONETARY],
+ "LC_MESSAGES", &c->locale[LOCALE_LC_MESSAGES],
+ "LC_PAPER", &c->locale[LOCALE_LC_PAPER],
+ "LC_NAME", &c->locale[LOCALE_LC_NAME],
+ "LC_ADDRESS", &c->locale[LOCALE_LC_ADDRESS],
+ "LC_TELEPHONE", &c->locale[LOCALE_LC_TELEPHONE],
+ "LC_MEASUREMENT", &c->locale[LOCALE_LC_MEASUREMENT],
+ "LC_IDENTIFICATION", &c->locale[LOCALE_LC_IDENTIFICATION],
+ NULL);
+
+ if (r == -ENOENT) {
+ int p;
+
+ /* Fill in what we got passed from systemd. */
+ for (p = 0; p < _LOCALE_MAX; p++) {
+ assert(names[p]);
- r = free_and_copy(&c->locale[p], getenv(names[p]));
- if (r < 0)
- return r;
+ r = free_and_copy(&c->locale[p], getenv(names[p]));
+ if (r < 0)
+ return r;
+ }
}
+ }
+ if (r > 0)
r = 0;
- }
locale_simplify(c);
return r;
--
1.9.0
More information about the systemd-devel
mailing list