Re: syslogd(8): timed out waiting for child

From: Martin Blapp <mb_at_imp.ch>
Date: Tue, 25 May 2004 23:57:45 +0200 (CEST)
and here is the patch adapted for current ...

--- syslogd.c.orig	Tue May 25 23:52:28 2004
+++ syslogd.c	Tue May 25 23:50:55 2004
_at__at_ -881,7 +881,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) {
 			(void)strlcpy(f->f_lasttime, timestamp,
_at__at_ -1135,12 +1135,34 _at__at_
 		dprintf(" %s\n", f->f_un.f_fname);
 		v->iov_base = "\n";
 		v->iov_len = 1;
+	again:
 		if (writev(f->f_file, iov, 7) < 0) {
 			int e = errno;
 			(void)close(f->f_file);
-			f->f_type = F_UNUSED;
-			errno = e;
-			logerror(f->f_un.f_fname);
+
+			/*
+			 * Check for errors on TTY's due to loss of tty
+			 */
+			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|O_NONBLOCK, 0);
+				if (f->f_file < 0) {
+					f->f_type = F_UNUSED;
+					logerror(f->f_un.f_fname);
+				} else
+					goto again;
+			} else {
+				f->f_type = F_UNUSED;
+				errno = e;
+				logerror(f->f_un.f_fname);
+			}
 		} else if (f->f_flags & SYNC_FILE)
 			(void)fsync(f->f_file);
 		break;
_at__at_ -1792,7 +1814,8 _at__at_
 		break;

 	case '/':
-		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;
_at__at_ -1807,8 +1830,13 _at__at_
 			(void)strlcpy(f->f_un.f_fname, p + sizeof(_PATH_DEV) - 1,
 			    sizeof(f->f_un.f_fname));
 		} else {
-			(void)strlcpy(f->f_un.f_fname, p, sizeof(f->f_un.f_fname));
 			f->f_type = F_FILE;
+			/* 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);
+			}
+			(void)strlcpy(f->f_un.f_fname, p, sizeof(f->f_un.f_fname));
 		}
 		break;
Received on Tue May 25 2004 - 12:57:53 UTC

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