]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1586] ntpd 4.2.7p40 doesn't write to syslog after fork on QNX.
authorDave Hart <hart@ntp.org>
Tue, 20 Jul 2010 15:21:33 +0000 (15:21 +0000)
committerDave Hart <hart@ntp.org>
Tue, 20 Jul 2010 15:21:33 +0000 (15:21 +0000)
  Add closelog() before closing most or all descriptors after fork().

bk: 4c45befdnxlz7nrOxh6S7WeIFTtaig

ChangeLog
include/ntp_io.h
ntpd/ntp_io.c
ntpd/ntpd.c
ntpd/work_fork.c

index f2885606c6ee7207284d900860cd969ed7e110dc..c121a8661a1c5a2b8f29e41f015f83824489b5d2 100644 (file)
--- 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 <stenn@ntp.org>
 * [Bug 1395] ease ntpdate elimination with ntpd -w/--wait-sync
 * [Bug 1396] allow servers on ntpd command line like ntpdate
index ecee9ab27641c4982a43053cbbc91f19dd0bd74e..08952cceb599291cc636c5cc9ddf832c90efb966 100644 (file)
@@ -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);
index 76b9b3f1512c391a4a690c682649a4cdd59decfb..c74827195a237921ac08a5abeb0205f39e4abb5a 100644 (file)
@@ -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()
  *
index f104583c2fa582e5978e72268a1db1baedcdee53..39cb3c4ed891020cc65c56bf53fd6d37b764cc8a 100644 (file)
@@ -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);
 
index 86c471b21166cfdbbb3ed2ee515ba6445400ab7c..2ec9d0d28f992ab8266f40cd64ccf941ae46e49b 100644 (file)
@@ -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