Index: usr.sbin/syslogd/syslogd.c =================================================================== --- usr.sbin/syslogd/syslogd.c +++ usr.sbin/syslogd/syslogd.c @@ -349,6 +349,22 @@ static void timedout(int); static void increase_rcvbuf(int); +static void +close_filed(struct filed *f) +{ + int saved_errno; + + if (f == NULL) + return; + + saved_errno = errno; + + close(f->f_file); + f->f_file = -1; + f->f_type = F_UNUSED; + errno = saved_errno; +} + int main(int argc, char *argv[]) { @@ -1024,7 +1040,7 @@ (void)strlcpy(f->f_lasttime, timestamp, sizeof(f->f_lasttime)); fprintlog(f, flags, msg); - (void)close(f->f_file); + close_filed(f); } (void)sigsetmask(omask); return; @@ -1313,8 +1329,7 @@ */ if (errno != ENOSPC) { int e = errno; - (void)close(f->f_file); - f->f_type = F_UNUSED; + close_filed(f); errno = e; logerror(f->f_un.f_fname); } @@ -1337,13 +1352,11 @@ } } if (writev(f->f_file, iov, IOV_SIZE) < 0) { - int e = errno; - (void)close(f->f_file); + 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; - errno = e; logerror(f->f_un.f_pipe.f_pname); } break; @@ -1446,7 +1459,7 @@ for (f = Files; f; f = f->f_next) if (f->f_type == F_PIPE && f->f_un.f_pipe.f_pid == pid) { - (void)close(f->f_file); + close_filed(f); f->f_un.f_pipe.f_pid = 0; log_deadchild(pid, status, f->f_un.f_pipe.f_pname); @@ -1550,7 +1563,7 @@ if (f->f_prevcount) fprintlog(f, 0, (char *)NULL); if (f->f_type == F_PIPE && f->f_un.f_pipe.f_pid > 0) { - (void)close(f->f_file); + close_filed(f); f->f_un.f_pipe.f_pid = 0; } } @@ -1634,11 +1647,11 @@ case F_FORW: case F_CONSOLE: case F_TTY: - (void)close(f->f_file); + close_filed(f); break; case F_PIPE: if (f->f_un.f_pipe.f_pid > 0) { - (void)close(f->f_file); + close_filed(f); deadq_enter(f->f_un.f_pipe.f_pid, f->f_un.f_pipe.f_pname); }