syslogd(8): timed out waiting for child

From: Martin Blapp <mb_at_imp.ch>
Date: Tue, 25 May 2004 23:36:54 +0200 (CEST)
And even more, each time after kill -HUP, syslogd has been blocked for ever.
After a while I found the the problem: a locked locked terminal ... After I've
removed the lock, kill -HUP was possible again without any problems anymore.

It looks like we missed a OpenBSD patch. The OpenBSD syslogd
has now privseparation. Anybody execpt me has some interest int his area ?

Martin

 Revision 1.43 / (download) - annotate - [select for diffs] , Fri Aug 3 20:24:16
2001 UTC (2 years, 9 months ago) by millert
Branch: MAIN
CVS Tags: OPENBSD_3_0_BASE, OPENBSD_3_0
Changes since 1.42: +26 -11 lines
Diff to previous 1.42 (colored)

Open files with O_NONBLOCK but turn off non-blocking mode for
non-ttys.  If write(2) returns EAGAIN just ignore the error and
move on.  This prevents a locked terminal from causing syslogd
grief.  If we ever want to support logging to a fifo this will
probably have to be revisited.

diff -u -r1.42 -r1.43
--- src/usr.sbin/syslogd/syslogd.c	2001/08/03 19:09:26	1.42
+++ src/usr.sbin/syslogd/syslogd.c	2001/08/03 20:24:16	1.43
_at__at_ -1,4 +1,4 _at__at_
-/*	$OpenBSD: syslogd.c,v 1.42 2001/08/03 19:09:26 deraadt Exp $	*/
+/*	$OpenBSD: syslogd.c,v 1.43 2001/08/03 20:24:16 millert Exp $	*/

 /*
  * Copyright (c) 1983, 1988, 1993, 1994
_at__at_ -43,7 +43,7 _at__at_
 #if 0
 static char sccsid[] = "_at_(#)syslogd.c	8.3 (Berkeley) 4/4/94";
 #else
-static char rcsid[] = "$OpenBSD: syslogd.c,v 1.42 2001/08/03 19:09:26 deraadt
Exp $";
+static char rcsid[] = "$OpenBSD: syslogd.c,v 1.43 2001/08/03 20:24:16 millert
Exp $";
 #endif
 #endif /* not lint */

_at__at_ -589,7 +589,7 _at__at_
 	/* log the message to the particular outputs */
 	if (!Initialized) {
 		f = &consfile;
-		f->f_file = open(ctty, O_WRONLY, 0);
+		f->f_file = open(ctty, O_WRONLY|O_NONBLOCK, 0);

 		if (f->f_file >= 0) {
 			fprintlog(f, flags, msg);
_at__at_ -758,9 +758,16 _at__at_
 			/*
 			 * Check for errors on TTY's due to loss of tty
 			 */
-			if ((e == EIO || e == EBADF) && f->f_type != F_FILE) {
+			if (e == EAGAIN) {
+				/*
+				 * Silently drop messages on blocked write.
+				 * This can happen when logging to a locked tty.
+				 */
+				break;
+			} else if ((e == EIO || e == EBADF) &&
+			    f->f_type != F_FILE) {
 				f->f_file = open(f->f_un.f_fname,
-				    O_WRONLY|O_APPEND, 0);
+				    O_WRONLY|O_APPEND|O_NONBLOCK, 0);
 				if (f->f_file < 0) {
 					f->f_type = F_UNUSED;
 					logerror(f->f_un.f_fname);
_at__at_ -1213,17 +1220,25 _at__at_

 	case '/':
 		(void)strlcpy(f->f_un.f_fname, p, sizeof(f->f_un.f_fname));
-		if ((f->f_file = open(p, O_WRONLY|O_APPEND, 0)) < 0) {
+		f->f_file = open(p, O_WRONLY|O_APPEND|O_NONBLOCK, 0);
+		if (f->f_file < 0) {
 			f->f_type = F_UNUSED;
 			logerror(p);
 			break;
 		}
-		if (isatty(f->f_file))
-			f->f_type = F_TTY;
-		else
+		if (isatty(f->f_file)) {
+			if (strcmp(p, ctty) == 0)
+				f->f_type = F_CONSOLE;
+			else
+				f->f_type = F_TTY;
+		} else {
 			f->f_type = F_FILE;
-		if (strcmp(p, ctty) == 0)
-			f->f_type = F_CONSOLE;
+			/* Clear O_NONBLOCK flag on f->f_file */
+			if ((i = fcntl(f->f_file, F_GETFL, 0)) != -1) {
+				i &= ~O_NONBLOCK;
+				fcntl(f->f_file, F_SETFL, i);
+			}
+		}
 		break;

 	case '*':
Received on Tue May 25 2004 - 12:40:24 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:55 UTC