]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2141] handle_sigio() calls get_systime(), which must be
authorDave Hart <hart@ntp.org>
Wed, 18 Apr 2012 11:46:26 +0000 (11:46 +0000)
committerDave Hart <hart@ntp.org>
Wed, 18 Apr 2012 11:46:26 +0000 (11:46 +0000)
  reentrant when SIGIO is used.  Sanity checks relative to the prior
  get_systime() are disabled in ntpd on systems with signaled I/O, but
  active in sntp and ntpdate.

bk: 4f8ea992tqrAYsnppvU0M7KdOzxwUw

ChangeLog
include/iosignal.h
libntp/iosignal.c
libntp/systime.c

index d1d7df308521d6a62820b8a306e525eec7ce4da3..5083b6e78d45503c07c8fca32bda10d852a2ec05 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+* [Bug 2141] handle_sigio() calls get_systime(), which must be
+  reentrant when SIGIO is used.  Sanity checks relative to the prior
+  get_systime() are disabled in ntpd on systems with signaled I/O, but
+  active in sntp and ntpdate.
 (4.2.7p272) 2012/04/14 Released by Harlan Stenn <stenn@ntp.org>
 * LCRYPTO is gone - replace with VER_SUFFIX.
 * Change the link order for ntpsntpd.
index 632ae7e023c95895ef61fcacdde70be8b89663a5..02d589923fb761660a967ee51c0ca8707b337c02 100644 (file)
 #  endif       /* SIGIO == SIGPOLL */
 # endif                /* USE_SIGIO && USE_SIGPOLL */
 
+#define        USING_SIGIO()   using_sigio
+
+extern int             using_sigio;
+
 extern void            block_sigio     (void);
 extern void            unblock_sigio   (void);
 extern int             init_clock_sig  (struct refclockio *);
@@ -46,6 +50,7 @@ RETSIGTYPE            sigio_handler   (int);
 #else  /* !HAVE_SIGNALED_IO follows */
 # define BLOCKIO()     do {} while (0)
 # define UNBLOCKIO()   do {} while (0)
+# define USING_SIGIO() FALSE
 #endif
 
 #endif /* IOSIGNAL_H */
