From owner-svn-src-all@freebsd.org Sat Dec 31 03:07:49 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 76982C96AE0; Sat, 31 Dec 2016 03:07:49 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 271C015FE; Sat, 31 Dec 2016 03:07:49 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBV37mKf046768; Sat, 31 Dec 2016 03:07:48 GMT (envelope-from hrs@FreeBSD.org) Received: (from hrs@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBV37miu046767; Sat, 31 Dec 2016 03:07:48 GMT (envelope-from hrs@FreeBSD.org) Message-Id: <201612310307.uBV37miu046767@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hrs set sender to hrs@FreeBSD.org using -f From: Hiroki Sato Date: Sat, 31 Dec 2016 03:07:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310888 - head/usr.sbin/syslogd X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Dec 2016 03:07:49 -0000 Author: hrs Date: Sat Dec 31 03:07:48 2016 New Revision: 310888 URL: https://svnweb.freebsd.org/changeset/base/310888 Log: Retry to open an F_PIPE process when it dies unexpectedly. Reported by: Eugene Grosbein PR: 215335 Modified: head/usr.sbin/syslogd/syslogd.c Modified: head/usr.sbin/syslogd/syslogd.c ============================================================================== --- head/usr.sbin/syslogd/syslogd.c Sat Dec 31 02:23:15 2016 (r310887) +++ head/usr.sbin/syslogd/syslogd.c Sat Dec 31 03:07:48 2016 (r310888) @@ -368,9 +368,19 @@ close_filed(struct filed *f) if (f == NULL || f->f_file == -1) return; + switch (f->f_type) { + case F_FILE: + case F_TTY: + case F_CONSOLE: + case F_FORW: + f->f_type = F_UNUSED; + break; + case F_PIPE: + f->fu_pipe_pid = 0; + break; + } (void)close(f->f_file); f->f_file = -1; - f->f_type = F_UNUSED; } static int @@ -1378,18 +1388,15 @@ fprintlog(struct filed *f, int flags, co if (f->fu_pipe_pid == 0) { if ((f->f_file = p_open(f->fu_pipe_pname, &f->fu_pipe_pid)) < 0) { - f->f_type = F_UNUSED; logerror(f->fu_pipe_pname); break; } } if (writev(f->f_file, iov, nitems(iov)) < 0) { int e = errno; + + deadq_enter(f->fu_pipe_pid, f->fu_pipe_pname); close_filed(f); - if (f->fu_pipe_pid > 0) - deadq_enter(f->fu_pipe_pid, - f->fu_pipe_pname); - f->fu_pipe_pid = 0; errno = e; logerror(f->fu_pipe_pname); } @@ -1520,7 +1527,6 @@ reapchild(int signo __unused) if (f->f_type == F_PIPE && f->fu_pipe_pid == pid) { close_filed(f); - f->fu_pipe_pid = 0; log_deadchild(pid, status, f->fu_pipe_pname); break; } @@ -1619,10 +1625,8 @@ die(int signo) /* flush any pending output */ if (f->f_prevcount) fprintlog(f, 0, (char *)NULL); - if (f->f_type == F_PIPE && f->fu_pipe_pid > 0) { + if (f->f_type == F_PIPE && f->fu_pipe_pid > 0) close_filed(f); - f->fu_pipe_pid = 0; - } } Initialized = was_initialized; if (signo) { @@ -1851,12 +1855,8 @@ init(int signo) close_filed(f); break; case F_PIPE: - if (f->fu_pipe_pid > 0) { - close_filed(f); - deadq_enter(f->fu_pipe_pid, - f->fu_pipe_pname); - } - f->fu_pipe_pid = 0; + deadq_enter(f->fu_pipe_pid, f->fu_pipe_pname); + close_filed(f); break; } } @@ -2753,6 +2753,8 @@ deadq_enter(pid_t pid, const char *name) struct deadq_entry *dq; int status; + if (pid == 0) + return; /* * Be paranoid, if we can't signal the process, don't enter it * into the dead queue (perhaps it's already dead). If possible,