From: Dave Hart Date: Tue, 18 Jul 2023 19:17:19 +0000 (+0000) Subject: [Bug 3849] ntpd --wait-sync times out. X-Git-Tag: NTP_4_2_8P18_RC1~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b09c0ac5ec2e2d5335acce6269539237825374b;p=thirdparty%2Fntp.git [Bug 3849] ntpd --wait-sync times out. bk: 64b6e53fpCDap51TBH4R7ZCi2_dqcw --- diff --git a/ChangeLog b/ChangeLog index 244e0c6ee..439996b7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,14 @@ --- -* [Bug 3846] Use -Wno-format-truncation by default. +* [Bug 3849] ntpd --wait-sync times out. +* [Bug 3846] Use -Wno-format-truncation by default. * [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. * [Bug 3837] NULL pointer deref crash when ntpd deletes last interface. Reported by renmingshuai. Correct UNLINK_EXPR_SLIST() when the list is empty. -* [Bug 3835] NTP_HARD_*FLAGS not used by libevent tearoff. +* [Bug 3835] NTP_HARD_*FLAGS not used by libevent tearoff. * [Bug 3831] pollskewlist zeroed on runtime configuration. * [Bug 3830] configure libevent check intersperses output with answer. * [Bug 3828] BK should ignore a git repo in the same directory. diff --git a/libntp/msyslog.c b/libntp/msyslog.c index a1ba72792..b72d5c8dc 100644 --- a/libntp/msyslog.c +++ b/libntp/msyslog.c @@ -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); } diff --git a/ntpd/ntp_loopfilter.c b/ntpd/ntp_loopfilter.c index e76e4dce0..6378e0d7e 100644 --- a/ntpd/ntp_loopfilter.c +++ b/ntpd/ntp_loopfilter.c @@ -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; diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index f2c592384..e91cce0f1 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -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; diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index 868f7a9c8..a47386d0d 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -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 diff --git a/ntpsnmpd/Makefile.am b/ntpsnmpd/Makefile.am index 5729bb85c..71a53d996 100644 --- a/ntpsnmpd/Makefile.am +++ b/ntpsnmpd/Makefile.am @@ -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)