diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2022-05-05 16:12:43 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2022-05-05 16:12:43 +0000 |
commit | be8113c872aa20def6b9ecb7b5c50247ff278f4f (patch) | |
tree | d255172810f4cf95aefbd7372241294a37205c26 | |
parent | 8ec2be0c40ee0401eb351b2e4cee83b012f55990 (diff) |
Add error handling if setting the keyboard encoding fails. After
open of all /dev/wskbd* devices failed, report the error from the
first one. Also wrap long lines.
OK mpi@
-rw-r--r-- | sbin/kbd/kbd_wscons.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/sbin/kbd/kbd_wscons.c b/sbin/kbd/kbd_wscons.c index 539d53cf311..c7437f626c0 100644 --- a/sbin/kbd/kbd_wscons.c +++ b/sbin/kbd/kbd_wscons.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kbd_wscons.c,v 1.35 2022/04/17 17:33:50 bluhm Exp $ */ +/* $OpenBSD: kbd_wscons.c,v 1.36 2022/05/05 16:12:42 bluhm Exp $ */ /* * Copyright (c) 2001 Mats O Jansson. All rights reserved. @@ -232,7 +232,7 @@ void kbd_set(char *name, int verbose) { char buf[LINE_MAX], *c, *b, device[sizeof "/dev/wskbd00"]; - int map = 0, v, i, fd; + int map = 0, v, i, fd, error = 0; struct nameint *n; c = name; @@ -271,20 +271,30 @@ kbd_set(char *name, int verbose) 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_SETENCODING, &map) == -1) { - if (errno == EINVAL) { - fprintf(stderr, - "%s: unsupported encoding %s on %s\n", - __progname, name, device); - } else - err(1, "WSKBDIO_SETENCODING: %s", device); - v--; - } - v++; + if (errno != EINVAL) + err(1, "WSKBDIO_SETENCODING %s", + device); + fprintf(stderr, + "%s: unsupported encoding %s on %s\n", + __progname, name, device); + } else + v++; close(fd); } } + if (error > 0) { + errno = error; + err(1, "/dev/wskbd0"); + } if (verbose && v > 0) fprintf(stderr, "kbd: keyboard mapping set to %s\n", name); |