summaryrefslogtreecommitdiff
path: root/usr.bin/sndiod
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2019-06-28 13:35:06 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2019-06-28 13:35:06 +0000
commit61656abc7ff84215165af1bd464bc053b3b66158 (patch)
treec7eabb0c4fa9faa024e724e99c240c40da07ca42 /usr.bin/sndiod
parent18603ebf99fbb890ae9666cb0c4aa9f879e7edaa (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.bin/sndiod')
-rw-r--r--usr.bin/sndiod/fdpass.c8
-rw-r--r--usr.bin/sndiod/file.c6
-rw-r--r--usr.bin/sndiod/listen.c24
3 files changed, 19 insertions, 19 deletions
diff --git a/usr.bin/sndiod/fdpass.c b/usr.bin/sndiod/fdpass.c
index 67c2f665077..42de8e7502f 100644
--- a/usr.bin/sndiod/fdpass.c
+++ b/usr.bin/sndiod/fdpass.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdpass.c,v 1.5 2019/05/10 04:39:08 ratchov Exp $ */
+/* $OpenBSD: fdpass.c,v 1.6 2019/06/28 13:35:03 deraadt Exp $ */
/*
* Copyright (c) 2015 Alexandre Ratchov <alex@caoua.org>
*
@@ -105,7 +105,7 @@ fdpass_send(struct fdpass *f, int cmd, int num, int mode, int fd)
*(int *)CMSG_DATA(cmsg) = fd;
}
n = sendmsg(f->fd, &msg, 0);
- if (n < 0) {
+ if (n == -1) {
if (log_level >= 1) {
fdpass_log(f);
log_puts(": sendmsg failed\n");
@@ -161,7 +161,7 @@ fdpass_recv(struct fdpass *f, int *cmd, int *num, int *mode, int *fd)
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
n = recvmsg(f->fd, &msg, MSG_WAITALL);
- if (n < 0 && errno == EMSGSIZE) {
+ if (n == -1 && errno == EMSGSIZE) {
if (log_level >= 1) {
fdpass_log(f);
log_puts(": out of fds\n");
@@ -172,7 +172,7 @@ fdpass_recv(struct fdpass *f, int *cmd, int *num, int *mode, int *fd)
*/
n = recvmsg(f->fd, &msg, MSG_WAITALL);
}
- if (n < 0) {
+ if (n == -1) {
if (log_level >= 1) {
fdpass_log(f);
log_puts(": recvmsg failed\n");
diff --git a/usr.bin/sndiod/file.c b/usr.bin/sndiod/file.c
index 5cb63d12ecb..443f88b1361 100644
--- a/usr.bin/sndiod/file.c
+++ b/usr.bin/sndiod/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.23 2016/10/27 04:37:47 ratchov Exp $ */
+/* $OpenBSD: file.c,v 1.24 2019/06/28 13:35:03 deraadt Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -394,7 +394,7 @@ file_poll(void)
timo = -1;
log_flush();
res = poll(pfds, nfds, timo);
- if (res < 0) {
+ if (res == -1) {
if (errno != EINTR) {
log_puts("poll failed");
panic();
@@ -440,7 +440,7 @@ filelist_init(void)
{
sigset_t set;
- if (clock_gettime(CLOCK_UPTIME, &file_ts) < 0) {
+ if (clock_gettime(CLOCK_UPTIME, &file_ts) == -1) {
log_puts("filelist_init: CLOCK_UPTIME unsupported\n");
panic();
}
diff --git a/usr.bin/sndiod/listen.c b/usr.bin/sndiod/listen.c
index 5397b6019b1..552b9457b96 100644
--- a/usr.bin/sndiod/listen.c
+++ b/usr.bin/sndiod/listen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: listen.c,v 1.12 2017/01/03 06:51:56 ratchov Exp $ */
+/* $OpenBSD: listen.c,v 1.13 2019/06/28 13:35:03 deraadt Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -84,12 +84,12 @@ listen_new_un(char *path)
struct listen *f;
sock = socket(AF_UNIX, SOCK_STREAM, 0);
- if (sock < 0) {
+ if (sock == -1) {
log_puts(path);
log_puts(": failed to create socket\n");
return 0;
}
- if (unlink(path) < 0 && errno != ENOENT) {
+ if (unlink(path) == -1 && errno != ENOENT) {
log_puts(path);
log_puts(": failed to unlink socket\n");
goto bad_close;
@@ -98,12 +98,12 @@ listen_new_un(char *path)
strlcpy(sockname.sun_path, path, sizeof(sockname.sun_path));
oldumask = umask(0111);
if (bind(sock, (struct sockaddr *)&sockname,
- sizeof(struct sockaddr_un)) < 0) {
+ sizeof(struct sockaddr_un)) == -1) {
log_puts(path);
log_puts(": failed to bind socket\n");
goto bad_close;
}
- if (listen(sock, 1) < 0) {
+ if (listen(sock, 1) == -1) {
log_puts(path);
log_puts(": failed to listen\n");
goto bad_close;
@@ -153,24 +153,24 @@ listen_new_tcp(char *addr, unsigned int port)
*/
for (ai = ailist; ai != NULL; ai = ai->ai_next) {
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
- if (s < 0) {
+ if (s == -1) {
log_puts(addr);
log_puts(": failed to create socket\n");
continue;
}
opt = 1;
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
- &opt, sizeof(int)) < 0) {
+ &opt, sizeof(int)) == -1) {
log_puts(addr);
log_puts(": failed to set SO_REUSEADDR\n");
goto bad_close;
}
- if (bind(s, ai->ai_addr, ai->ai_addrlen) < 0) {
+ if (bind(s, ai->ai_addr, ai->ai_addrlen) == -1) {
log_puts(addr);
log_puts(": failed to bind socket\n");
goto bad_close;
}
- if (listen(s, 1) < 0) {
+ if (listen(s, 1) == -1) {
log_puts(addr);
log_puts(": failed to listen\n");
goto bad_close;
@@ -230,14 +230,14 @@ listen_in(void *arg)
int sock, opt;
caddrlen = sizeof(caddrlen);
- while ((sock = accept(f->fd, &caddr, &caddrlen)) < 0) {
+ while ((sock = accept(f->fd, &caddr, &caddrlen)) == -1) {
if (errno == EINTR)
continue;
if (errno == ENFILE || errno == EMFILE)
file_slowaccept = 1;
return;
}
- if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
+ if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) {
file_log(f->file);
log_puts(": failed to set non-blocking mode\n");
goto bad_close;
@@ -245,7 +245,7 @@ listen_in(void *arg)
if (f->path == NULL) {
opt = 1;
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
- &opt, sizeof(int)) < 0) {
+ &opt, sizeof(int)) == -1) {
file_log(f->file);
log_puts(": failed to set TCP_NODELAY flag\n");
goto bad_close;