On Tue, Aug 29 2017, Jesper Wallin <[email protected]> wrote:
> Hi,
>
> I noticed that kbd(8) lets you list all available keyboard encodings
> with the -l flag.  However, we get no error and no list unless we're
> running this as root.  I apologize if this is intended and I fail to
> understand why.  If not intended, the patch below will check if we're
> root or otherwise error out.

Well, the behavior of kbd depends on the permissions of the device
files, not on the fact that you're root or not.  Maybe something like
this would be more appropriate?


Index: kbd_wscons.c
===================================================================
RCS file: /d/cvs/src/sbin/kbd/kbd_wscons.c,v
retrieving revision 1.32
diff -u -p -p -u -r1.32 kbd_wscons.c
--- kbd_wscons.c        3 Oct 2016 13:03:49 -0000       1.32
+++ kbd_wscons.c        30 Aug 2017 06:11:23 -0000
@@ -150,11 +150,12 @@ kbd_list(void)
 {
        int     kbds[SA_MAX];
        struct wskbd_encoding_data encs[SA_MAX];
-       int     fd, i, kbtype, t;
+       int     fd, i, kbtype, gotone, t;
        char    device[PATH_MAX];
 
        memset(kbds, 0, sizeof(kbds));
        memset(encs, 0, sizeof(encs));
+       gotone = 0;
 
        /* Go through all keyboards. */
        for (i = 0; i < NUM_KBD; i++) {
@@ -165,6 +166,7 @@ kbd_list(void)
                if (fd >= 0) {
                        if (ioctl(fd, WSKBDIO_GTYPE, &kbtype) < 0)
                                err(1, "WSKBDIO_GTYPE");
+                       gotone = 1;
                        switch (kbtype) {
                        case WSKBD_TYPE_PC_XT:
                        case WSKBD_TYPE_PC_AT:
@@ -208,6 +210,9 @@ kbd_list(void)
                        close(fd);
                }
        }
+
+       if (!gotone)
+               errx(1, "could not open any keyboard device");
 
        for (i = 0; i < SA_MAX; i++)
                if (kbds[i] != 0)

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to