[systemd-devel] [PATCH] gentoo: vconsole-setup support.

Gustavo Sverzut Barbieri barbieri at profusion.mobi
Sun Sep 19 17:23:51 PDT 2010


This patch is a bit bigger than expected since Gentoo being
non-standard in some places.

 1. it is installing binaries at /usr/bin instead of /bin.

 2. it is using CamelCase names for consolefonts.

 3. /etc/rc.conf:unicode=(yes|no) just forbids loadkeys and setfont
    "-u" options, but do not disable the actual kernel default_utf8
    from vt module.
---
 src/vconsole-setup.c |   83 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/src/vconsole-setup.c b/src/vconsole-setup.c
index 0f730a0..b3b50c4 100644
--- a/src/vconsole-setup.c
+++ b/src/vconsole-setup.c
@@ -40,6 +40,17 @@
 #include "log.h"
 #include "macro.h"
 
+#ifdef TARGET_GENTOO
+/* Gentoo uses sys-apps/kbd that installs to /usr and have fonts in CamelCase */
+#define KBD_LOADKEYS "/usr/bin/loadkeys"
+#define KBD_SETFONT "/usr/bin/setfont"
+#define DEFAULT_FONT "LatArCyrHeb-16"
+#else
+#define KBD_LOADKEYS "/bin/loadkeys"
+#define KBD_SETFONT "/bin/setfont"
+#define DEFAULT_FONT "latarcyrheb-sun16"
+#endif
+
 static bool is_console(int fd) {
         unsigned char data[1];
 
@@ -83,7 +94,7 @@ static int load_keymap(const char *vc, const char *map, bool utf8, pid_t *_pid)
         int i = 0;
         pid_t pid;
 
-        args[i++] = "/bin/loadkeys";
+        args[i++] = KBD_LOADKEYS;
         args[i++] = "-q";
         args[i++] = "-C";
         args[i++] = vc;
@@ -109,7 +120,7 @@ static int load_font(const char *vc, const char *font, const char *map, const ch
         int i = 0;
         pid_t pid;
 
-        args[i++] = "/bin/setfont";
+        args[i++] = KBD_SETFONT;
         args[i++] = "-C";
         args[i++] = vc;
         args[i++] = font;
@@ -141,6 +152,9 @@ int main(int argc, char **argv) {
         char *vc_font = NULL;
         char *vc_font_map = NULL;
         char *vc_font_unimap = NULL;
+#ifdef TARGET_GENTOO
+        char *vc_unicode = NULL;
+#endif
         int fd = -1;
         bool utf8;
         int r = EXIT_FAILURE;
@@ -199,6 +213,65 @@ int main(int argc, char **argv) {
                 free(vc_keymap);
                 vc_keymap = t;
         }
+
+#elif defined(TARGET_GENTOO)
+        if ((r = parse_env_file("/etc/rc.conf", NEWLINE,
+                                "unicode", &vc_unicode,
+                                NULL)) < 0) {
+                if (r != -ENOENT)
+                        log_warning("Failed to read /etc/rc.conf: %s", strerror(-r));
+        }
+        if (vc_unicode) {
+                int rc_unicode;
+
+                if (strcasecmp(vc_unicode, "yes") == 0 ||
+                    strcasecmp(vc_unicode, "on") == 0 ||
+                    strcasecmp(vc_unicode, "true") == 0 ||
+                    strcmp(vc_unicode, "1") == 0)
+                        rc_unicode = 1;
+                else if (strcasecmp(vc_unicode, "no") == 0 ||
+                    strcasecmp(vc_unicode, "off") == 0 ||
+                    strcasecmp(vc_unicode, "false") == 0 ||
+                    strcmp(vc_unicode, "0") == 0)
+                        rc_unicode = 0;
+                else {
+                        log_error("Unknown value for /etc/rc.conf unicode=%s", vc_unicode);
+                        rc_unicode = -1;
+                }
+
+                if (rc_unicode != -1) {
+                        if (rc_unicode && !utf8)
+                                log_warning("/etc/rc.conf wants unicode, but current locale is not UTF-8 capable!");
+                        else if (!rc_unicode && utf8) {
+                                log_debug("/etc/rc.conf does not want unicode, leave it on in kernel but does not apply to vconsole.");
+                                utf8 = false;
+                        }
+                }
+        }
+
+        /* /etc/conf.d/consolefont comments and gentoo documentation
+         * mention uppercase, but the actual contents are lowercase.
+         * the existing /etc/init.d/consolefont tries both
+         */
+        if ((r = parse_env_file("/etc/conf.d/consolefont", NEWLINE,
+                                "CONSOLEFONT", &vc_font,
+                                "consolefont", &vc_font,
+                                "consoletranslation", &vc_font_map,
+                                "CONSOLETRANSLATION", &vc_font_map,
+                                "unicodemap", &vc_font_unimap,
+                                "UNICODEMAP", &vc_font_unimap,
+                                NULL)) < 0) {
+                if (r != -ENOENT)
+                        log_warning("Failed to read /etc/conf.d/consolefont: %s", strerror(-r));
+        }
+
+        if ((r = parse_env_file("/etc/conf.d/keymaps", NEWLINE,
+                                "keymap", &vc_keymap,
+                                "KEYMAP", &vc_keymap,
+                                NULL)) < 0) {
+                if (r != -ENOENT)
+                        log_warning("Failed to read /etc/conf.d/keymaps: %s", strerror(-r));
+        }
 #endif
 
         /* Override distribution-specific options with the
@@ -232,7 +305,7 @@ int main(int argc, char **argv) {
         if (!vc_keymap)
                 vc_keymap = strdup("us");
         if (!vc_font)
-                vc_font = strdup("latarcyrheb-sun16");
+                vc_font = strdup(DEFAULT_FONT);
 
         if (!vc_keymap || !vc_font) {
                 log_error("Failed to allocate strings.");
@@ -245,10 +318,10 @@ int main(int argc, char **argv) {
 
 finish:
         if (keymap_pid > 0)
-                wait_for_terminate_and_warn("/bin/loadkeys", keymap_pid);
+                wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid);
 
         if (font_pid > 0)
-                wait_for_terminate_and_warn("/bin/setfont", font_pid);
+                wait_for_terminate_and_warn(KBD_SETFONT, font_pid);
 
         free(vc_keymap);
         free(vc_font);
-- 
1.7.2.2



More information about the systemd-devel mailing list