]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
ntpd.c, ntp_io.c, ChangeLog, ntpd.h, iosignal.h:
authorFrank Kardel <kardel@ntp.org>
Wed, 31 Jul 2013 08:45:06 +0000 (08:45 +0000)
committerFrank Kardel <kardel@ntp.org>
Wed, 31 Jul 2013 08:45:06 +0000 (08:45 +0000)
  [Bug 2425] move part of input handler code from ntpd.c to ntp_io.c
  and fix select() only platforms calling input_handler directly.

bk: 51f8ce92JNHkegUOTK-84ImVOv_X0g

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

index 81e69509016f1c49d124c6548ab6e4a612a076bc..b3a695ac7c5910042fff8b0deaa97af2d54ce402 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+* [Bug 2425] move part of input handler code from ntpd.c to ntp_io.c
+* and fix select() only platforms calling input_handler directly.
 (4.2.7p377) 2013/07/28 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 2397] License/copyright cleanup.
 * [Bug 2439] Fix check of EscapeCommFunction() in ports/winnt/libntp/termios.c.
index fc37277108ca733ece701d7fc4d5fe4f94124929..406804e14c668f1c86f987f6ba97df1c4d62314e 100644 (file)
@@ -17,6 +17,9 @@
 # undef USE_SIGIO
 #endif
 
+/* type of input handler function - only shared between iosignal.c and ntp_io.c */
+typedef void (input_handler_t)(l_fp *);
+
 #if defined(HAVE_SIGNALED_IO)
 # if defined(USE_TTY_SIGPOLL) || defined(USE_UDP_SIGPOLL)
 #  define USE_SIGPOLL
@@ -37,9 +40,6 @@
 
 extern int             using_sigio;
 
-typedef void (input_handler_t)(l_fp *);
-extern input_handler_t input_handler;
-
 extern void            block_sigio     (void);
 extern void            unblock_sigio   (void);
 extern int             init_clock_sig  (struct refclockio *);
index 2066441a8c67c7d5b72ac53eab96aac9331551a7..90e4a7b449c08af16eb454ac5bab4aa0d5fa63a5 100644 (file)
@@ -117,7 +117,7 @@ extern      endpt * findbcastinter          (sockaddr_u *);
 extern void    enable_broadcast        (endpt *, sockaddr_u *);
 extern void    enable_multicast_if     (endpt *, sockaddr_u *);
 extern void    interface_update        (interface_receiver_t, void *);
-
+extern  void    io_handler              (void);
 extern void    init_io         (void);
 extern void    io_open_sockets (void);
 extern void    io_clr_stats    (void);
@@ -378,8 +378,6 @@ extern u_long       io_timereset;           /* time counters were reset */
 
 /* ntp_io.c */
 extern  int    disable_dynamic_updates;
-extern fd_set  activefds;
-extern int     maxactivefd;
 extern u_int   sys_ifnum;              /* next .ifnum to assign */
 extern endpt * any_interface;          /* IPv4 wildcard */
 extern endpt * any6_interface;         /* IPv6 wildcard */
index 83e64db66a2707dc6f521ad88641ebdcbdc84c55..5bbbeb758b3afb9f79e1f4b4b0f3f96731d9ebce 100644 (file)
@@ -177,16 +177,18 @@ static    struct refclockio *refio;
 
 /*
  * File descriptor masks etc. for call to select
- * Not needed for I/O Completion Ports
+ * Not needed for I/O Completion Ports or anything outside this file
  */
-fd_set activefds;
-int maxactivefd;
+static fd_set activefds;
+static int maxactivefd;
 
 /*
  * bit alternating value to detect verified interfaces during an update cycle
  */
 static  u_short                sys_interphase = 0;
 
+static input_handler_t input_handler;
+
 static endpt * new_interface(endpt *);
 static void    add_interface(endpt *);
 static int     update_interfaces(u_short, interface_receiver_t,
@@ -3464,7 +3466,7 @@ read_network_packet(
 /*
  * input_handler - receive packets asynchronously
  */
-void
+static void
 input_handler(
        l_fp *  cts
        )
@@ -4618,6 +4620,69 @@ init_async_notifications()
                "Listening on routing socket on fd #%d for interface updates",
                fd);
 }
