Check return values of syscalls against -1, from deraadt@.

This commit is contained in:
Alexandre Ratchov 2019-07-01 09:06:49 +02:00
parent 74abe4dcc7
commit 934e1611e8
12 changed files with 94 additions and 94 deletions

View File

@ -219,7 +219,7 @@ be32_set(be32_t *p, unsigned int v)
static int
afile_readhdr(struct afile *f, void *addr, size_t size)
{
if (lseek(f->fd, 0, SEEK_SET) < 0) {
if (lseek(f->fd, 0, SEEK_SET) == -1) {
log_puts(f->path);
log_puts(": failed to seek to beginning of file\n");
return 0;
@ -235,7 +235,7 @@ afile_readhdr(struct afile *f, void *addr, size_t size)
static int
afile_writehdr(struct afile *f, void *addr, size_t size)
{
if (lseek(f->fd, 0, SEEK_SET) < 0) {
if (lseek(f->fd, 0, SEEK_SET) == -1) {
log_puts(f->path);
log_puts(": failed to seek back to header\n");
return 0;
@ -404,7 +404,7 @@ afile_wav_readhdr(struct afile *f)
* next chunk
*/
pos += sizeof(struct wav_chunk) + csize;
if (lseek(f->fd, sizeof(riff) + pos, SEEK_SET) < 0) {
if (lseek(f->fd, sizeof(riff) + pos, SEEK_SET) == -1) {
log_puts(f->path);
log_puts(": filed to seek to chunk\n");
return 0;
@ -593,7 +593,7 @@ afile_aiff_readhdr(struct afile *f)
csize = (csize + 1) & ~1;
pos += sizeof(struct aiff_chunk) + csize;
if (lseek(f->fd, sizeof(form) + pos, SEEK_SET) < 0) {
if (lseek(f->fd, sizeof(form) + pos, SEEK_SET) == -1) {
log_puts(f->path);
log_puts(": filed to seek to chunk\n");
return 0;
@ -708,7 +708,7 @@ afile_au_readhdr(struct afile *f)
f->par.msb = 0;
f->rate = be32_get(&hdr.rate);
f->nch = be32_get(&hdr.nch);
if (lseek(f->fd, f->startpos, SEEK_SET) < 0) {
if (lseek(f->fd, f->startpos, SEEK_SET) == -1) {
log_puts(f->path);
log_puts(": ");
log_puts("failed to seek to data chunk\n");
@ -778,7 +778,7 @@ afile_read(struct afile *f, void *data, size_t count)
count = maxread;
}
n = read(f->fd, data, count);
if (n < 0) {
if (n == -1) {
log_puts(f->path);
log_puts(": couldn't read\n");
return 0;
@ -808,7 +808,7 @@ afile_write(struct afile *f, void *data, size_t count)
count = maxwrite;
}
n = write(f->fd, data, count);
if (n < 0) {
if (n == -1) {
log_puts(f->path);
log_puts(": couldn't write\n");
return 0;
@ -833,7 +833,7 @@ afile_seek(struct afile *f, off_t pos)
* seek only if needed to avoid errors with pipes & sockets
*/
if (pos != f->curpos) {
if (lseek(f->fd, pos, SEEK_SET) < 0) {
if (lseek(f->fd, pos, SEEK_SET) == -1) {
log_puts(f->path);
log_puts(": couldn't seek\n");
return 0;
@ -896,7 +896,7 @@ afile_open(struct afile *f, char *path, int hdr, int flags,
} else {
f->path = path;
f->fd = open(f->path, O_RDONLY, 0);
if (f->fd < 0) {
if (f->fd == -1) {
log_puts(f->path);
log_puts(": failed to open for reading\n");
return 0;
@ -925,7 +925,7 @@ afile_open(struct afile *f, char *path, int hdr, int flags,
f->path = path;
f->fd = open(f->path,
O_WRONLY | O_TRUNC | O_CREAT, 0666);
if (f->fd < 0) {
if (f->fd == -1) {
log_puts(f->path);
log_puts(": failed to create file\n");
return 0;

View File

@ -1197,7 +1197,7 @@ playrec(char *dev, int mode, int bufsz, char *port)
nm = mio_pollfd(dev_mh, pfds + ns, POLLIN);
else
nm = 0;
if (poll(pfds, ns + nm, -1) < 0) {
if (poll(pfds, ns + nm, -1) == -1) {
if (errno == EINTR)
continue;
log_puts("poll failed\n");

View File

@ -50,13 +50,13 @@ random_bytes(unsigned char *buf, int len)
int fd;
fd = open(DEV_RANDOM, O_RDONLY);
if (fd < 0) {
if (fd == -1) {
DPERROR(DEV_RANDOM);
return 0;
}
while (len > 0) {
n = read(fd, buf, len);
if (n < 0) {
if (n == -1) {
if (errno == EINTR)
continue;
DPERROR(DEV_RANDOM);
@ -92,7 +92,7 @@ _aucat_rmsg(struct aucat *hdl, int *eof)
while (hdl->rtodo > 0) {
data = (unsigned char *)&hdl->rmsg;
data += sizeof(struct amsg) - hdl->rtodo;
while ((n = read(hdl->fd, data, hdl->rtodo)) < 0) {
while ((n = read(hdl->fd, data, hdl->rtodo)) == -1) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
@ -138,7 +138,7 @@ _aucat_wmsg(struct aucat *hdl, int *eof)
while (hdl->wtodo > 0) {
data = (unsigned char *)&hdl->wmsg;
data += sizeof(struct amsg) - hdl->wtodo;
while ((n = write(hdl->fd, data, hdl->wtodo)) < 0) {
while ((n = write(hdl->fd, data, hdl->wtodo)) == -1) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
@ -170,7 +170,7 @@ _aucat_rdata(struct aucat *hdl, void *buf, size_t len, int *eof)
}
if (len > hdl->rtodo)
len = hdl->rtodo;
while ((n = read(hdl->fd, buf, len)) < 0) {
while ((n = read(hdl->fd, buf, len)) == -1) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
@ -223,7 +223,7 @@ _aucat_wdata(struct aucat *hdl, const void *buf, size_t len,
DPRINTF("_aucat_wdata: len == 0\n");
abort();
}
while ((n = write(hdl->fd, buf, len)) < 0) {
while ((n = write(hdl->fd, buf, len)) == -1) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
@ -269,12 +269,12 @@ aucat_mkcookie(unsigned char *cookie)
memcpy(path + home_len, COOKIE_SUFFIX, sizeof(COOKIE_SUFFIX));
path_len = home_len + sizeof(COOKIE_SUFFIX) - 1;
fd = open(path, O_RDONLY);
if (fd < 0) {
if (fd == -1) {
if (errno != ENOENT)
DPERROR(path);
goto bad_gen;
}
if (fstat(fd, &sb) < 0) {
if (fstat(fd, &sb) == -1) {
DPERROR(path);
goto bad_close;
}
@ -283,7 +283,7 @@ aucat_mkcookie(unsigned char *cookie)
goto bad_close;
}
len = read(fd, cookie, AMSG_COOKIELEN);
if (len < 0) {
if (len == -1) {
DPERROR(path);
goto bad_close;
}
@ -322,25 +322,25 @@ bad_gen:
/* create ~/.sndio directory */
memcpy(tmp, home, home_len);
memcpy(tmp + home_len, COOKIE_DIR, sizeof(COOKIE_DIR));
if (mkdir(tmp, 0755) < 0 && errno != EEXIST)
if (mkdir(tmp, 0755) == -1 && errno != EEXIST)
goto done;
/* create cookie file in it */
memcpy(tmp, path, path_len);
memcpy(tmp + path_len, TEMPL_SUFFIX, sizeof(TEMPL_SUFFIX));
fd = mkstemp(tmp);
if (fd < 0) {
if (fd == -1) {
DPERROR(tmp);
goto done;
}
if (write(fd, cookie, AMSG_COOKIELEN) < 0) {
if (write(fd, cookie, AMSG_COOKIELEN) == -1) {
DPERROR(tmp);
unlink(tmp);
close(fd);
goto done;
}
close(fd);
if (rename(tmp, path) < 0) {
if (rename(tmp, path) == -1) {
DPERROR(tmp);
unlink(tmp);
}
@ -370,12 +370,12 @@ aucat_connect_tcp(struct aucat *hdl, char *host, unsigned int unit)
for (ai = ailist; ai != NULL; ai = ai->ai_next) {
s = socket(ai->ai_family, ai->ai_socktype | SOCK_CLOEXEC,
ai->ai_protocol);
if (s < 0) {
if (s == -1) {
DPERROR("socket");
continue;
}
#ifndef HAVE_SOCK_CLOEXEC
if (fcntl(s, F_SETFL, FD_CLOEXEC) < 0) {
if (fcntl(s, F_SETFL, FD_CLOEXEC) == -1) {
DPERROR("FD_CLOEXEC");
close(s);
s = - 1;
@ -383,7 +383,7 @@ aucat_connect_tcp(struct aucat *hdl, char *host, unsigned int unit)
}
#endif
restart:
if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0) {
if (connect(s, ai->ai_addr, ai->ai_addrlen) == -1) {
if (errno == EINTR)
goto restart;
DPERROR("connect");
@ -394,10 +394,10 @@ aucat_connect_tcp(struct aucat *hdl, char *host, unsigned int unit)
break;
}
freeaddrinfo(ailist);
if (s < 0)
if (s == -1)
return 0;
opt = 1;
if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int)) < 0) {
if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int)) == -1) {
DPERROR("setsockopt");
close(s);
return 0;
@ -419,23 +419,23 @@ aucat_connect_un(struct aucat *hdl, unsigned int unit)
SOCKPATH_DIR "-%u/" SOCKPATH_FILE "%u", uid, unit);
ca.sun_family = AF_UNIX;
s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (s < 0)
if (s == -1)
return 0;
#ifndef HAVE_SOCK_CLOEXEC
if (fcntl(s, F_SETFL, FD_CLOEXEC) < 0) {
if (fcntl(s, F_SETFL, FD_CLOEXEC) == -1) {
DPERROR("FD_CLOEXEC");
close(s);
return 0;
}
#endif
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
while (connect(s, (struct sockaddr *)&ca, len) == -1) {
if (errno == EINTR)
continue;
DPERROR(ca.sun_path);
/* try shared server */
snprintf(ca.sun_path, sizeof(ca.sun_path),
SOCKPATH_DIR "/" SOCKPATH_FILE "%u", unit);
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
while (connect(s, (struct sockaddr *)&ca, len) == -1) {
if (errno == EINTR)
continue;
DPERROR(ca.sun_path);
@ -566,7 +566,7 @@ _aucat_open(struct aucat *hdl, const char *str, unsigned int mode)
}
return 1;
bad_connect:
while (close(hdl->fd) < 0 && errno == EINTR)
while (close(hdl->fd) == -1 && errno == EINTR)
; /* retry */
return 0;
}
@ -589,7 +589,7 @@ _aucat_close(struct aucat *hdl, int eof)
*/
while (1) {
n = read(hdl->fd, dummy, sizeof(dummy));
if (n < 0) {
if (n == -1) {
if (errno == EINTR)
continue;
break;
@ -599,14 +599,14 @@ _aucat_close(struct aucat *hdl, int eof)
}
}
bad_close:
while (close(hdl->fd) < 0 && errno == EINTR)
while (close(hdl->fd) == -1 && errno == EINTR)
; /* nothing */
}
int
_aucat_setfl(struct aucat *hdl, int nbio, int *eof)
{
if (fcntl(hdl->fd, F_SETFL, nbio ? O_NONBLOCK : 0) < 0) {
if (fcntl(hdl->fd, F_SETFL, nbio ? O_NONBLOCK : 0) == -1) {
DPERROR("_aucat_setfl: fcntl");
*eof = 1;
return 0;

View File

@ -107,7 +107,7 @@ mio_psleep(struct mio_hdl *hdl, int event)
}
for (;;) {
nfds = mio_pollfd(hdl, pfd, event);
while (poll(pfd, nfds, -1) < 0) {
while (poll(pfd, nfds, -1) == -1) {
if (errno == EINTR)
continue;
DPERROR("mio_psleep: poll");

View File

@ -128,7 +128,7 @@ mio_rmidi_getfd(const char *str, unsigned int mode, int nbio)
flags = O_RDWR;
else
flags = (mode & MIO_OUT) ? O_WRONLY : O_RDONLY;
while ((fd = open(path, flags | O_NONBLOCK | O_CLOEXEC)) < 0) {
while ((fd = open(path, flags | O_NONBLOCK | O_CLOEXEC)) == -1) {
if (errno == EINTR)
continue;
DPERROR(path);
@ -160,12 +160,12 @@ _mio_rmidi_open(const char *str, unsigned int mode, int nbio)
int fd;
fd = mio_rmidi_getfd(str, mode, nbio);
if (fd < 0)
if (fd == -1)
return NULL;
hdl = mio_rmidi_fdopen(fd, mode, nbio);
if (hdl != NULL)
return hdl;
while (close(fd) < 0 && errno == EINTR)
while (close(fd) == -1 && errno == EINTR)
; /* retry */
return NULL;
}
@ -178,7 +178,7 @@ mio_rmidi_close(struct mio_hdl *sh)
do {
rc = close(hdl->fd);
} while (rc < 0 && errno == EINTR);
} while (rc == -1 && errno == EINTR);
free(hdl);
}
@ -188,7 +188,7 @@ mio_rmidi_read(struct mio_hdl *sh, void *buf, size_t len)
struct mio_rmidi_hdl *hdl = (struct mio_rmidi_hdl *)sh;
ssize_t n;
while ((n = read(hdl->fd, buf, len)) < 0) {
while ((n = read(hdl->fd, buf, len)) == -1) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
@ -211,7 +211,7 @@ mio_rmidi_write(struct mio_hdl *sh, const void *buf, size_t len)
struct mio_rmidi_hdl *hdl = (struct mio_rmidi_hdl *)sh;
ssize_t n;
while ((n = write(hdl->fd, buf, len)) < 0) {
while ((n = write(hdl->fd, buf, len)) == -1) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {

View File

@ -237,7 +237,7 @@ sio_psleep(struct sio_hdl *hdl, int event)
}
for (;;) {
nfds = sio_pollfd(hdl, pfd, event);
while (poll(pfd, nfds, -1) < 0) {
while (poll(pfd, nfds, -1) == -1) {
if (errno == EINTR)
continue;
DPERROR("sio_psleep: poll");

View File

@ -81,12 +81,12 @@ sio_sun_adjpar(struct sio_sun_hdl *hdl, struct audio_swpar *ap)
{
if (hdl->sio.eof)
return 0;
if (ioctl(hdl->fd, AUDIO_SETPAR, ap)) {
if (ioctl(hdl->fd, AUDIO_SETPAR, ap) == -1) {
DPERROR("AUDIO_SETPAR");
hdl->sio.eof = 1;
return 0;
}
if (ioctl(hdl->fd, AUDIO_GETPAR, ap)) {
if (ioctl(hdl->fd, AUDIO_GETPAR, ap) == -1) {
DPERROR("AUDIO_GETPAR");
hdl->sio.eof = 1;
return 0;
@ -165,7 +165,7 @@ sio_sun_getcap(struct sio_hdl *sh, struct sio_cap *cap)
unsigned int enc_map = 0, rchan_map = 0, pchan_map = 0, rate_map;
unsigned int i, j, conf;
if (ioctl(hdl->fd, AUDIO_GETPAR, &savepar)) {
if (ioctl(hdl->fd, AUDIO_GETPAR, &savepar) == -1) {
DPERROR("AUDIO_GETPAR");
hdl->sio.eof = 1;
return 0;
@ -258,7 +258,7 @@ sio_sun_getcap(struct sio_hdl *sh, struct sio_cap *cap)
}
cap->nconf = nconf;
if (ioctl(hdl->fd, AUDIO_SETPAR, &savepar)) {
if (ioctl(hdl->fd, AUDIO_SETPAR, &savepar) == -1) {
DPERROR("AUDIO_SETPAR");
hdl->sio.eof = 1;
return 0;
@ -304,7 +304,7 @@ sio_sun_getfd(const char *str, unsigned int mode, int nbio)
flags = O_RDWR;
else
flags = (mode & SIO_PLAY) ? O_WRONLY : O_RDONLY;
while ((fd = open(path, flags | O_NONBLOCK | O_CLOEXEC)) < 0) {
while ((fd = open(path, flags | O_NONBLOCK | O_CLOEXEC)) == -1) {
if (errno == EINTR)
continue;
DPERROR(path);
@ -329,7 +329,7 @@ sio_sun_fdopen(int fd, unsigned int mode, int nbio)
/*
* pause the device
*/
if (ioctl(fd, AUDIO_STOP) < 0) {
if (ioctl(fd, AUDIO_STOP) == -1) {
DPERROR("AUDIO_STOP");
free(hdl);
return NULL;
@ -346,12 +346,12 @@ _sio_sun_open(const char *str, unsigned int mode, int nbio)
int fd;
fd = sio_sun_getfd(str, mode, nbio);
if (fd < 0)
if (fd == -1)
return NULL;
hdl = sio_sun_fdopen(fd, mode, nbio);
if (hdl != NULL)
return hdl;
while (close(fd) < 0 && errno == EINTR)
while (close(fd) == -1 && errno == EINTR)
; /* retry */
return NULL;
}
@ -361,7 +361,7 @@ sio_sun_close(struct sio_hdl *sh)
{
struct sio_sun_hdl *hdl = (struct sio_sun_hdl *)sh;
while (close(hdl->fd) < 0 && errno == EINTR)
while (close(hdl->fd) == -1 && errno == EINTR)
; /* retry */
free(hdl);
}
@ -390,7 +390,7 @@ sio_sun_start(struct sio_hdl *sh)
/*
* no play buffers to fill, start now!
*/
if (ioctl(hdl->fd, AUDIO_START) < 0) {
if (ioctl(hdl->fd, AUDIO_START) == -1) {
DPERROR("AUDIO_START");
hdl->sio.eof = 1;
return 0;
@ -409,7 +409,7 @@ sio_sun_stop(struct sio_hdl *sh)
hdl->filling = 0;
return 1;
}
if (ioctl(hdl->fd, AUDIO_STOP) < 0) {
if (ioctl(hdl->fd, AUDIO_STOP) == -1) {
DPERROR("AUDIO_STOP");
hdl->sio.eof = 1;
return 0;
@ -444,7 +444,7 @@ sio_sun_setpar(struct sio_hdl *sh, struct sio_par *par)
ap.round = par->appbufsz / 2;
ap.nblks = 2;
}
if (ioctl(hdl->fd, AUDIO_SETPAR, &ap) < 0) {
if (ioctl(hdl->fd, AUDIO_SETPAR, &ap) == -1) {
DPERROR("AUDIO_SETPAR");
hdl->sio.eof = 1;
return 0;
@ -458,7 +458,7 @@ sio_sun_getpar(struct sio_hdl *sh, struct sio_par *par)
struct sio_sun_hdl *hdl = (struct sio_sun_hdl *)sh;
struct audio_swpar ap;
if (ioctl(hdl->fd, AUDIO_GETPAR, &ap) < 0) {
if (ioctl(hdl->fd, AUDIO_GETPAR, &ap) == -1) {
DPERROR("AUDIO_GETPAR");
hdl->sio.eof = 1;
return 0;
@ -483,7 +483,7 @@ sio_sun_read(struct sio_hdl *sh, void *buf, size_t len)
struct sio_sun_hdl *hdl = (struct sio_sun_hdl *)sh;
ssize_t n;
while ((n = read(hdl->fd, buf, len)) < 0) {
while ((n = read(hdl->fd, buf, len)) == -1) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
@ -508,7 +508,7 @@ sio_sun_write(struct sio_hdl *sh, const void *buf, size_t len)
ssize_t n, todo;
todo = len;
while ((n = write(hdl->fd, data, todo)) < 0) {
while ((n = write(hdl->fd, data, todo)) == -1) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
@ -536,7 +536,7 @@ sio_sun_pollfd(struct sio_hdl *sh, struct pollfd *pfd, int events)
if (hdl->filling && hdl->sio.wused == hdl->sio.par.bufsz *
hdl->sio.par.pchan * hdl->sio.par.bps) {
hdl->filling = 0;
if (ioctl(hdl->fd, AUDIO_START) < 0) {
if (ioctl(hdl->fd, AUDIO_START) == -1) {
DPERROR("AUDIO_START");
hdl->sio.eof = 1;
return 0;
@ -557,7 +557,7 @@ sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd)
if ((pfd->revents & POLLHUP) ||
(pfd->revents & (POLLIN | POLLOUT)) == 0)
return pfd->revents;
if (ioctl(hdl->fd, AUDIO_GETPOS, &ap) < 0) {
if (ioctl(hdl->fd, AUDIO_GETPOS, &ap) == -1) {
DPERROR("sio_sun_revents: GETPOS");
hdl->sio.eof = 1;
return POLLHUP;

View File

@ -98,7 +98,7 @@ main(int argc, char **argv)
ifd = STDIN_FILENO;
else {
ifd = open(ifile, O_RDONLY, 0);
if (ifd < 0) {
if (ifd == -1) {
perror(ifile);
return 1;
}
@ -108,7 +108,7 @@ main(int argc, char **argv)
ofd = STDOUT_FILENO;
else {
ofd = open(ofile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (ofd < 0) {
if (ofd == -1) {
perror(ofile);
return 1;
}
@ -147,7 +147,7 @@ main(int argc, char **argv)
len = read(ifd, buf, sizeof(buf));
if (len == 0)
break;
if (len < 0) {
if (len == -1) {
perror("stdin");
break;
}

View File

@ -395,7 +395,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();
@ -441,7 +441,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();
}

View File

@ -86,12 +86,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;
@ -100,12 +100,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;
@ -155,14 +155,14 @@ 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;
@ -175,19 +175,19 @@ listen_new_tcp(char *addr, unsigned int port)
*/
opt = 1;
if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
&opt, sizeof(int)) < 0) {
&opt, sizeof(int)) == -1) {
log_puts(addr);
log_puts(": failed to set IPV6_V6ONLY\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;
@ -247,14 +247,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;
@ -262,7 +262,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;

View File

@ -227,11 +227,11 @@ setsig(void)
sigfillset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sa.sa_handler = sigint;
if (sigaction(SIGINT, &sa, NULL) < 0)
if (sigaction(SIGINT, &sa, NULL) == -1)
err(1, "sigaction(int) failed");
if (sigaction(SIGTERM, &sa, NULL) < 0)
if (sigaction(SIGTERM, &sa, NULL) == -1)
err(1, "sigaction(term) failed");
if (sigaction(SIGHUP, &sa, NULL) < 0)
if (sigaction(SIGHUP, &sa, NULL) == -1)
err(1, "sigaction(hup) failed");
}
@ -243,11 +243,11 @@ unsetsig(void)
sigfillset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sa.sa_handler = SIG_DFL;
if (sigaction(SIGHUP, &sa, NULL) < 0)
if (sigaction(SIGHUP, &sa, NULL) == -1)
err(1, "unsetsig(hup): sigaction failed");
if (sigaction(SIGTERM, &sa, NULL) < 0)
if (sigaction(SIGTERM, &sa, NULL) == -1)
err(1, "unsetsig(term): sigaction failed");
if (sigaction(SIGINT, &sa, NULL) < 0)
if (sigaction(SIGINT, &sa, NULL) == -1)
err(1, "unsetsig(int): sigaction failed");
}
@ -267,12 +267,12 @@ getbasepath(char *base)
snprintf(base, SOCKPATH_MAX, SOCKPATH_DIR "-%u", uid);
}
omask = umask(mask);
if (mkdir(base, 0777) < 0) {
if (mkdir(base, 0777) == -1) {
if (errno != EEXIST)
err(1, "mkdir(\"%s\")", base);
}
umask(omask);
if (stat(base, &sb) < 0)
if (stat(base, &sb) == -1)
err(1, "stat(\"%s\")", base);
if (!S_ISDIR(sb.st_mode))
errx(1, "%s is not a directory", base);
@ -505,15 +505,15 @@ main(int argc, char **argv)
if (background) {
log_flush();
log_level = 0;
if (daemon(0, 0) < 0)
if (daemon(0, 0) == -1)
err(1, "daemon");
}
if (pw != NULL) {
if (setpriority(PRIO_PROCESS, 0, SNDIO_PRIO) < 0)
if (setpriority(PRIO_PROCESS, 0, SNDIO_PRIO) == -1)
err(1, "setpriority");
if (setgroups(1, &pw->pw_gid) ||
setgid(pw->pw_gid) ||
setuid(pw->pw_uid))
if (setgroups(1, &pw->pw_gid) == -1 ||
setgid(pw->pw_gid) == -1 ||
setuid(pw->pw_uid) == -1)
err(1, "cannot drop privileges");
}
for (;;) {

View File

@ -321,7 +321,7 @@ sock_fdwrite(struct sock *f, void *data, int count)
int n;
n = write(f->fd, data, count);
if (n < 0) {
if (n == -1) {
#ifdef DEBUG
if (errno == EFAULT) {
log_puts("sock_fdwrite: fault\n");
@ -362,7 +362,7 @@ sock_fdread(struct sock *f, void *data, int count)
int n;
n = read(f->fd, data, count);
if (n < 0) {
if (n == -1) {
#ifdef DEBUG
if (errno == EFAULT) {
log_puts("sock_fdread: fault\n");