diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-01-11 22:36:23 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-01-11 22:36:23 +0000 |
commit | f5b2a5ddee3438479deb91eb0385729c99013974 (patch) | |
tree | 8d832ada3150e72740cc9be47436990556201e38 | |
parent | c38fdd35e74972b43fbb1adf46d859873f5a564f (diff) |
change signal handler to set a flag, and then in the main loop do
the work that this handler used to do. many signal handlers in the
tree should be changed to this, since a large percentage of them
have raceable stuff in them; like mixing malloc's and stdio inside and
outside the handler.. terrrible stuff
-rw-r--r-- | libexec/comsat/comsat.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/libexec/comsat/comsat.c b/libexec/comsat/comsat.c index 345478778d9..d744d2df7d4 100644 --- a/libexec/comsat/comsat.c +++ b/libexec/comsat/comsat.c @@ -39,7 +39,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)comsat.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$Id: comsat.c,v 1.12 1999/08/17 09:13:13 millert Exp $"; +static char rcsid[] = "$Id: comsat.c,v 1.13 2001/01/11 22:36:22 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -78,9 +78,12 @@ int nutmp, uf; void jkfprintf __P((FILE *, char[], off_t)); void mailfor __P((char *)); void notify __P((struct utmp *, off_t)); -void onalrm __P((int)); +void readutmp __P((int)); +void doreadutmp __P((void)); void reapchildren __P((int)); +volatile int wantreadutmp; + int main(argc, argv) int argc; @@ -112,8 +115,8 @@ main(argc, argv) } (void)time(&lastmsgtime); (void)gethostname(hostname, sizeof(hostname)); - onalrm(0); - (void)signal(SIGALRM, onalrm); + doreadutmp(); + (void)signal(SIGALRM, readutmp); (void)signal(SIGTTOU, SIG_IGN); (void)signal(SIGCHLD, reapchildren); for (;;) { @@ -121,7 +124,10 @@ main(argc, argv) if (cc <= 0) { if (errno != EINTR) sleep(1); - errno = 0; + if (wantreadutmp) { + doreadutmp(); + wantreadutmp = 0; + } continue; } if (!nutmp) /* no one has logged in yet */ @@ -143,14 +149,21 @@ reapchildren(signo) { int save_errno = errno; - while (wait3(NULL, WNOHANG, NULL) > 0); + while (wait3(NULL, WNOHANG, NULL) > 0) + ; errno = save_errno; } void -onalrm(signo) +readutmp(signo) int signo; { + wantreadutmp = 1; +} + +void +doreadutmp(void) +{ static u_int utmpsize; /* last malloced size for utmp */ static u_int utmpmtime; /* last modification time for utmp */ struct stat statbf; |