From: Dave Hart Date: Tue, 20 Jul 2010 15:21:33 +0000 (+0000) Subject: [Bug 1586] ntpd 4.2.7p40 doesn't write to syslog after fork on QNX. X-Git-Tag: NTP_4_2_7P41~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9610316d9d23fdf44a0c9b1b85b7d8df8f22168d;p=thirdparty%2Fntp.git [Bug 1586] ntpd 4.2.7p40 doesn't write to syslog after fork on QNX. Add closelog() before closing most or all descriptors after fork(). bk: 4c45befdnxlz7nrOxh6S7WeIFTtaig --- diff --git a/ChangeLog b/ChangeLog index f2885606c..c121a8661 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* [Bug 1586] ntpd 4.2.7p40 doesn't write to syslog after fork on QNX. (4.2.7p40) 2010/07/12 Released by Harlan Stenn * [Bug 1395] ease ntpdate elimination with ntpd -w/--wait-sync * [Bug 1396] allow servers on ntpd command line like ntpdate diff --git a/include/ntp_io.h b/include/ntp_io.h index ecee9ab27..08952cceb 100644 --- a/include/ntp_io.h +++ b/include/ntp_io.h @@ -87,6 +87,7 @@ extern void add_nic_rule(nic_rule_match match_type, nic_rule_action action); #ifndef HAVE_IO_COMPLETION_PORT extern void close_all_beyond(int); +extern void close_all_except(int); #endif #ifdef WORK_FORK extern void update_resp_pipe_fd(int, int); diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 76b9b3f15..c74827195 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -470,6 +470,25 @@ move_fd( #ifndef HAVE_IO_COMPLETION_PORT +/* + * close_all_except() + * + * Close all file descriptors except the given keep_fd. + */ +void +close_all_except( + int keep_fd + ) +{ + int fd; + + for (fd = 0; fd < keep_fd; fd++) + close(fd); + + close_all_beyond(keep_fd); +} + + /* * close_all_beyond() * diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index f104583c2..39cb3c4ed 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -808,15 +808,16 @@ ntpdmain( /* * child/daemon * close all open files excepting waitsync_fd_to_close. + * msyslog() unreliable until after init_logging(). */ + closelog(); if (syslog_file != NULL) { fclose(syslog_file); syslog_file = NULL; syslogit = 1; - /* no msyslog() until after init_logging() */ } - close_all_beyond(waitsync_fd_to_close); - open("/", 0); + close_all_except(waitsync_fd_to_close); + open("/dev/null", 0); dup2(0, 1); dup2(0, 2); diff --git a/ntpd/work_fork.c b/ntpd/work_fork.c index 86c471b21..2ec9d0d28 100644 --- a/ntpd/work_fork.c +++ b/ntpd/work_fork.c @@ -391,6 +391,7 @@ fork_blocking_child( child_resp_write_pipe = blocking_pipes[3]; kill_asyncio(0); + closelog(); if (syslog_file != NULL) { fclose(syslog_file); syslog_file = NULL; @@ -400,7 +401,7 @@ fork_blocking_child( for (fd = 3; fd < keep_fd; fd++) if (fd != child_req_read_pipe && fd != child_resp_write_pipe) - close(fd); + close(fd); close_all_beyond(keep_fd); /* * We get signals from refclock serial I/O on NetBSD in the