diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2009-02-04 20:35:15 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2009-02-04 20:35:15 +0000 |
commit | 751b5132bb874db9601b5e853ac78ff29a04c113 (patch) | |
tree | 0ef4b3d6bdf7c751c265d0a271d12d74eb8a8710 /usr.bin/aucat | |
parent | ee4dbb556fd6b40c4aba4483d9401e7ebaf7bf2c (diff) |
if there are too many connections, stop acceping new ones rather
than exit()ing with ``too many open files'' fatal error
Diffstat (limited to 'usr.bin/aucat')
-rw-r--r-- | usr.bin/aucat/aucat.c | 12 | ||||
-rw-r--r-- | usr.bin/aucat/file.c | 9 | ||||
-rw-r--r-- | usr.bin/aucat/listen.c | 22 | ||||
-rw-r--r-- | usr.bin/aucat/pipe.c | 2 | ||||
-rw-r--r-- | usr.bin/aucat/safile.c | 11 | ||||
-rw-r--r-- | usr.bin/aucat/sock.c | 4 | ||||
-rw-r--r-- | usr.bin/aucat/wav.c | 4 |
7 files changed, 48 insertions, 16 deletions
diff --git a/usr.bin/aucat/aucat.c b/usr.bin/aucat/aucat.c index 5ae6ea236bb..21947cd89b9 100644 --- a/usr.bin/aucat/aucat.c +++ b/usr.bin/aucat/aucat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aucat.c,v 1.56 2009/02/04 08:00:33 ratchov Exp $ */ +/* $OpenBSD: aucat.c,v 1.57 2009/02/04 20:35:14 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -267,6 +267,11 @@ newinput(struct farg *fa) * XXX : we should round rate, right ? */ f = wav_new_in(&wav_ops, fd, fa->name, &fa->ipar, fa->hdr); + if (f == NULL) { + if (fd != STDIN_FILENO) + close(fd); + return; + } nfr = dev_bufsz * fa->ipar.rate / dev_rate; buf = abuf_new(nfr, &fa->ipar); proc = rpipe_new((struct file *)f); @@ -304,6 +309,11 @@ newoutput(struct farg *fa) * XXX : we should round rate, right ? */ f = wav_new_out(&wav_ops, fd, fa->name, &fa->opar, fa->hdr); + if (f == NULL) { + if (fd != STDOUT_FILENO) + close(fd); + return; + } nfr = dev_bufsz * fa->opar.rate / dev_rate; proc = wpipe_new((struct file *)f); buf = abuf_new(nfr, &fa->opar); diff --git a/usr.bin/aucat/file.c b/usr.bin/aucat/file.c index 3a4e1beb938..c1e37b14205 100644 --- a/usr.bin/aucat/file.c +++ b/usr.bin/aucat/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.10 2009/01/23 17:38:15 ratchov Exp $ */ +/* $OpenBSD: file.c,v 1.11 2009/02/04 20:35:14 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -68,9 +68,10 @@ file_new(struct fileops *ops, char *name, unsigned nfds) LIST_FOREACH(f, &file_list, entry) nfds += f->ops->nfds(f); - if (nfds > MAXFDS) - err(1, "%s: too many polled files", name); - + if (nfds > MAXFDS) { + DPRINTF("file_new: %s: too many polled files\n", name); + return NULL; + } f = malloc(ops->size); if (f == NULL) err(1, "file_new: %s", ops->name); diff --git a/usr.bin/aucat/listen.c b/usr.bin/aucat/listen.c index fc6a3cacaab..0851d7a461b 100644 --- a/usr.bin/aucat/listen.c +++ b/usr.bin/aucat/listen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: listen.c,v 1.7 2009/02/03 19:44:58 ratchov Exp $ */ +/* $OpenBSD: listen.c,v 1.8 2009/02/04 20:35:14 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -56,11 +56,11 @@ listen_new(struct fileops *ops, char *path, sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock < 0) { perror("socket"); - exit(1); + return NULL; } if (unlink(path) < 0 && errno != ENOENT) { perror("unlink"); - exit(1); + goto bad_close; } sockname.sun_family = AF_UNIX; strlcpy(sockname.sun_path, path, sizeof(sockname.sun_path)); @@ -68,14 +68,16 @@ listen_new(struct fileops *ops, char *path, if (bind(sock, (struct sockaddr *)&sockname, sizeof(struct sockaddr_un)) < 0) { perror("bind"); - exit(1); + goto bad_close; } umask(oldumask); if (listen(sock, 1) < 0) { perror("listen"); - exit(1); + goto bad_close; } f = (struct listen *)file_new(ops, path, 1); + if (f == NULL) + goto bad_close; f->path = strdup(path); if (f->path == NULL) { perror("strdup"); @@ -95,6 +97,9 @@ listen_new(struct fileops *ops, char *path, } #endif return f; + bad_close: + close(sock); + return NULL; } int @@ -133,8 +138,11 @@ listen_revents(struct file *file, struct pollfd *pfd) close(sock); return 0; } - (void)sock_new(&sock_ops, sock, "socket", - &f->wpar, &f->rpar, f->maxweight); + if (sock_new(&sock_ops, sock, "socket", + &f->wpar, &f->rpar, f->maxweight) == NULL) { + close(sock); + return 0; + } } return 0; } diff --git a/usr.bin/aucat/pipe.c b/usr.bin/aucat/pipe.c index ccee2e5a8d7..de0f4021947 100644 --- a/usr.bin/aucat/pipe.c +++ b/usr.bin/aucat/pipe.c @@ -30,6 +30,8 @@ pipe_new(struct fileops *ops, int fd, char *name) struct pipe *f; f = (struct pipe *)file_new(ops, name, 1); + if (f == NULL) + return NULL; f->fd = fd; return f; } diff --git a/usr.bin/aucat/safile.c b/usr.bin/aucat/safile.c index 2552de2337e..7d879bbe8dd 100644 --- a/usr.bin/aucat/safile.c +++ b/usr.bin/aucat/safile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: safile.c,v 1.10 2009/01/23 17:38:15 ratchov Exp $ */ +/* $OpenBSD: safile.c,v 1.11 2009/02/04 20:35:14 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -128,9 +128,9 @@ safile_new(struct fileops *ops, char *path, par.appbufsz = *bufsz; par.round = *round; if (!sio_setpar(hdl, &par)) - return 0; + goto bad_close; if (!sio_getpar(hdl, &par)) - return 0; + goto bad_close; if (ipar) { ipar->bits = par.bits; ipar->bps = par.bps; @@ -153,9 +153,14 @@ safile_new(struct fileops *ops, char *path, *round = par.round; DPRINTF("safile_new: using %u(%u) fpb\n", *bufsz, *round); f = (struct safile *)file_new(ops, "hdl", sio_nfds(hdl)); + if (f == NULL) + goto bad_close; f->hdl = hdl; sio_onmove(f->hdl, safile_cb, f); return f; + bad_close: + sio_close(hdl); + return NULL; } void diff --git a/usr.bin/aucat/sock.c b/usr.bin/aucat/sock.c index 85b9ba02e98..41b736161ad 100644 --- a/usr.bin/aucat/sock.c +++ b/usr.bin/aucat/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.12 2009/01/23 17:38:15 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.13 2009/02/04 20:35:14 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -273,6 +273,8 @@ sock_new(struct fileops *ops, int fd, char *name, struct sock *f; f = (struct sock *)pipe_new(ops, fd, name); + if (f == NULL) + return NULL; f->pstate = SOCK_INIT; f->mode = 0; if (dev_rec) { diff --git a/usr.bin/aucat/wav.c b/usr.bin/aucat/wav.c index 212fd2d7fff..1502488cfbf 100644 --- a/usr.bin/aucat/wav.c +++ b/usr.bin/aucat/wav.c @@ -35,6 +35,8 @@ wav_new_in(struct fileops *ops, int fd, char *name, struct wav *f; f = (struct wav *)pipe_new(ops, fd, name); + if (f == NULL) + return NULL; if (hdr == HDR_WAV) { if (!wav_readhdr(f->pipe.fd, par, &f->rbytes)) exit(1); @@ -52,6 +54,8 @@ wav_new_out(struct fileops *ops, int fd, char *name, struct wav *f; f = (struct wav *)pipe_new(ops, fd, name); + if (f == NULL) + return NULL; if (hdr == HDR_WAV) { par->le = 1; par->sig = (par->bits <= 8) ? 0 : 1; |