summaryrefslogtreecommitdiffstats
path: root/libexec/rpc.rstatd
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2005-09-16 23:50:33 +0000
committerderaadt <deraadt@openbsd.org>2005-09-16 23:50:33 +0000
commitfcc5cfe849ef19d756c950c7d55f05a88f1d234c (patch)
treecf1d8968ac2a8307fbd81c9ab9d96dba001cff7d /libexec/rpc.rstatd
parentif tokendb_open() failed, do not crash if tokendb_close() is called (diff)
downloadwireguard-openbsd-fcc5cfe849ef19d756c950c7d55f05a88f1d234c.tar.xz
wireguard-openbsd-fcc5cfe849ef19d756c950c7d55f05a88f1d234c.zip
use poll() instead of select(), pr4502, alexander.farber@gmail.com
Diffstat (limited to 'libexec/rpc.rstatd')
-rw-r--r--libexec/rpc.rstatd/rstatd.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/libexec/rpc.rstatd/rstatd.c b/libexec/rpc.rstatd/rstatd.c
index a3af17f69f1..d1b8921b3c7 100644
--- a/libexec/rpc.rstatd/rstatd.c
+++ b/libexec/rpc.rstatd/rstatd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rstatd.c,v 1.20 2004/09/16 10:53:03 otto Exp $ */
+/* $OpenBSD: rstatd.c,v 1.21 2005/09/16 23:50:33 deraadt Exp $ */
/*-
* Copyright (c) 1993, John Brezak
@@ -29,7 +29,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: rstatd.c,v 1.20 2004/09/16 10:53:03 otto Exp $";
+static char rcsid[] = "$OpenBSD: rstatd.c,v 1.21 2005/09/16 23:50:33 deraadt Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -53,7 +53,7 @@ extern void rstat_service(struct svc_req *, SVCXPRT *);
void my_svc_run(void);
-int from_inetd = 1; /* started from inetd ? */
+int from_inetd = 1; /* started from inetd ? */
int closedown = 20; /* how long to wait before going dormant */
volatile sig_atomic_t gotsig;
@@ -149,7 +149,8 @@ my_svc_run(void)
{
extern volatile sig_atomic_t wantupdatestat;
extern void updatestat(void);
- fd_set *fds;
+ struct pollfd *pfd = NULL, *newp;
+ int nready, saved_max_pollfd = 0;
for (;;) {
if (wantupdatestat) {
@@ -162,32 +163,30 @@ my_svc_run(void)
(void) pmap_unset(RSTATPROG, RSTATVERS_ORIG);
exit(0);
}
+ if (svc_max_pollfd > saved_max_pollfd) {
+ newp = realloc(pfd, sizeof(*pfd) * svc_max_pollfd);
+ if (newp == NULL) {
+ free(pfd);
+ perror("svc_run: - realloc failed");
+ return;
+ }
+ pfd = newp;
+ saved_max_pollfd = svc_max_pollfd;
+ }
+ memcpy(pfd, svc_pollfd, sizeof(*pfd) * svc_max_pollfd);
- if (__svc_fdset) {
- int bytes = howmany(__svc_fdsetsize, NFDBITS) *
- sizeof(fd_mask);
- fds = (fd_set *)malloc(bytes); /* XXX */
- memcpy(fds, __svc_fdset, bytes);
- } else
- fds = NULL;
- switch (select(svc_maxfd+1, fds, 0, 0, (struct timeval *)0)) {
+ nready = poll(pfd, svc_max_pollfd, INFTIM);
+ switch (nready) {
case -1:
- if (errno == EINTR) {
- if (fds)
- free(fds);
+ if (errno == EINTR)
continue;
- }
- perror("svc_run: - select failed");
- if (fds)
- free(fds);
+ perror("svc_run: - poll failed");
+ free(pfd);
return;
case 0:
- if (fds)
- free(fds);
continue;
default:
- svc_getreqset2(fds, svc_maxfd+1);
- free(fds);
+ svc_getreq_poll(pfd, nready);
}
}
}