bin/78304: Signal handler abuse in comsat(8)

Gavin Atkinson gavin.atkinson at ury.york.ac.uk
Wed Mar 2 18:37:47 GMT 2005


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 ---



More information about the freebsd-bugs mailing list