When kbd -l was executed as regular user, it failed silently. Try
authorbluhm <bluhm@openbsd.org>
Sun, 17 Apr 2022 17:33:50 +0000 (17:33 +0000)
committerbluhm <bluhm@openbsd.org>
Sun, 17 Apr 2022 17:33:50 +0000 (17:33 +0000)
to open all wskbd devices, but report the first error and exit if
none was successful.
OK deraadt@ espie@

sbin/kbd/kbd_wscons.c

index a33071f..539d53c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kbd_wscons.c,v 1.34 2020/01/22 06:24:07 tedu Exp $ */
+/*     $OpenBSD: kbd_wscons.c,v 1.35 2022/04/17 17:33:50 bluhm Exp $ */
 
 /*
  * Copyright (c) 2001 Mats O Jansson.  All rights reserved.
@@ -150,7 +150,7 @@ kbd_list(void)
 {
        int     kbds[SA_MAX];
        struct wskbd_encoding_data encs[SA_MAX];
-       int     fd, i, kbtype, t;
+       int     fd, i, kbtype, t, error = 0;
        char    device[PATH_MAX];
 
        memset(kbds, 0, sizeof(kbds));
@@ -162,9 +162,16 @@ kbd_list(void)
                fd = open(device, O_WRONLY);
                if (fd == -1)
                        fd = open(device, O_RDONLY);
-               if (fd >= 0) {
+               if (fd == -1) {
+                       /* remember the first error number */
+                       if (error == 0)
+                               error = errno;
+               } else {
+                       /* at least one success, do not print error */
+                       error = -1;
+
                        if (ioctl(fd, WSKBDIO_GTYPE, &kbtype) == -1)
-                               err(1, "WSKBDIO_GTYPE");
+                               err(1, "WSKBDIO_GTYPE %s", device);
                        switch (kbtype) {
                        case WSKBD_TYPE_PC_XT:
                        case WSKBD_TYPE_PC_AT:
@@ -208,6 +215,10 @@ kbd_list(void)
                        close(fd);
                }
        }
+       if (error > 0) {
+               errno = error;
+               err(1, "/dev/wskbd0");
+       }
 
        for (i = 0; i < SA_MAX; i++)
                if (kbds[i] != 0)