Date: Wed, 2 Mar 2005 18:37:44 +0000 (GMT) From: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk> To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org Subject: Re: bin/78304: Signal handler abuse in comsat(8) Message-ID: <20050302183348.L85538@ury.york.ac.uk> In-Reply-To: <200503021520.j22FKDiS080979@freefall.freebsd.org> References: <200503021520.j22FKDiS080979@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Sorry, attached an earlier version of the patch by mistake. Copy of it at http://www.devrandom.co.uk/freebsd/comsat-sigs.patch incase my mail reader has mangled this copy. Gavin --- comsat-sigs.patch begins here --- Index: src/libexec/comsat/comsat.c =================================================================== RCS file: /usr/cvs/src/libexec/comsat/comsat.c,v retrieving revision 1.17 diff -u -r1.17 comsat.c --- src/libexec/comsat/comsat.c 14 Feb 2005 17:42:56 -0000 1.17 +++ src/libexec/comsat/comsat.c 28 Feb 2005 00:07:10 -0000 @@ -77,11 +77,13 @@ struct utmp *utmp = NULL; time_t lastmsgtime; int nutmp, uf; +volatile sig_atomic_t needreadutmp = 0; void jkfprintf(FILE *, char[], char[], off_t); void mailfor(char *); void notify(struct utmp *, char[], off_t, int); void onalrm(int); +void readutmp(void); void reapchildren(int); int @@ -109,11 +111,16 @@ } (void)time(&lastmsgtime); (void)gethostname(hostname, sizeof(hostname)); - onalrm(0); + readutmp(); (void)signal(SIGALRM, onalrm); (void)signal(SIGTTOU, SIG_IGN); (void)signal(SIGCHLD, reapchildren); for (;;) { + if (needreadutmp) { + needreadutmp = 0; + readutmp(); + } + cc = recv(0, msgbuf, sizeof(msgbuf) - 1, 0); if (cc <= 0) { if (errno != EINTR) @@ -134,12 +141,22 @@ void reapchildren(int signo) { - while (wait3(NULL, WNOHANG, NULL) > 0); + int save_errno = errno; + + while (wait3(NULL, WNOHANG, NULL) > 0) + ; + errno = save_errno; } void onalrm(int signo) { + needreadutmp = 1; +} + +void +readutmp(void) +{ static u_int utmpsize; /* last malloced size for utmp */ static u_int utmpmtime; /* last modification time for utmp */ struct stat statbf; --- comsat-sigs.patch ends here ---
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050302183348.L85538>