Hi,

It has bothered me for some time that vconsole.conf doesn't offer a setting to 
boot with NumLock enabled. With the patch in the attachment you can put 
NUM_LOCK=y in vconsole.conf (or vconsole.num_lock=y on the kernel command 
line) and it'll do the right thing. SCROLL_LOCK, CAPS_LOCK, 
vconsole.scroll_lock and vconsole.caps_lock work correspondingly. I'm not sure 
how useful that is especially for CapsLock, but it felt incomplete without 
that and was easy to implement, so meh.

Comments welcome
Cheers
Matthias
diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c
index 6501705..9c4549f 100644
--- a/src/vconsole/vconsole-setup.c
+++ b/src/vconsole/vconsole-setup.c
@@ -203,6 +203,39 @@ static void font_copy_to_all_vcs(int fd) {
         }
 }
 
+static int set_modifiers(int fd, int num_modifiers, char *const *modifier_status, const char *modifier) {
+        char mask;
+        int r = 0;
+        if (ioctl(fd, KDGKBLED, &mask)) {
+                r = -errno;
+                log_warning("failed to get keyboard modifier status: %s", strerror(errno));
+                return r;
+        }
+        
+        for (int i = 0; i < num_modifiers; ++i) {
+                if (modifier_status[i] == NULL)
+                        continue;
+                switch (parse_boolean(modifier_status[i])) {
+                case 0:
+                        mask &= ~modifier[i];
+                        break;
+                case 1:
+                        mask |= modifier[i];
+                        break;
+                default:
+                        log_warning("invalid value for keyboard modifier: \"%s\"", modifier_status[i]);
+                }
+        }
+                
+        if (ioctl(fd, KDSKBLED, mask)) {
+                r = -errno;
+                log_warning("failed to set keyboard modifier status: %s", strerror(errno));
+                return r;
+        }
+        
+        return 0;
+}
+
 int main(int argc, char **argv) {
         const char *vc;
         char *vc_keymap = NULL;
@@ -210,6 +243,8 @@ int main(int argc, char **argv) {
         char *vc_font = NULL;
         char *vc_font_map = NULL;
         char *vc_font_unimap = NULL;
+        const char vc_modifiers[] = { LED_SCR, LED_NUM, LED_CAP };
+        char *vc_modifier_status[ELEMENTSOF(vc_modifiers)] = { };
         int fd = -1;
         bool utf8;
         pid_t font_pid = 0, keymap_pid = 0;
@@ -251,6 +286,9 @@ int main(int argc, char **argv) {
                                    "vconsole.font", &vc_font,
                                    "vconsole.font.map", &vc_font_map,
                                    "vconsole.font.unimap", &vc_font_unimap,
+                                   "vconsole.scroll_lock", vc_modifier_status,
+                                   "vconsole.num_lock", vc_modifier_status + 1,
+                                   "vconsole.caps_lock", vc_modifier_status + 2,
                                    NULL);
 
                 if (r < 0 && r != -ENOENT)
@@ -266,6 +304,9 @@ int main(int argc, char **argv) {
                                    "FONT", &vc_font,
                                    "FONT_MAP", &vc_font_map,
                                    "FONT_UNIMAP", &vc_font_unimap,
+                                   "SCROLL_LOCK", vc_modifier_status,
+                                   "NUM_LOCK", vc_modifier_status + 1,
+                                   "CAPS_LOCK", vc_modifier_status + 2,
                                    NULL);
 
                 if (r < 0 && r != -ENOENT)
@@ -282,6 +323,9 @@ int main(int argc, char **argv) {
             font_load(vc, vc_font, vc_font_map, vc_font_unimap, &font_pid) >= 0)
                 r = EXIT_SUCCESS;
 
+        if (set_modifiers(fd, ELEMENTSOF(vc_modifiers), vc_modifier_status, vc_modifiers))
+                r = EXIT_FAILURE;
+
 finish:
         if (keymap_pid > 0)
                 wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid);
@@ -296,6 +340,9 @@ finish:
         free(vc_font);
         free(vc_font_map);
         free(vc_font_unimap);
+        free(vc_modifier_status[0]);
+        free(vc_modifier_status[1]);
+        free(vc_modifier_status[2]);
 
         if (fd >= 0)
                 close_nointr_nofail(fd);
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to