]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3849] ntpd --wait-sync times out.
authorDave Hart <hart@ntp.org>
Tue, 18 Jul 2023 19:17:19 +0000 (19:17 +0000)
committerDave Hart <hart@ntp.org>
Tue, 18 Jul 2023 19:17:19 +0000 (19:17 +0000)
bk: 64b6e53fpCDap51TBH4R7ZCi2_dqcw

ChangeLog
libntp/msyslog.c
ntpd/ntp_loopfilter.c
ntpd/ntp_proto.c
ntpd/ntpd.c
ntpsnmpd/Makefile.am

index 244e0c6ee1600d6e47221000269f5e0dea64fe80..439996b7a95a2062d6f4f461b749fd48a3f7d19b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,13 +1,14 @@
 ---
 
-* [Bug 3846] Use -Wno-format-truncation by default.
+* [Bug 3849] ntpd --wait-sync times out. <hart@ntp.org>
+* [Bug 3846] Use -Wno-format-truncation by default. <hart@ntp.org>
 * [Bug 3841] 4.2.8p17 build break w/ gcc 12 -Wformat-security without -Wformat
              Need to remove --Wformat-security when removing -Wformat to
              silence numerous libopts warnings.  <hart@ntp.org>
 * [Bug 3837] NULL pointer deref crash when ntpd deletes last interface.
              Reported by renmingshuai.  Correct UNLINK_EXPR_SLIST() when the
              list is empty. <hart@ntp.org>
-* [Bug 3835] NTP_HARD_*FLAGS not used by libevent tearoff.
+* [Bug 3835] NTP_HARD_*FLAGS not used by libevent tearoff. <hart@ntp.org>
 * [Bug 3831] pollskewlist zeroed on runtime configuration. <hart@ntp.org>
 * [Bug 3830] configure libevent check intersperses output with answer. <stenn@>
 * [Bug 3828] BK should ignore a git repo in the same directory.
index a1ba72792595741c9c56a85d27e061f6530e18e6..b72d5c8dc3799386dc8305dcd26c6429564b601a 100644 (file)
@@ -348,15 +348,14 @@ msyslog(
        ...
        )
 {
-       char    buf[1024];
        va_list ap;
 
        va_start(ap, fmt);
-       mvsnprintf(buf, sizeof(buf), fmt, ap);
+       mvsyslog(level, fmt, ap);
        va_end(ap);
-       addto_syslog(level, buf);
 }
 
+
 void
 mvsyslog(
        int             level,
@@ -365,6 +364,7 @@ mvsyslog(
        )
 {
        char    buf[1024];
+
        mvsnprintf(buf, sizeof(buf), fmt, ap);
        addto_syslog(level, buf);
 }
index e76e4dce071106348410e6b664582dbdecafdbdd..6378e0d7e66982c286f61797e650dfa2ea41b8b8 100644 (file)
@@ -1027,6 +1027,22 @@ rstclock(
                    tc_counter));
        if (trans != state && trans != EVNT_FSET)
                report_event(trans, NULL, NULL);
+#ifdef HAVE_WORKING_FORK
+       if (trans != state && EVNT_SYNC == trans) {
+               /*
+                * If our parent process is waiting for the
+                * first clock sync, send them home satisfied.
+                */
+               if (daemon_pipe[1] != -1) {
+                       if (2 != write(daemon_pipe[1], "S\n", 2)) {
+                               msyslog(LOG_ERR, "daemon failed to notify parent ntpd (--wait-sync)");
+                       }
+                       close(daemon_pipe[1]);
+                       daemon_pipe[1] = -1;
+               }
+       }
+#endif /* HAVE_WORKING_FORK */
+
        state = trans;
        last_offset = clock_offset = offset;
        clock_epoch = current_time;
index f2c59238432ae6979a31933df972624d42116260..e91cce0f1a32bfa4120445c34f52a8493084a1b7 100644 (file)
@@ -2981,20 +2981,6 @@ clock_update(
                        if (crypto_flags)
                                crypto_update();
 #endif /* AUTOKEY */
-                       /*
-                        * If our parent process is waiting for the
-                        * first clock sync, send them home satisfied.
-                        */
-#ifdef HAVE_WORKING_FORK
-                       if (daemon_pipe[1] != -1) {
-                               if (2 != write(daemon_pipe[1], "S\n", 2)) {
-                                       msyslog(LOG_ERR, "daemon failed to notify parent ntpd (--wait-sync)");
-                               }
-                               close(daemon_pipe[1]);
-                               daemon_pipe[1] = -1;
-                               DPRINTF(1, ("notified parent --wait-sync is done\n"));
-                       }
-#endif /* HAVE_WORKING_FORK */
 
                }
 
