Add closelog() before closing most or all descriptors after fork().
bk: 4c45befdnxlz7nrOxh6S7WeIFTtaig
+* [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 <stenn@ntp.org>
* [Bug 1395] ease ntpdate elimination with ntpd -w/--wait-sync
* [Bug 1396] allow servers on ntpd command line like ntpdate
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);
#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()
*
/*
* 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);
child_resp_write_pipe = blocking_pipes[3];
kill_asyncio(0);
+ closelog();
if (syslog_file != NULL) {
fclose(syslog_file);
syslog_file = NULL;
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