+
+void
+io_handler(void)
+{
+#  ifndef HAVE_SIGNALED_IO
+       fd_set rdfdes;
+       int nfound;
+#  endif
+       /*
+        * Use select() on all on all input fd's for unlimited
+        * time.  select() will terminate on SIGALARM or on the
+        * reception of input.  Using select() means we can't do
+        * robust signal handling and we get a potential race
+        * between checking for alarms and doing the select().
+        * Mostly harmless, I think.
+        */
+       /*
+        * On VMS, I suspect that select() can't be interrupted
+        * by a "signal" either, so I take the easy way out and
+        * have select() time out after one second.
+        * System clock updates really aren't time-critical,
+        * and - lacking a hardware reference clock - I have
+        * yet to learn about anything else that is.
+        */
+#  ifndef HAVE_SIGNALED_IO
+       rdfdes = activefds;
+#   if !defined(VMS) && !defined(SYS_VXWORKS)
+       nfound = select(maxactivefd + 1, &rdfdes, NULL,
+                       NULL, NULL);
+#   else       /* VMS, VxWorks */
+       /* make select() wake up after one second */
+       {
+               struct timeval t1;
+
+               t1.tv_sec = 1;
+               t1.tv_usec = 0;
+               nfound = select(maxactivefd + 1,
+                               &rdfdes, NULL, NULL,
+                               &t1);
+       }
+#   endif      /* VMS, VxWorks */
+       if (nfound > 0) {
+               l_fp ts;
+
+               get_systime(&ts);
+
+               input_handler(&ts);
+       } else if (nfound == -1 && errno != EINTR) {
+               msyslog(LOG_ERR, "select() error: %m");
+       }
+#   ifdef DEBUG
+       else if (debug > 4) {
+               msyslog(LOG_DEBUG, "select(): nfound=%d, error: %m", nfound);
+       } else {
+               DPRINTF(1, ("select() returned %d: %m\n", nfound));
+       }
+#   endif /* DEBUG */
+#  else /* HAVE_SIGNALED_IO */
+       wait_for_signal();
+#  endif /* HAVE_SIGNALED_IO */
+}
+
+
 #else
 /* HAS_ROUTING_SOCKET not defined */
 static void
index 12ddb126aac2f2773461917671f211c4d1714022..4fcdf7421e3e4cc3d221460d3dc65a2210edc253 100644 (file)
@@ -948,22 +948,6 @@ getgroup:
        }       /* if (droproot) */
 # endif        /* HAVE_DROPROOT */
 
-       /*
-        * Use select() on all on all input fd's for unlimited
-        * time.  select() will terminate on SIGALARM or on the
-        * reception of input.  Using select() means we can't do
-        * robust signal handling and we get a potential race
-        * between checking for alarms and doing the select().
-        * Mostly harmless, I think.
-        */
-       /*
-        * On VMS, I suspect that select() can't be interrupted
-        * by a "signal" either, so I take the easy way out and
-        * have select() time out after one second.
-        * System clock updates really aren't time-critical,
-        * and - lacking a hardware reference clock - I have
-        * yet to learn about anything else that is.
-        */
 # ifdef HAVE_IO_COMPLETION_PORT
 
        for (;;) {
@@ -972,12 +956,8 @@ getgroup:
 
        BLOCK_IO_AND_ALARM();
        was_alarmed = FALSE;
-       for (;;) {
-#  ifndef HAVE_SIGNALED_IO
-               fd_set rdfdes;
-               int nfound;
-#  endif
 
+       for (;;) {
                if (alarm_flag) {       /* alarmed? */
                        was_alarmed = TRUE;
                        alarm_flag = FALSE;
@@ -987,47 +967,12 @@ getgroup:
                        /*
                         * Nothing to do.  Wait for something.
                         */
-#  ifndef HAVE_SIGNALED_IO
-                       rdfdes = activefds;
-#   if !defined(VMS) && !defined(SYS_VXWORKS)
-                       nfound = select(maxactivefd + 1, &rdfdes, NULL,
-                                       NULL, NULL);
-#   else       /* VMS, VxWorks */
-                       /* make select() wake up after one second */
-                       {
-                               struct timeval t1;
-
-                               t1.tv_sec = 1;
-                               t1.tv_usec = 0;
-                               nfound = select(maxactivefd + 1,
-                                               &rdfdes, NULL, NULL,
-                                               &t1);
-                       }
-#   endif      /* VMS, VxWorks */
-                       if (nfound > 0) {
-                               l_fp ts;
-
-                               get_systime(&ts);
+                       io_handler();
+               }
 
-                               input_handler(&ts);
-                       } else if (nfound == -1 && errno != EINTR) {
-                               msyslog(LOG_ERR, "select() error: %m");
-                       }
-#   ifdef DEBUG
-                         else if (debug > 4) {
-                               msyslog(LOG_DEBUG, "select(): nfound=%d, error: %m", nfound);
-                       } else {
-                               DPRINTF(1, ("select() returned %d: %m\n", nfound));
-                       }
-#   endif /* DEBUG */
-#  else /* HAVE_SIGNALED_IO */
-
-                       wait_for_signal();
-#  endif /* HAVE_SIGNALED_IO */
-                       if (alarm_flag) {       /* alarmed? */
-                               was_alarmed = TRUE;
-                               alarm_flag = FALSE;
-                       }
+               if (alarm_flag) {       /* alarmed? */
+                       was_alarmed = TRUE;
+                       alarm_flag = FALSE;
                }
 
                if (was_alarmed) {