diff options
author | eugen <eugen@FreeBSD.org> | 2017-07-07 13:44:18 +0000 |
---|---|---|
committer | eugen <eugen@FreeBSD.org> | 2017-07-07 13:44:18 +0000 |
commit | 75c1f1fcfd5999c39763886df2db30a017f6a9e6 (patch) | |
tree | aeb1711d6487f627fc63f6eab7670af047f7d768 | |
parent | 131cd01d9e065cdf66abb12020ede37646ad25dd (diff) | |
download | FreeBSD-src-75c1f1fcfd5999c39763886df2db30a017f6a9e6.zip FreeBSD-src-75c1f1fcfd5999c39763886df2db30a017f6a9e6.tar.gz |
MFC r310888:
Retry to open an F_PIPE process when it dies unexpectedly.
PR: 215335
Reviewed by: ae
Approved by: az (mentor)
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 490bbc0..6e8fbc7 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -362,9 +362,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 @@ -1346,18 +1356,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); } @@ -1485,7 +1493,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; @@ -1587,10 +1594,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) { @@ -1823,12 +1828,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; @@ -2730,6 +2732,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, |