CVS commit: src/usr.bin/usbhidaction
Module Name:src Committed By: mrg Date: Tue Apr 13 02:07:35 UTC 2021 Modified Files: src/usr.bin/usbhidaction: usbhidaction.c Log Message: increase the size of a buffer by 1 byte. i think GCC 10 is right here. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/usr.bin/usbhidaction/usbhidaction.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/usbhidaction/usbhidaction.c diff -u src/usr.bin/usbhidaction/usbhidaction.c:1.29 src/usr.bin/usbhidaction/usbhidaction.c:1.30 --- src/usr.bin/usbhidaction/usbhidaction.c:1.29 Tue May 15 01:41:29 2018 +++ src/usr.bin/usbhidaction/usbhidaction.c Tue Apr 13 02:07:35 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: usbhidaction.c,v 1.29 2018/05/15 01:41:29 jmcneill Exp $ */ +/* $NetBSD: usbhidaction.c,v 1.30 2021/04/13 02:07:35 mrg Exp $ */ /* * Copyright (c) 2000, 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: usbhidaction.c,v 1.29 2018/05/15 01:41:29 jmcneill Exp $"); +__RCSID("$NetBSD: usbhidaction.c,v 1.30 2021/04/13 02:07:35 mrg Exp $"); #endif #include @@ -240,7 +240,7 @@ parse_conf(const char *conf, report_desc char *p; int line; char buf[SIZE], name[SIZE], value[SIZE], action[SIZE]; - char usagestr[SIZE], coll[SIZE]; + char usagestr[SIZE+1], coll[SIZE]; struct command *cmd, *cmds; struct hid_data *d; struct hid_item h;
CVS commit: src/usr.bin/usbhidaction
Module Name:src Committed By: jmcneill Date: Tue May 15 01:41:30 UTC 2018 Modified Files: src/usr.bin/usbhidaction: usbhidaction.1 usbhidaction.c Log Message: Add an optional '-p pidfile' parameter. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/usbhidaction/usbhidaction.1 cvs rdiff -u -r1.28 -r1.29 src/usr.bin/usbhidaction/usbhidaction.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/usbhidaction/usbhidaction.1 diff -u src/usr.bin/usbhidaction/usbhidaction.1:1.15 src/usr.bin/usbhidaction/usbhidaction.1:1.16 --- src/usr.bin/usbhidaction/usbhidaction.1:1.15 Wed Apr 30 13:11:01 2008 +++ src/usr.bin/usbhidaction/usbhidaction.1 Tue May 15 01:41:29 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: usbhidaction.1,v 1.15 2008/04/30 13:11:01 martin Exp $ +.\" $NetBSD: usbhidaction.1,v 1.16 2018/05/15 01:41:29 jmcneill Exp $ .\" .\" Copyright (c) 2000 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 20, 2004 +.Dd May 14, 2018 .Dt USBHIDACTION 1 .Os .Sh NAME @@ -39,6 +39,7 @@ .Op Fl d .Op Fl i .Fl f Ar device +.Op Fl p Ar pidfile .Op Fl t Ar table .Op Fl v .Op Ar arg ... @@ -69,6 +70,14 @@ If it is a relative path, it is taken to be the name of the device under .Pa /dev . An absolute path is taken to be the literal device pathname. +.It Fl p Ar pidfile +Writes a file containing the process ID of the program. +The file name has the form +.Pa /var/run/usbhidaction.pid . +If the option is not given, +.Ar pidfile +defaults to +.Pa usbhidaction . .It Fl t Ar table Specify a path name for the HID usage table file. .It Fl v Index: src/usr.bin/usbhidaction/usbhidaction.c diff -u src/usr.bin/usbhidaction/usbhidaction.c:1.28 src/usr.bin/usbhidaction/usbhidaction.c:1.29 --- src/usr.bin/usbhidaction/usbhidaction.c:1.28 Sun Dec 10 20:38:14 2017 +++ src/usr.bin/usbhidaction/usbhidaction.c Tue May 15 01:41:29 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: usbhidaction.c,v 1.28 2017/12/10 20:38:14 bouyer Exp $ */ +/* $NetBSD: usbhidaction.c,v 1.29 2018/05/15 01:41:29 jmcneill Exp $ */ /* * Copyright (c) 2000, 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: usbhidaction.c,v 1.28 2017/12/10 20:38:14 bouyer Exp $"); +__RCSID("$NetBSD: usbhidaction.c,v 1.29 2018/05/15 01:41:29 jmcneill Exp $"); #endif #include @@ -95,13 +95,14 @@ main(int argc, char **argv) struct command *cmd; int reportid; const char *table = NULL; + const char *pidfn = NULL; setprogname(argv[0]); (void)setlinebuf(stdout); demon = 1; ignore = 0; - while ((ch = getopt(argc, argv, "c:df:it:v")) != -1) { + while ((ch = getopt(argc, argv, "c:df:ip:t:v")) != -1) { switch(ch) { case 'c': conf = optarg; @@ -115,6 +116,9 @@ main(int argc, char **argv) case 'f': dev = optarg; break; + case 'p': + pidfn = optarg; + break; case 't': table = optarg; break; @@ -169,7 +173,7 @@ main(int argc, char **argv) if (demon) { if (daemon(0, 0) < 0) err(EXIT_FAILURE, "daemon()"); - (void)pidfile(NULL); + (void)pidfile(pidfn); isdemon = 1; } @@ -214,7 +218,7 @@ usage(void) { (void)fprintf(stderr, "usage: %s -c config_file [-d] -f hid_dev " - "[-i] [-t table] [-v]\n", getprogname()); + "[-i] [-p pidfile] [-t table] [-v]\n", getprogname()); exit(EXIT_FAILURE); }
CVS commit: src/usr.bin/usbhidaction
Module Name:src Committed By: dholland Date: Sat Dec 31 10:13:15 UTC 2016 Modified Files: src/usr.bin/usbhidaction: usbhidaction.c Log Message: PR 51754 Charlotte Koch: fix -v output of config parser. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/usr.bin/usbhidaction/usbhidaction.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/usbhidaction/usbhidaction.c diff -u src/usr.bin/usbhidaction/usbhidaction.c:1.26 src/usr.bin/usbhidaction/usbhidaction.c:1.27 --- src/usr.bin/usbhidaction/usbhidaction.c:1.26 Tue Sep 29 14:27:00 2015 +++ src/usr.bin/usbhidaction/usbhidaction.c Sat Dec 31 10:13:15 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: usbhidaction.c,v 1.26 2015/09/29 14:27:00 christos Exp $ */ +/* $NetBSD: usbhidaction.c,v 1.27 2016/12/31 10:13:15 dholland Exp $ */ /* * Copyright (c) 2000, 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: usbhidaction.c,v 1.26 2015/09/29 14:27:00 christos Exp $"); +__RCSID("$NetBSD: usbhidaction.c,v 1.27 2016/12/31 10:13:15 dholland Exp $"); #endif #include @@ -392,9 +392,17 @@ parse_conf(const char *conf, report_desc cmd->value = -1; } - if (verbose) - (void)printf("PARSE:%d %s, %d, '%s'\n", cmd->line, name, - cmd->value, cmd->action); + if (verbose) { + char valuebuf[16]; + + if (cmd->anyvalue) +snprintf(valuebuf, sizeof(valuebuf), "%s", "*"); + else +snprintf(valuebuf, sizeof(valuebuf), "%d", +cmd->value); + (void)printf("PARSE:%d %s, %s, '%s'\n", cmd->line, name, +valuebuf, cmd->action); + } } (void)fclose(f); return (cmds);
CVS commit: src/usr.bin/usbhidaction
Module Name:src Committed By: christos Date: Tue Sep 29 14:27:00 UTC 2015 Modified Files: src/usr.bin/usbhidaction: usbhidaction.c Log Message: - PR/50291: Fix memory leak - estrdup/emalloc - use EXIT_FAILURE instead of 1 To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/usr.bin/usbhidaction/usbhidaction.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/usbhidaction/usbhidaction.c diff -u src/usr.bin/usbhidaction/usbhidaction.c:1.25 src/usr.bin/usbhidaction/usbhidaction.c:1.26 --- src/usr.bin/usbhidaction/usbhidaction.c:1.25 Thu Jan 24 12:46:00 2013 +++ src/usr.bin/usbhidaction/usbhidaction.c Tue Sep 29 10:27:00 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: usbhidaction.c,v 1.25 2013/01/24 17:46:00 christos Exp $ */ +/* $NetBSD: usbhidaction.c,v 1.26 2015/09/29 14:27:00 christos Exp $ */ /* * Copyright (c) 2000, 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: usbhidaction.c,v 1.25 2013/01/24 17:46:00 christos Exp $"); +__RCSID("$NetBSD: usbhidaction.c,v 1.26 2015/09/29 14:27:00 christos Exp $"); #endif #include @@ -50,6 +50,7 @@ __RCSID("$NetBSD: usbhidaction.c,v 1.25 #include #include #include +#include static int verbose = 0; static int isdemon = 0; @@ -136,22 +137,23 @@ main(int argc, char **argv) if (dev[0] != '/') { (void)snprintf(devnamebuf, sizeof(devnamebuf), "/dev/%s%s", - isdigit((unsigned char)dev[0]) ? "uhid" : "", dev); + isdigit((unsigned char)dev[0]) ? "uhid" : "", dev); dev = devnamebuf; } if (demon && conf[0] != '/') - errx(1, "config file must have an absolute path, %s", conf); + errx(EXIT_FAILURE, + "config file must have an absolute path, %s", conf); fd = open(dev, O_RDWR | O_CLOEXEC); if (fd < 0) - err(1, "%s", dev); + err(EXIT_FAILURE, "%s", dev); if (ioctl(fd, USB_GET_REPORT_ID, ) < 0) reportid = -1; repd = hid_get_report_desc(fd); if (repd == NULL) - err(1, "hid_get_report_desc() failed"); + err(EXIT_FAILURE, "hid_get_report_desc() failed"); commands = parse_conf(conf, repd, reportid, ignore); @@ -159,14 +161,14 @@ main(int argc, char **argv) if (verbose) (void)printf("report size %d\n", sz); - if (sz > (int)sizeof(buf)) - errx(1, "report too large"); + if ((size_t)sz > sizeof(buf)) + errx(EXIT_FAILURE, "report too large"); (void)signal(SIGHUP, sighup); if (demon) { if (daemon(0, 0) < 0) - err(1, "daemon()"); + err(EXIT_FAILURE, "daemon()"); (void)pidfile(NULL); isdemon = 1; } @@ -181,13 +183,13 @@ main(int argc, char **argv) } if (n < 0) { if (verbose) -err(1, "read"); +err(EXIT_FAILURE, "read"); else -exit(1); +exit(EXIT_FAILURE); } #if 0 if (n != sz) { - err(2, "read size"); + err(EXIT_FAILURE, "read size"); } #endif for (cmd = commands; cmd; cmd = cmd->next) { @@ -213,7 +215,7 @@ usage(void) (void)fprintf(stderr, "usage: %s -c config_file [-d] -f hid_dev " "[-i] [-t table] [-v]\n", getprogname()); - exit(1); + exit(EXIT_FAILURE); } static int @@ -242,7 +244,7 @@ parse_conf(const char *conf, report_desc f = fopen(conf, "r"); if (f == NULL) - err(1, "%s", conf); + err(EXIT_FAILURE, "%s", conf); cmds = NULL; for (line = 1; ; line++) { @@ -268,14 +270,12 @@ parse_conf(const char *conf, report_desc (void)fclose(f); return (NULL); } else { -errx(1, "config file `%s', line %d," +errx(EXIT_FAILURE, "config file `%s', line %d," ", syntax error: %s", conf, line, buf); } } - cmd = malloc(sizeof *cmd); - if (cmd == NULL) - err(1, "malloc failed"); + cmd = emalloc(sizeof *cmd); cmd->next = cmds; cmds = cmd; cmd->line = line; @@ -294,9 +294,10 @@ parse_conf(const char *conf, report_desc (void)fclose(f); return (NULL); } else { - errx(1, "config file `%s', line %d, " - "bad value: %s\n", - conf, line, value); + errx(EXIT_FAILURE, + "config file `%s', line %d, " + "bad value: %s\n", + conf, line, value); } } } @@ -375,15 +376,15 @@ parse_conf(const char *conf, report_desc (void)fclose(f); return (NULL); } else { - errx(1, "config file `%s', line %d, HID item " - "not found: `%s'", conf, line, name); + errx(EXIT_FAILURE, "config file `%s', line %d," + " HID item not found: `%s'", conf, line, name); } foundhid: hid_end_parse(d); cmd->item = h; - cmd->name = strdup(name); - cmd->action = strdup(action); + cmd->name = estrdup(name); + cmd->action = estrdup(action); if (range) { if (cmd->value == 1) cmd->value = u - lo; @@ -413,7 +414,7 @@ docmd(struct command *cmd, int value, co if (isdigit((unsigned char)*p)) { n = strtol(p, , 10) - 1; if (n >= 0 && n < argc) { - (void)strncpy(q, argv[n], len); + (void)strlcpy(q,
CVS commit: src/usr.bin/usbhidaction
Module Name:src Committed By: christos Date: Thu Jan 24 17:46:00 UTC 2013 Modified Files: src/usr.bin/usbhidaction: usbhidaction.c Log Message: use O_CLOEXEC To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/usbhidaction/usbhidaction.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/usbhidaction/usbhidaction.c diff -u src/usr.bin/usbhidaction/usbhidaction.c:1.24 src/usr.bin/usbhidaction/usbhidaction.c:1.25 --- src/usr.bin/usbhidaction/usbhidaction.c:1.24 Sun Jan 18 02:14:03 2009 +++ src/usr.bin/usbhidaction/usbhidaction.c Thu Jan 24 12:46:00 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: usbhidaction.c,v 1.24 2009/01/18 07:14:03 lukem Exp $ */ +/* $NetBSD: usbhidaction.c,v 1.25 2013/01/24 17:46:00 christos Exp $ */ /* * Copyright (c) 2000, 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: usbhidaction.c,v 1.24 2009/01/18 07:14:03 lukem Exp $); +__RCSID($NetBSD: usbhidaction.c,v 1.25 2013/01/24 17:46:00 christos Exp $); #endif #include stdio.h @@ -143,14 +143,10 @@ main(int argc, char **argv) if (demon conf[0] != '/') errx(1, config file must have an absolute path, %s, conf); - fd = open(dev, O_RDWR); + fd = open(dev, O_RDWR | O_CLOEXEC); if (fd 0) err(1, %s, dev); - /* Avoid passing the device file descriptor to executed commands */ - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) - err(1, fcntl(F_SETFD, FD_CLOEXEC)); - if (ioctl(fd, USB_GET_REPORT_ID, reportid) 0) reportid = -1; repd = hid_get_report_desc(fd);