@@ -3933,13 +3919,13 @@ clock_select(void)
                        sys_clockhop = 0;
                } else if ((x = fabs(typesystem->offset -
                    osys_peer->offset)) < sys_mindisp) {
-                       if (sys_clockhop == 0)
+                       if (0 == sys_clockhop)
                                sys_clockhop = sys_mindisp;
                        else
                                sys_clockhop *= .5;
                        DPRINTF(1, ("select: clockhop %d %.6f %.6f\n",
                                j, x, sys_clockhop));
-                       if (fabs(x) < sys_clockhop)
+                       if (x < sys_clockhop)
                                typesystem = osys_peer;
                        else
                                sys_clockhop = 0;
index 868f7a9c8068c74ad75e3ebb17fb24d6570268b9..a47386d0dfe9a23ece5f27c41117f0b2066b0a69 100644 (file)
@@ -608,7 +608,6 @@ detach_from_terminal(
                        pipe[1] = -1;
                        exit_code = wait_child_sync_if(
                                        pipe[0], wait_sync);
-                       DPRINTF(1, ("sync_if: rc=%d\n", exit_code));
                        if (exit_code <= 0) {
                                /* probe daemon exit code -- wait for
                                 * child process if we have an unexpected
@@ -616,7 +615,6 @@ detach_from_terminal(
                                 */
                                exit_code = wait_child_exit_if(
                                                cpid, (exit_code < 0));
-                               DPRINTF(1, ("exit_if: rc=%d\n", exit_code));
                        }
                }
                exit(exit_code);
@@ -1450,7 +1448,7 @@ int scmp_sc[] = {
 #if defined(SYS_WINNT)
        ntservice_isup();
 #elif defined(HAVE_WORKING_FORK)
-       if (daemon_pipe[1] != -1) {
+       if (daemon_pipe[1] != -1 && 0 == wait_sync) {
                if (2 != write(daemon_pipe[1], "R\n", 2)) {
                        msyslog(LOG_ERR, "daemon failed to notify parent ntpd after init");
                }
@@ -1697,29 +1695,31 @@ wait_child_sync_if(
                }
                rc = read(pipe_read_fd, &ch, 1);
                if (rc == 0) {
-                       DPRINTF(2, ("daemon control: got EOF\n"));
+                       /* DPRINTF is useless here as -d/-D disable forking */
+                       fprintf(stderr, "daemon control: got EOF\n");
                        return -1;      /* unexpected EOF, check daemon */
                } else if (rc == 1) {
-                       DPRINTF(2, ("daemon control: got '%c'\n",
-                                   (ch >= ' ' ? ch : '.')));
-                       if (ch == 'R' && !wait_sync)
-                               return 0;
-                       if (ch == 'S' && wait_sync)
+                       if (   ('S' == ch && wait_sync > 0)
+                           || ('R' == ch && 0 == wait_sync)) {
                                return 0;
+                       }
                } else {
-                       DPRINTF(2, ("daemon control: read 1 char failed: %s\n",
-                                   strerror(errno)));
+                       mfprintf(stderr, "%s: daemon control: read 1 char failed: %m\n",
+                                progname);
+                       msyslog(LOG_ERR, "daemon control: read 1 char failed: %m");
                        return EX_IOERR;
                }
        } while (wait_rem > 0);
 
-       if (wait_sync) {
+       if (wait_sync > 0) {
                fprintf(stderr, "%s: -w/--wait-sync %ld timed out.\n",
                        progname, wait_sync);
+               msyslog(LOG_ERR, "-w/--wait-sync %ld timed out.", wait_sync);
                return EX_PROTOCOL;
        } else {
                fprintf(stderr, "%s: daemon startup monitoring timed out.\n",
                        progname);
+               msyslog(LOG_ERR, "daemon startup monitoring timed out.");
                return 0;
        }
 }
@@ -1735,7 +1735,6 @@ wait_child_exit_if(
        int     rc = 0;
        int     wstatus;
        if (cpid == waitpid(cpid, &wstatus, (blocking ? 0 : WNOHANG))) {
-               DPRINTF(1, ("child (pid=%d) dead now\n", cpid));
                if (WIFEXITED(wstatus)) {
                        rc = WEXITSTATUS(wstatus);
                        msyslog(LOG_ERR, "daemon child exited with code %d",
@@ -1748,8 +1747,6 @@ wait_child_exit_if(
                        rc = EX_SOFTWARE;
                        msyslog(LOG_ERR, "daemon child died with unknown cause");
                }
-       } else {
-               DPRINTF(1, ("child (pid=%d) still alive\n", cpid));
        }
        return rc;
 #    else
index 5729bb85cd460f824c06cb5fa1f739f06f0129e9..71a53d99680333cdf6fe330ea7ace94c88d8f138 100644 (file)
@@ -9,9 +9,9 @@ ntpsnmpd_SOURCES= netsnmp_daemonize.c ntpsnmpd.c ntpSnmpSubagentObject.c \
                ntpsnmpd-opts.c ntpsnmpd-opts.h ntpSnmpSubagentObject.h \
                ntp_snmp.h
 # HMS: we probably want a version.o file here, too.
-LDADD  = ../ntpq/libntpq.a ../libntp/libntp.a
-LDADD += $(SNMP_LIBS) $(LDADD_LIBNTP) $(LIBM)
-LDADD += $(PTHREAD_LIBS) $(LDADD_NTP) $(LIBOPTS_LDADD)
+ntpsnmpd_LDADD  = ../ntpq/libntpq.a ../libntp/libntp.a
+ntpsnmpd_LDADD += $(LDADD_LIBNTP) $(LIBM) $(PTHREAD_LIBS)
+ntpsnmpd_LDADD += $(LDADD_NTP) $(LIBOPTS_LDADD) $(SNMP_LIBS)
 
 AM_CFLAGS  = $(SNMP_CFLAGS) $(CFLAGS_NTP)
 AM_CFLAGS += $(NTP_HARD_CFLAGS)