[systemd-commits] 3 commits - fixme Makefile.am src/locale-setup.c src/locale-setup.h src/main.c src/util.c src/vconsole-setup.c

Lennart Poettering lennart at kemper.freedesktop.org
Wed Sep 15 16:58:36 PDT 2010


 Makefile.am          |    1 
 fixme                |    5 -
 src/locale-setup.c   |  153 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/locale-setup.h   |   27 +++++++++
 src/main.c           |    3 +
 src/util.c           |    4 -
 src/vconsole-setup.c |   52 +++++++++++------
 7 files changed, 220 insertions(+), 25 deletions(-)

New commits:
commit 1ebdf5b6847b6a52480a6e9382c1cb70f931a535
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Sep 16 01:58:16 2010 +0200

    vconsole: fall back to fedora specific configuration

diff --git a/src/vconsole-setup.c b/src/vconsole-setup.c
index 8e4fede..cb8fc43 100644
--- a/src/vconsole-setup.c
+++ b/src/vconsole-setup.c
@@ -168,31 +168,47 @@ int main(int argc, char **argv) {
         if (!(utf8 = is_locale_utf8()))
                 disable_utf8(fd);
 
-        if ((r = parse_env_file(
-                             "/etc/vconsole",
-                             NEWLINE,
-                             "VCONSOLE_KEYMAP", &vc_keymap,
-                             "VCONSOLE_FONT", &vc_font,
-                             "VCONSOLE_FONT_MAP", &vc_font_map,
-                             "VCONSOLE_FONT_UNIMAP", &vc_font_unimap,
-                             NULL)) < 0) {
+#ifdef TARGET_FEDORA
+        if ((r = parse_env_file("/etc/sysconfig/i18n", NEWLINE,
+                                "SYSFONT", &vc_font,
+                                NULL)) < 0) {
+
+                if (r != -ENOENT)
+                        log_warning("Failed to read /etc/sysconfig/i18n: %s", strerror(-r));
+        }
+
+        if ((r = parse_env_file("/etc/sysconfig/keyboard", NEWLINE,
+                                "KEYTABLE", &vc_keymap,
+                                NULL)) < 0) {
+
+                if (r != -ENOENT)
+                        log_warning("Failed to read /etc/sysconfig/i18n: %s", strerror(-r));
+        }
+#endif
+
+        /* Override distribution-specific options with the
+         * distribution-independent configuration */
+        if ((r = parse_env_file("/etc/vconsole", NEWLINE,
+                                "VCONSOLE_KEYMAP", &vc_keymap,
+                                "VCONSOLE_FONT", &vc_font,
+                                "VCONSOLE_FONT_MAP", &vc_font_map,
+                                "VCONSOLE_FONT_UNIMAP", &vc_font_unimap,
+                                NULL)) < 0) {
 
                 if (r != -ENOENT)
                         log_warning("Failed to read /etc/vconsole: %s", strerror(-r));
         }
 
-        if ((r = parse_env_file(
-                             "/proc/cmdline",
-                             WHITESPACE,
+        if ((r = parse_env_file("/proc/cmdline", WHITESPACE,
 #ifdef TARGET_FEDORA
-                             "SYSFONT", &vc_font,
-                             "KEYTABLE", &vc_keymap,
+                                "SYSFONT", &vc_font,
+                                "KEYTABLE", &vc_keymap,
 #endif
-                             "vconsole.keymap", &vc_keymap,
-                             "vconsole.font", &vc_font,
-                             "vconsole.font.map", &vc_font_map,
-                             "vconsole.font.unimap", &vc_font_unimap,
-                             NULL)) < 0) {
+                                "vconsole.keymap", &vc_keymap,
+                                "vconsole.font", &vc_font,
+                                "vconsole.font.map", &vc_font_map,
+                                "vconsole.font.unimap", &vc_font_unimap,
+                                NULL)) < 0) {
 
                 if (r != -ENOENT)
                         log_warning("Failed to read /proc/cmdline: %s", strerror(-r));
commit e7db37dd19d540e9ac8b89c689914d44d15433c4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Sep 16 01:57:59 2010 +0200

    util: fix handling of quotes in parse_env_file()

diff --git a/src/util.c b/src/util.c
index 47da11c..c1ee936 100644
--- a/src/util.c
+++ b/src/util.c
@@ -641,8 +641,8 @@ int parse_env_file(
                                 n = strcspn(p, seperator);
 
                                 if (n >= 2 &&
-                                    strchr(QUOTES, v[0]) &&
-                                    v[n-1] == v[0])
+                                    strchr(QUOTES, p[0]) &&
+                                    p[n-1] == p[0])
                                         v = strndup(p+1, n-2);
                                 else
                                         v = strndup(p, n);
commit 72bca11ba2bcaadd9c6188e97e6d5834b4115002
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Sep 16 01:57:42 2010 +0200

    locale: initialize locale from /etc/locale by default

diff --git a/Makefile.am b/Makefile.am
index 8711a52..7632e55 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -343,6 +343,7 @@ libsystemd_core_la_SOURCES = \
 	src/hostname-setup.c \
 	src/loopback-setup.c \
 	src/kmod-setup.c \
+	src/locale-setup.c \
 	src/specifier.c \
 	src/unit-name.c \
 	src/fdset.c \
diff --git a/fixme b/fixme
index bce501c..1738284 100644
--- a/fixme
+++ b/fixme
@@ -1,8 +1,5 @@
 * do not throw error when .service file is linked to /dev/null
 
-* read /etc/locale, and export LANG= and friends to started services
-  allow overwrite of setting by kernel commandline: locale.LANG=, ...
-
 * oneshot services which do not remain: 'exited' instead of 'dead'?
   it should be visible in 'systemctl' that they have been run
 
@@ -90,8 +87,6 @@
 
 * systemctl auto-pager a la git
 
-* console setup
-
 * fsck setup
 
 * merge CK
diff --git a/src/locale-setup.c b/src/locale-setup.c
new file mode 100644
index 0000000..923be04
--- /dev/null
+++ b/src/locale-setup.c
@@ -0,0 +1,153 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "locale-setup.h"
+#include "util.h"
+#include "macro.h"
+
+enum {
+        VARIABLE_LANG,
+        VARIABLE_LC_CTYPE,
+        VARIABLE_LC_NUMERIC,
+        VARIABLE_LC_TIME,
+        VARIABLE_LC_COLLATE,
+        VARIABLE_LC_MONETARY,
+        VARIABLE_LC_MESSAGES,
+        VARIABLE_LC_ALL,
+        VARIABLE_LC_PAPER,
+        VARIABLE_LC_NAME,
+        VARIABLE_LC_ADDRESS,
+        VARIABLE_LC_TELEPHONE,
+        VARIABLE_LC_MEASUREMENT,
+        VARIABLE_LC_IDENTIFICATION,
+        _VARIABLE_MAX
+};
+
+static const char * const variable_names[_VARIABLE_MAX] = {
+        [VARIABLE_LANG] = "LANG",
+        [VARIABLE_LC_CTYPE] = "LC_CTYPE",
+        [VARIABLE_LC_NUMERIC] = "LC_NUMERIC",
+        [VARIABLE_LC_TIME] = "TIME",
+        [VARIABLE_LC_COLLATE] = "COLLATE",
+        [VARIABLE_LC_MONETARY] = "MONETARY",
+        [VARIABLE_LC_MESSAGES] = "MESSAGE",
+        [VARIABLE_LC_ALL] = "ALL",
+        [VARIABLE_LC_PAPER] = "PAPER",
+        [VARIABLE_LC_NAME] = "NAME",
+        [VARIABLE_LC_ADDRESS] = "ADDRESS",
+        [VARIABLE_LC_TELEPHONE] = "TELEPHONE",
+        [VARIABLE_LC_MEASUREMENT] = "MEASUREMENT",
+        [VARIABLE_LC_IDENTIFICATION] = "IDENTIFICATION"
+};
+
+int locale_setup(void) {
+        char *variables[_VARIABLE_MAX];
+        int r, i;
+
+        zero(variables);
+
+#ifdef TARGET_FEDORA
+        if ((r = parse_env_file("/etc/sysconfig/i18n", NEWLINE,
+                                "LANG", &variables[VARIABLE_LANG],
+                                NULL)) < 0) {
+
+                if (r != -ENOENT)
+                        log_warning("Failed to read /etc/sysconfig/i18n: %s", strerror(-r));
+        }
+#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_ALL",            &variables[VARIABLE_LC_ALL],
+                                "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_ALL",            &variables[VARIABLE_LC_ALL],
+                                "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;
+                        goto finish;
+                }
+        }
+
+        for (i = 0; i < _VARIABLE_MAX; i++) {
+
+                if (!variables[i])
+                        continue;
+
+                if (setenv(variable_names[i], variables[i], 1) < 0) {
+                        r = -errno;
+                        goto finish;
+                }
+
+        }
+        r = 0;
+
+finish:
+        for (i = 0; i < _VARIABLE_MAX; i++)
+                free(variables[i]);
+
+        return r;
+}
diff --git a/src/locale-setup.h b/src/locale-setup.h
new file mode 100644
index 0000000..09a6bc6
--- /dev/null
+++ b/src/locale-setup.h
@@ -0,0 +1,27 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#ifndef foolocalesetuphfoo
+#define foolocalesetuphfoo
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+int locale_setup(void);
+
+#endif
diff --git a/src/main.c b/src/main.c
index e4f229e..671f2bb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -38,6 +38,7 @@
 #include "hostname-setup.h"
 #include "loopback-setup.h"
 #include "kmod-setup.h"
+#include "locale-setup.h"
 #include "load-fragment.h"
 #include "fdset.h"
 #include "special.h"
@@ -997,6 +998,8 @@ int main(int argc, char *argv[]) {
                  PACKAGE_STRING " running in %s mode. (" SYSTEMD_FEATURES "; " DISTRIBUTION ")", manager_running_as_to_string(arg_running_as));
 
         if (arg_running_as == MANAGER_SYSTEM && !serialization) {
+                locale_setup();
+
                 if (arg_show_status)
                         status_welcome();
 


More information about the systemd-commits mailing list