From 7aafb3b7cde05585fb0f14f3836fa731224551b7 Mon Sep 17 00:00:00 2001 From: eugen Date: Fri, 7 Jul 2017 11:54:45 +0000 Subject: [PATCH] MFC r310888: Retry to open an F_PIPE process when it dies unexpectedly. PR: 215335 Reviewed by: ae Approved by: az (mentor) git-svn-id: svn://svn.freebsd.org/base/stable/10@320772 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.sbin/syslogd/syslogd.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 3d5429f9e..d09ec0258 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -349,9 +349,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->f_un.f_pipe.f_pid = 0; + break; + } (void)close(f->f_file); f->f_file = -1; - f->f_type = F_UNUSED; } int @@ -1311,18 +1321,16 @@ fprintlog(struct filed *f, int flags, const char *msg) if (f->f_un.f_pipe.f_pid == 0) { if ((f->f_file = p_open(f->f_un.f_pipe.f_pname, &f->f_un.f_pipe.f_pid)) < 0) { - f->f_type = F_UNUSED; logerror(f->f_un.f_pipe.f_pname); break; } } if (writev(f->f_file, iov, IOV_SIZE) < 0) { int e = errno; + close_filed(f); - if (f->f_un.f_pipe.f_pid > 0) - deadq_enter(f->f_un.f_pipe.f_pid, - f->f_un.f_pipe.f_pname); - f->f_un.f_pipe.f_pid = 0; + deadq_enter(f->f_un.f_pipe.f_pid, + f->f_un.f_pipe.f_pname); errno = e; logerror(f->f_un.f_pipe.f_pname); } @@ -1427,7 +1435,6 @@ reapchild(int signo __unused) if (f->f_type == F_PIPE && f->f_un.f_pipe.f_pid == pid) { close_filed(f); - f->f_un.f_pipe.f_pid = 0; log_deadchild(pid, status, f->f_un.f_pipe.f_pname); break; @@ -1529,10 +1536,8 @@ die(int signo) /* flush any pending output */ if (f->f_prevcount) fprintlog(f, 0, (char *)NULL); - if (f->f_type == F_PIPE && f->f_un.f_pipe.f_pid > 0) { + if (f->f_type == F_PIPE && f->f_un.f_pipe.f_pid > 0) close_filed(f); - f->f_un.f_pipe.f_pid = 0; - } } Initialized = was_initialized; if (signo) { @@ -1599,12 +1604,9 @@ init(int signo) close_filed(f); break; case F_PIPE: - if (f->f_un.f_pipe.f_pid > 0) { - close_filed(f); - deadq_enter(f->f_un.f_pipe.f_pid, - f->f_un.f_pipe.f_pname); - } - f->f_un.f_pipe.f_pid = 0; + close_filed(f); + deadq_enter(f->f_un.f_pipe.f_pid, + f->f_un.f_pipe.f_pname); break; } next = f->f_next; @@ -2582,6 +2584,8 @@ deadq_enter(pid_t pid, const char *name) dq_t p; 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, -- 2.42.0