-/* $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.
{
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));
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:
close(fd);
}
}
+ if (error > 0) {
+ errno = error;
+ err(1, "/dev/wskbd0");
+ }
for (i = 0; i < SA_MAX; i++)
if (kbds[i] != 0)