From owner-freebsd-current@FreeBSD.ORG Tue May 25 14:57:53 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9CFFC16A4CE for ; Tue, 25 May 2004 14:57:53 -0700 (PDT) Received: from mail.imp.ch (ns1.imp.ch [157.161.1.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id F2A4A43D1D for ; Tue, 25 May 2004 14:57:52 -0700 (PDT) (envelope-from mb@imp.ch) Received: from cvs.imp.ch (cvs.imp.ch [157.161.4.9]) by mail.imp.ch (8.12.9p2/8.12.3) with ESMTP id i4PLvjbK081092 for ; Tue, 25 May 2004 23:57:45 +0200 (CEST) (envelope-from Martin.Blapp@imp.ch) Date: Tue, 25 May 2004 23:57:45 +0200 (CEST) From: Martin Blapp To: current@freebsd.org In-Reply-To: <20040525233637.C7820@cvs.imp.ch> Message-ID: <20040525235603.A7820@cvs.imp.ch> References: <20040525233637.C7820@cvs.imp.ch> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: syslogd(8): timed out waiting for child X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 May 2004 21:57:53 -0000 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 @@ -881,7 +881,7 @@ /* 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, @@ -1135,12 +1135,34 @@ 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; @@ -1792,7 +1814,8 @@ 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; @@ -1807,8 +1830,13 @@ (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;