[systemd-devel] [Patch] NumLock setting from vconsole.conf

Matthias Berndt matthias_berndt at gmx.de
Thu Jan 31 12:38:50 PST 2013


Hi,

The attached version of the patch contains updates to the man pages.

Cheers
Matthias
-------------- next part --------------
diff --git a/man/vconsole.conf.xml b/man/vconsole.conf.xml
index 45156b7..3707279 100644
--- a/man/vconsole.conf.xml
+++ b/man/vconsole.conf.xml
@@ -74,7 +74,10 @@
                 <varname>vconsole.keymap.toggle=</varname>,
                 <varname>vconsole.font=</varname>,
                 <varname>vconsole.font.map=</varname>,
-                <varname>vconsole.font.unimap=</varname> may be used
+                <varname>vconsole.font.unimap=</varname>,
+                <varname>vconsole.scroll_lock</varname>,
+                <varname>vconsole.num_lock</varname>,
+                <varname>vconsole.caps_lock</varname> may be used
                 to override the console settings at boot.</para>
 
                 <para>Depending on the operating system other
@@ -115,6 +118,17 @@
                                 font map.</para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><varname>SCROLL_LOCK=</varname></term>
+                                <term><varname>NUM_LOCK=</varname></term>
+                                <term><varname>CAPS_LOCK=</varname></term>
+                                <listitem><para>These boolean variables control 
+                                the state of the respective toggle switches. 
+                                When an invalid or no value is specified,
+                                the state is left unchanged.
+                                </para></listitem>
+                        </varlistentry>
+
                 </variablelist>
         </refsect1>
 
@@ -122,12 +136,13 @@
                 <title>Example</title>
 
                 <example>
-                        <title>German keyboard and console</title>
+                        <title>German keyboard and console with NumLock enabled:</title>
 
                         <para><filename>/etc/vconsole.conf:</filename></para>
 
                         <programlisting>KEYMAP=de-latin1
-FONT=latarcyrheb-sun16</programlisting>
+FONT=latarcyrheb-sun16
+NUM_LOCK=on</programlisting>
                 </example>
 
         </refsect1>
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);


More information about the systemd-devel mailing list