diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2004-04-13 01:10:06 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2004-04-13 01:10:06 +0000 |
commit | 655f45137c9b293b16a89a50c2fe69e14d16af39 (patch) | |
tree | 829d229679c1200b37019fdb58cd8bc8edfc5596 /usr.sbin/syslogc | |
parent | d7f62b0b2e3bd0136f993bec4f9c0b1c02ae274d (diff) |
Sort getopt list and tidy error checks. From andrushock@korovino.net;
ok deraadt@
Diffstat (limited to 'usr.sbin/syslogc')
-rw-r--r-- | usr.sbin/syslogc/syslogc.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/usr.sbin/syslogc/syslogc.c b/usr.sbin/syslogc/syslogc.c index f32eddbd1ee..cb3face5da7 100644 --- a/usr.sbin/syslogc/syslogc.c +++ b/usr.sbin/syslogc/syslogc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogc.c,v 1.4 2004/03/15 01:07:21 djm Exp $ */ +/* $OpenBSD: syslogc.c,v 1.5 2004/04/13 01:10:05 djm Exp $ */ /* * Copyright (c) 2004 Damien Miller @@ -29,7 +29,8 @@ #define DEFAULT_CTLSOCK "/var/run/syslogd.sock" -#define MAX_MEMBUF_NAME 64 /* Max length of membuf log name */ +#define MAX_MEMBUF_NAME 64 /* Max length of membuf log name */ + struct ctl_cmd { #define CMD_READ 1 /* Read out log */ #define CMD_READ_CLEAR 2 /* Read and clear log */ @@ -66,18 +67,18 @@ main(int argc, char **argv) ctlsock_path = DEFAULT_CTLSOCK; while ((ch = getopt(argc, argv, "Cchqs:")) != -1) { switch (ch) { + case 'C': + cc.cmd = CMD_CLEAR; + break; + case 'c': + cc.cmd = CMD_READ_CLEAR; + break; case 'h': usage(); break; case 'q': cc.cmd = CMD_LIST; break; - case 'c': - cc.cmd = CMD_READ_CLEAR; - break; - case 'C': - cc.cmd = CMD_CLEAR; - break; case 's': ctlsock_path = optarg; break; @@ -96,7 +97,7 @@ main(int argc, char **argv) usage(); if (cc.cmd != CMD_LIST) { - if (strlcpy(cc.logname, argv[optind], sizeof(cc.logname)) > + if (strlcpy(cc.logname, argv[optind], sizeof(cc.logname)) >= sizeof(cc.logname)) errx(1, "Specified log name is too long"); } @@ -105,14 +106,14 @@ main(int argc, char **argv) strlcpy(ctl.sun_path, ctlsock_path, sizeof(ctl.sun_path)); ctl.sun_family = AF_UNIX; - if ((ctlsock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) + if ((ctlsock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) err(1, "socket"); if (connect(ctlsock, (struct sockaddr*)&ctl, sizeof(ctl)) == -1) - err(1, "%s", ctl.sun_path); + err(1, "connect: %s", ctl.sun_path); if ((ctlf = fdopen(ctlsock, "r+")) == NULL) err(1, "fdopen"); /* Send command */ - if (fwrite(&cc, sizeof(cc), 1, ctlf) <= 0) + if (fwrite(&cc, sizeof(cc), 1, ctlf) != 1) err(1, "fwrite"); fflush(ctlf); |