diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2019-06-28 13:32:54 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2019-06-28 13:32:54 +0000 |
commit | 86ffccf24f66032a89d70a32b3609584c0db7345 (patch) | |
tree | 2ae97fac6ea5be57cc953baf8612e8f683da0172 /usr.sbin/rbootd | |
parent | ce9fea47562d4f179d45680d6aec00ede2877141 (diff) |
When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.
Diffstat (limited to 'usr.sbin/rbootd')
-rw-r--r-- | usr.sbin/rbootd/bpf.c | 24 | ||||
-rw-r--r-- | usr.sbin/rbootd/parseconf.c | 4 | ||||
-rw-r--r-- | usr.sbin/rbootd/rbootd.c | 6 | ||||
-rw-r--r-- | usr.sbin/rbootd/rmpproto.c | 8 |
4 files changed, 21 insertions, 21 deletions
diff --git a/usr.sbin/rbootd/bpf.c b/usr.sbin/rbootd/bpf.c index 069253c0973..5ada9b29bed 100644 --- a/usr.sbin/rbootd/bpf.c +++ b/usr.sbin/rbootd/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.26 2017/04/19 05:36:13 natano Exp $ */ +/* $OpenBSD: bpf.c,v 1.27 2019/06/28 13:32:50 deraadt Exp $ */ /* $NetBSD: bpf.c,v 1.5.2.1 1995/11/14 08:45:42 thorpej Exp $ */ /* @@ -94,7 +94,7 @@ BpfOpen(void) * type and make sure it's type Ethernet. */ (void) strncpy(ifr.ifr_name, IntfName, sizeof(ifr.ifr_name)); - if (ioctl(BpfFd, BIOCSETIF, (caddr_t)&ifr) < 0) { + if (ioctl(BpfFd, BIOCSETIF, (caddr_t)&ifr) == -1) { syslog(LOG_ERR, "bpf: ioctl(BIOCSETIF,%s): %m", IntfName); DoExit(); } @@ -102,7 +102,7 @@ BpfOpen(void) /* * Make sure we are dealing with an Ethernet device. */ - if (ioctl(BpfFd, BIOCGDLT, (caddr_t)&n) < 0) { + if (ioctl(BpfFd, BIOCGDLT, (caddr_t)&n) == -1) { syslog(LOG_ERR, "bpf: ioctl(BIOCGDLT): %m"); DoExit(); } @@ -116,7 +116,7 @@ BpfOpen(void) * On read(), return packets immediately (do not buffer them). */ n = 1; - if (ioctl(BpfFd, BIOCIMMEDIATE, (caddr_t)&n) < 0) { + if (ioctl(BpfFd, BIOCIMMEDIATE, (caddr_t)&n) == -1) { syslog(LOG_ERR, "bpf: ioctl(BIOCIMMEDIATE): %m"); DoExit(); } @@ -132,11 +132,11 @@ BpfOpen(void) #endif ifr.ifr_addr.sa_family = AF_UNSPEC; bcopy(&RmpMcastAddr[0], (char *)&ifr.ifr_addr.sa_data[0], RMP_ADDRLEN); - if (ioctl(BpfFd, SIOCADDMULTI, (caddr_t)&ifr) < 0) { + if (ioctl(BpfFd, SIOCADDMULTI, (caddr_t)&ifr) == -1) { syslog(LOG_WARNING, "bpf: can't add mcast addr (%m), setting promiscuous mode"); - if (ioctl(BpfFd, BIOCPROMISC, (caddr_t)0) < 0) { + if (ioctl(BpfFd, BIOCPROMISC, (caddr_t)0) == -1) { syslog(LOG_ERR, "bpf: can't set promiscuous mode: %m"); DoExit(); } @@ -145,7 +145,7 @@ BpfOpen(void) /* * Ask BPF how much buffer space it requires and allocate one. */ - if (ioctl(BpfFd, BIOCGBLEN, (caddr_t)&BpfLen) < 0) { + if (ioctl(BpfFd, BIOCGBLEN, (caddr_t)&BpfLen) == -1) { syslog(LOG_ERR, "bpf: ioctl(BIOCGBLEN): %m"); DoExit(); } @@ -213,17 +213,17 @@ BpfOpen(void) sizeof(bpf_wf_insn)/sizeof(bpf_wf_insn[0]), bpf_wf_insn }; - if (ioctl(BpfFd, BIOCSETF, (caddr_t)&bpf_pgm) < 0) { + if (ioctl(BpfFd, BIOCSETF, (caddr_t)&bpf_pgm) == -1) { syslog(LOG_ERR, "bpf: ioctl(BIOCSETF): %m"); DoExit(); } - if (ioctl(BpfFd, BIOCSETWF, (caddr_t)&bpf_w_pgm) < 0) { + if (ioctl(BpfFd, BIOCSETWF, (caddr_t)&bpf_w_pgm) == -1) { syslog(LOG_ERR, "bpf: ioctl(BIOCSETWF): %m"); DoExit(); } - if (ioctl(BpfFd, BIOCLOCK) < 0) { + if (ioctl(BpfFd, BIOCLOCK) == -1) { syslog(LOG_ERR, "bpf: ioctl(BIOCLOCK): %m"); DoExit(); } @@ -324,7 +324,7 @@ BpfRead(RMPCONN *rconn, int doread) * We let the caller decide whether or not we can issue a read(). */ if (doread) { - if ((cc = read(BpfFd, (char *)BpfPkt, (int)BpfLen)) < 0) { + if ((cc = read(BpfFd, (char *)BpfPkt, (int)BpfLen)) == -1) { syslog(LOG_ERR, "bpf: read: %m"); return(0); } else { @@ -379,7 +379,7 @@ BpfRead(RMPCONN *rconn, int doread) int BpfWrite(RMPCONN *rconn) { - if (write(BpfFd, (char *)&rconn->rmp, rconn->rmplen) < 0) { + if (write(BpfFd, (char *)&rconn->rmp, rconn->rmplen) == -1) { syslog(LOG_ERR, "write: %s: %m", EnetStr(rconn)); return(0); } diff --git a/usr.sbin/rbootd/parseconf.c b/usr.sbin/rbootd/parseconf.c index 4739c15d9eb..2563ce9b59a 100644 --- a/usr.sbin/rbootd/parseconf.c +++ b/usr.sbin/rbootd/parseconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parseconf.c,v 1.13 2016/05/29 02:19:02 guenther Exp $ */ +/* $OpenBSD: parseconf.c,v 1.14 2019/06/28 13:32:50 deraadt Exp $ */ /* $NetBSD: parseconf.c,v 1.4 1995/10/06 05:12:16 thorpej Exp $ */ /* @@ -320,7 +320,7 @@ GetBootFiles(void) */ i = 0; for (dp = readdir(dfd); dp != NULL; dp = readdir(dfd)) { - if (stat(dp->d_name, &statb) < 0 || + if (stat(dp->d_name, &statb) == -1 || (statb.st_mode & S_IFMT) != S_IFREG) continue; if (i == C_MAXFILE) diff --git a/usr.sbin/rbootd/rbootd.c b/usr.sbin/rbootd/rbootd.c index 5c1dbee3edc..a1c4050b164 100644 --- a/usr.sbin/rbootd/rbootd.c +++ b/usr.sbin/rbootd/rbootd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rbootd.c,v 1.31 2016/05/29 02:19:02 guenther Exp $ */ +/* $OpenBSD: rbootd.c,v 1.32 2019/06/28 13:32:50 deraadt Exp $ */ /* $NetBSD: rbootd.c,v 1.5 1995/10/06 05:12:17 thorpej Exp $ */ /* @@ -159,7 +159,7 @@ main(int argc, char *argv[]) * All boot files are relative to the boot directory, we might * as well chdir() there to make life easier. */ - if (chdir(BootDir) < 0) { + if (chdir(BootDir) == -1) { syslog(LOG_ERR, "chdir: %m (%s)", BootDir); DoExit(); } @@ -215,7 +215,7 @@ main(int argc, char *argv[]) nsel = poll(pfd, 1, RmpConns ? RMP_TIMEOUT * 100 : -1); - if (nsel < 0) { + if (nsel == -1) { if (errno == EINTR) continue; syslog(LOG_ERR, "poll: %m"); diff --git a/usr.sbin/rbootd/rmpproto.c b/usr.sbin/rbootd/rmpproto.c index 74d8277b9b6..268fc2e780b 100644 --- a/usr.sbin/rbootd/rmpproto.c +++ b/usr.sbin/rbootd/rmpproto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rmpproto.c,v 1.12 2016/03/16 15:41:11 krw Exp $ */ +/* $OpenBSD: rmpproto.c,v 1.13 2019/06/28 13:32:50 deraadt Exp $ */ /* $NetBSD: rmpproto.c,v 1.5.2.1 1995/11/14 08:45:44 thorpej Exp $ */ /* @@ -355,7 +355,7 @@ match: * "too many open files" - RMP_E_BUSY * anything else - RMP_E_OPENFILE */ - if ((rconn->bootfd = open(filename, O_RDONLY, 0600)) < 0) { + if ((rconn->bootfd = open(filename, O_RDONLY, 0600)) == -1) { rpl->r_brpl.rmp_retcode = (errno == ENOENT)? RMP_E_NOFILE: (errno == EMFILE || errno == ENFILE)? RMP_E_BUSY: RMP_E_OPENFILE; @@ -444,7 +444,7 @@ SendReadRepl(RMPCONN *rconn) * Position read head on file according to info in request packet. */ GETWORD(req->r_rrq.rmp_offset, size); - if (lseek(oldconn->bootfd, (off_t)size, SEEK_SET) < 0) { + if (lseek(oldconn->bootfd, (off_t)size, SEEK_SET) == -1) { syslog(LOG_ERR, "SendReadRepl: lseek: %m (%s)", EnetStr(rconn)); rpl->r_rrpl.rmp_retcode = RMP_E_ABORT; @@ -457,7 +457,7 @@ SendReadRepl(RMPCONN *rconn) */ if ((size = read(oldconn->bootfd, &rpl->r_rrpl.rmp_data, (int) ntohs(req->r_rrq.rmp_size))) <= 0) { - if (size < 0) { + if (size == -1) { syslog(LOG_ERR, "SendReadRepl: read: %m (%s)", EnetStr(rconn)); rpl->r_rrpl.rmp_retcode = RMP_E_ABORT; |