diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-11-18 23:45:40 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-11-18 23:45:40 +0000 |
commit | 84fe7a9a05c8bd0fb05516042646f86a823ab65f (patch) | |
tree | 71955038d54c7cda40a88771eecd8e92514a6149 /libexec/rpc.rstatd | |
parent | 77c3ec8597fc2749319d987267543fba284c40f1 (diff) |
create own svc_run(), which can do updating outside of a signal handler
Diffstat (limited to 'libexec/rpc.rstatd')
-rw-r--r-- | libexec/rpc.rstatd/rstat_proc.c | 24 | ||||
-rw-r--r-- | libexec/rpc.rstatd/rstatd.c | 66 |
2 files changed, 73 insertions, 17 deletions
diff --git a/libexec/rpc.rstatd/rstat_proc.c b/libexec/rpc.rstatd/rstat_proc.c index 511f2b533f8..5d0d933230d 100644 --- a/libexec/rpc.rstatd/rstat_proc.c +++ b/libexec/rpc.rstatd/rstat_proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rstat_proc.c,v 1.19 2001/11/06 19:18:30 art Exp $ */ +/* $OpenBSD: rstat_proc.c,v 1.20 2001/11/18 23:45:39 deraadt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -31,7 +31,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)rpc.rstatd.c 1.1 86/09/25 Copyr 1984 Sun Micro";*/ /*static char sccsid[] = "from: @(#)rstat_proc.c 2.2 88/08/01 4.0 RPCSRC";*/ -static char rcsid[] = "$OpenBSD: rstat_proc.c,v 1.19 2001/11/06 19:18:30 art Exp $"; +static char rcsid[] = "$OpenBSD: rstat_proc.c,v 1.20 2001/11/18 23:45:39 deraadt Exp $"; #endif /* @@ -87,9 +87,11 @@ union { struct statstime s3; } stats_all; -int stats_service(); -void updatestat(int); -void setup(void); +void updatestat(void); +void updatestatsig(int sig); +void setup(void); + +volatile sig_atomic_t wantupdatestat; static int stat_is_init = 0; @@ -102,8 +104,8 @@ stat_init() { stat_is_init = 1; setup(); - updatestat(0); - (void) signal(SIGALRM, updatestat); /* XXX huge signal race */ + updatestat(); + (void) signal(SIGALRM, updatestatsig); alarm(1); } @@ -171,7 +173,13 @@ rstatproc_havedisk_1_svc(arg, rqstp) } void -updatestat(int sig) +updatestatsig(int sig) +{ + wantupdatestat = 1; +} + +void +updatestat() { int i, mib[2], save_errno = errno; struct uvmexp uvmexp; diff --git a/libexec/rpc.rstatd/rstatd.c b/libexec/rpc.rstatd/rstatd.c index 2f20a8020d4..98d50c61e65 100644 --- a/libexec/rpc.rstatd/rstatd.c +++ b/libexec/rpc.rstatd/rstatd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rstatd.c,v 1.6 2001/07/08 21:18:10 deraadt Exp $ */ +/* $OpenBSD: rstatd.c,v 1.7 2001/11/18 23:45:39 deraadt Exp $ */ /*- * Copyright (c) 1993, John Brezak @@ -34,19 +34,27 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: rstatd.c,v 1.6 2001/07/08 21:18:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: rstatd.c,v 1.7 2001/11/18 23:45:39 deraadt Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/socket.h> #include <stdio.h> -#include <rpc/rpc.h> +#include <stdlib.h> +#include <unistd.h> #include <signal.h> #include <syslog.h> +#include <errno.h> #include <stdlib.h> +#include <rpc/rpc.h> #include <rpcsvc/rstat.h> -extern void rstat_service(); +extern int __svc_fdsetsize; +extern fd_set *__svc_fdset; +extern void svc_getreqset2 __P((fd_set *, int)); +extern void rstat_service(struct svc_req *, SVCXPRT *); + +void my_svc_run(void); int from_inetd = 1; /* started from inetd ? */ int closedown = 20; /* how long to wait before going dormant */ @@ -65,11 +73,9 @@ main(argc, argv) int argc; char *argv[]; { - SVCXPRT *transp; - int sock = 0; - int proto = 0; + int sock = 0, proto = 0, fromlen; struct sockaddr_in from; - int fromlen; + SVCXPRT *transp; if (argc == 2) closedown = atoi(argv[1]); @@ -118,7 +124,49 @@ main(argc, argv) exit(1); } - svc_run(); + my_svc_run(); syslog(LOG_ERR, "svc_run returned"); exit(1); } + +void +my_svc_run() +{ + extern volatile sig_atomic_t wantupdatestat; + extern void updatestat(void); + fd_set *fds; + + for (;;) { + if (wantupdatestat) { + updatestat(); + wantupdatestat = 0; + } + + 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)) { + case -1: + if (errno == EINTR) { + if (fds) + free(fds); + continue; + } + perror("svc_run: - select failed"); + if (fds) + free(fds); + return; + case 0: + if (fds) + free(fds); + continue; + default: + svc_getreqset2(fds, svc_maxfd+1); + free(fds); + } + } +} |