From 4a1be7c31b6a068826f79ae8a2ee9dc3342803a3 Mon Sep 17 00:00:00 2001 From: bluhm Date: Sun, 17 Apr 2022 17:33:50 +0000 Subject: [PATCH] When kbd -l was executed as regular user, it failed silently. Try to open all wskbd devices, but report the first error and exit if none was successful. OK deraadt@ espie@ --- sbin/kbd/kbd_wscons.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/sbin/kbd/kbd_wscons.c b/sbin/kbd/kbd_wscons.c index a33071fa8a8..539d53cf311 100644 --- a/sbin/kbd/kbd_wscons.c +++ b/sbin/kbd/kbd_wscons.c @@ -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) -- 2.20.1