index b10a161e9ee9370295e6e2ab0efb3df3c58c7a00..0176d8cbe7fe23826c7133cf9ec60a089d1c9b59 100644 (file)
@@ -311,6 +311,7 @@ sigio_handler(
 void
 set_signal(void)
 {
+       using_sigio = TRUE;
 #  ifdef USE_SIGIO
        (void) signal_no_reset(SIGIO, sigio_handler);
 # endif
@@ -481,6 +482,7 @@ block_sigio(void)
 void
 set_signal(void)
 {
+       using_sigio = TRUE;
        (void) signal_no_reset(SIGIO, sigio_handler);
 }
 
index b98bb7258d908d7d38ba55683c8c3ab6a1590014..5264b9e127c0c3482e064fcda20d943eb30e7c7e 100644 (file)
@@ -10,6 +10,7 @@
 #include "ntp_syslog.h"
 #include "ntp_stdlib.h"
 #include "ntp_random.h"
+#include "iosignal.h"
 #include "timevalops.h"
 #include "timespecops.h"
 #include "ntp_calendar.h"
@@ -84,6 +85,11 @@ static int systime_init_done;
 #else
 # define DONE_SYSTIME_INIT()   do {} while (FALSE)
 #endif
+
+#ifdef HAVE_SIGNALED_IO
+int using_sigio;
+#endif
+
 #ifdef SYS_WINNT
 CRITICAL_SECTION get_systime_cs;
 #endif
@@ -176,20 +182,29 @@ get_systime(
         * fuzzed result is strictly later than the prior.  Limit the
         * necessary fiction to 1 second.
         */
-       ts_min = add_tspec_ns(ts_prev, sys_fuzz_nsec);
-       if (cmp_tspec(ts, ts_min) < 0) {
-               ts_lam = sub_tspec(ts_min, ts);
-               if (ts_lam.tv_sec > 0 && !lamport_violated) {
-                       msyslog(LOG_ERR,
-                               "get_systime Lamport advance exceeds one second (%.9f)",
-                               ts_lam.tv_sec + 1e-9 * ts_lam.tv_nsec);
-                       exit(1);
+       if (!USING_SIGIO()) {
+               ts_min = add_tspec_ns(ts_prev, sys_fuzz_nsec);
+               if (cmp_tspec(ts, ts_min) < 0) {
+                       ts_lam = sub_tspec(ts_min, ts);
+                       if (ts_lam.tv_sec > 0 && !lamport_violated) {
+                               msyslog(LOG_ERR,
+                                       "get_systime Lamport advance exceeds one second (%.9f)",
+                                       ts_lam.tv_sec +
+                                           1e-9 * ts_lam.tv_nsec);
+                               exit(1);
+                       }
+                       if (!lamport_violated)
+                               ts = ts_min;
                }
-               if (!lamport_violated)
-                       ts = ts_min;
+               ts_prev_log = ts_prev;
+               ts_prev = ts;
+       } else {
+               /*
+                * Quiet "ts_prev_log.tv_sec may be used uninitialized"
+                * warning from x86 gcc 4.5.2.
+                */
+               ZERO(ts_prev_log);
        }
-       ts_prev_log = ts_prev;
-       ts_prev = ts;
 
        /* convert from timespec to l_fp fixed-point */
        result = tspec_stamp_to_lfp(ts);
@@ -206,27 +221,32 @@ get_systime(
         * sys_residual's effect for now) once sys_fuzz has been
         * determined.
         */
-       if (!L_ISZERO(&lfp_prev) && !lamport_violated) {
-               if (!L_ISGTU(&result, &lfp_prev) && sys_fuzz > 0.) {
-                       msyslog(LOG_ERR, "ts_min %s ts_prev %s ts %s",
-                               tspectoa(ts_min), tspectoa(ts_prev_log),
-                               tspectoa(ts));
-                       msyslog(LOG_ERR, "sys_fuzz %ld nsec, this fuzz %.9f, prior %.9f",
-                               sys_fuzz_nsec, dfuzz, dfuzz_prev);
-                       lfpdelta = lfp_prev;
-                       L_SUB(&lfpdelta, &result);
-                       LFPTOD(&lfpdelta, ddelta);
-                       msyslog(LOG_ERR,
-                               "get_systime prev result 0x%x.%08x is %.9f later than 0x%x.%08x",
-                               lfp_prev.l_ui, lfp_prev.l_uf,
-                               ddelta, result.l_ui, result.l_uf);
+       if (!USING_SIGIO()) {
+               if (!L_ISZERO(&lfp_prev) && !lamport_violated) {
+                       if (!L_ISGTU(&result, &lfp_prev) &&
+                           sys_fuzz > 0.) {
+                               msyslog(LOG_ERR, "ts_prev %s ts_min %s",
+                                       tspectoa(ts_prev_log),
+                                       tspectoa(ts_min));
+                               msyslog(LOG_ERR, "ts %s", tspectoa(ts));
+                               msyslog(LOG_ERR, "sys_fuzz %ld nsec, prior fuzz %.9f",
+                                       sys_fuzz_nsec, dfuzz_prev);
+                               msyslog(LOG_ERR, "this fuzz %.9f",
+                                       dfuzz);
+                               lfpdelta = lfp_prev;
+                               L_SUB(&lfpdelta, &result);
+                               LFPTOD(&lfpdelta, ddelta);
+                               msyslog(LOG_ERR,
+                                       "prev get_systime 0x%x.%08x is %.9f later than 0x%x.%08x",
+                                       lfp_prev.l_ui, lfp_prev.l_uf,
+                                       ddelta, result.l_ui, result.l_uf);
+                       }
                }
+               lfp_prev = result;
+               dfuzz_prev = dfuzz;
+               if (lamport_violated) 
+                       lamport_violated = FALSE;
        }
-       lfp_prev = result;
-       dfuzz_prev = dfuzz;
-       if (lamport_violated) 
-               lamport_violated = FALSE;
-
        LEAVE_GET_SYSTIME_CRITSEC();
        *now = result;
 }