summaryrefslogtreecommitdiff
path: root/usr.bin/aucat
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2012-03-29 20:08:23 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2012-03-29 20:08:23 +0000
commite864416cb181bb187bca7663761ae743b5f8452f (patch)
tree42de5f797ebbd72bf5b84687ce97222ff56512db /usr.bin/aucat
parent4cc5d79756d6e7b0698de79b261f87f45c4dfe9d (diff)
Don't spin if accept() fails because it is out of file descriptors,
instead set a flag that skips the listening socket from the poll() event loop. The flag is cleared whenever a file descriptor is closed allowing accept() to be retried. Explained by deraadt@
Diffstat (limited to 'usr.bin/aucat')
-rw-r--r--usr.bin/aucat/file.c3
-rw-r--r--usr.bin/aucat/file.h3
-rw-r--r--usr.bin/aucat/listen.c15
-rw-r--r--usr.bin/aucat/pipe.c1
4 files changed, 15 insertions, 7 deletions
diff --git a/usr.bin/aucat/file.c b/usr.bin/aucat/file.c
index fb9f7b44dbb..819800c2b28 100644
--- a/usr.bin/aucat/file.c
+++ b/usr.bin/aucat/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.28 2011/10/12 07:20:04 ratchov Exp $ */
+/* $OpenBSD: file.c,v 1.29 2012/03/29 20:08:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -73,6 +73,7 @@ struct timespec file_ts;
struct filelist file_list;
struct timo *timo_queue;
unsigned timo_abstime;
+int file_slowaccept = 0;
#ifdef DEBUG
long long file_wtime, file_utime;
#endif
diff --git a/usr.bin/aucat/file.h b/usr.bin/aucat/file.h
index 094d62fb092..fdaddfa6d46 100644
--- a/usr.bin/aucat/file.h
+++ b/usr.bin/aucat/file.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.h,v 1.12 2011/11/20 22:54:51 ratchov Exp $ */
+/* $OpenBSD: file.h,v 1.13 2012/03/29 20:08:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -68,6 +68,7 @@ struct file {
LIST_HEAD(filelist,file);
extern struct filelist file_list;
+extern int file_slowaccept;
#ifdef DEBUG
extern long long file_wtime, file_utime;
diff --git a/usr.bin/aucat/listen.c b/usr.bin/aucat/listen.c
index 2a635939718..5c79e71407c 100644
--- a/usr.bin/aucat/listen.c
+++ b/usr.bin/aucat/listen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: listen.c,v 1.17 2011/10/12 07:20:04 ratchov Exp $ */
+/* $OpenBSD: listen.c,v 1.18 2012/03/29 20:08:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -174,6 +174,8 @@ listen_pollfd(struct file *file, struct pollfd *pfd, int events)
{
struct listen *f = (struct listen *)file;
+ if (file_slowaccept)
+ return 0;
pfd->fd = f->fd;
pfd->events = POLLIN;
return 1;
@@ -189,10 +191,13 @@ listen_revents(struct file *file, struct pollfd *pfd)
if (pfd->revents & POLLIN) {
caddrlen = sizeof(caddrlen);
- sock = accept(f->fd, &caddr, &caddrlen);
- if (sock < 0) {
- /* XXX: should we kill the socket here ? */
- perror("accept");
+ while ((sock = accept(f->fd, &caddr, &caddrlen)) < 0) {
+ if (errno == EINTR)
+ continue;
+ if (errno == ENFILE || errno == EMFILE)
+ file_slowaccept = 1;
+ else
+ perror("accept");
return 0;
}
if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
diff --git a/usr.bin/aucat/pipe.c b/usr.bin/aucat/pipe.c
index 83900920095..528f7f47688 100644
--- a/usr.bin/aucat/pipe.c
+++ b/usr.bin/aucat/pipe.c
@@ -139,6 +139,7 @@ pipe_close(struct file *file)
struct pipe *f = (struct pipe *)file;
close(f->fd);
+ file_slowaccept = 0;
}
off_t