[Git][NTPsec/ntpsec][master] 3 commits: Getting ready for pselect
Hal Murray
gitlab at mg.gitlab.com
Fri Sep 16 21:20:59 UTC 2016
Hal Murray pushed to branch master at NTPsec / ntpsec
Commits:
8e910741 by Hal Murray at 2016-09-16T13:50:17-07:00
Getting ready for pselect
- - - - -
ac31b7f5 by Hal Murray at 2016-09-16T13:50:17-07:00
Remove unused includes
- - - - -
966871ed by Hal Murray at 2016-09-16T13:50:17-07:00
More getting ready for pselect
- - - - -
7 changed files:
- include/ntpd.h
- ntpd/ntp_control.c
- ntpd/ntp_io.c
- ntpd/ntp_monitor.c
- ntpd/ntp_sandbox.c
- ntpd/ntp_timer.c
- ntpd/ntpd.c
Changes:
=====================================
include/ntpd.h
=====================================
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -428,6 +428,11 @@ extern u_long sys_limitrejected; /* rate exceeded */
extern u_long sys_kodsent; /* KoD sent */
extern u_long use_stattime; /* time since reset */
+/* Signalling */
+extern volatile bool sawALRM;
+extern volatile bool sawHUP;
+extern volatile bool sawQuit; /* SIGQUIT, SIGINT, SIGTERM */
+extern sigset_t blockMask;
/* ntp_restrict.c */
extern restrict_u * restrictlist4; /* IPv4 restriction list */
@@ -445,7 +450,6 @@ extern void send_via_ntp_signd(struct recvbuf *, int, keyid_t, int,
#endif
/* ntp_timer.c */
-extern volatile bool alarm_flag; /* alarm flag */
extern volatile u_long alarm_overflow;
extern u_long current_time; /* seconds since startup */
extern u_long timer_timereset;
@@ -475,7 +479,6 @@ extern const char *chrootdir; /* directory to chroot() to */
#ifdef HAVE_WORKING_FORK
extern int waitsync_fd_to_close; /* -w/--wait-sync */
#endif
-extern void finish (int sig);
/* refclock_conf.c */
#ifdef REFCLOCK
=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -7,7 +7,6 @@
#include <stdio.h>
#include <ctype.h>
-#include <signal.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -325,6 +325,13 @@ static input_handler_t input_handler;
static inline int read_refclock_packet (SOCKET, struct refclockio *, l_fp);
#endif
+/*
+ * Flags from signal handlers
+ */
+volatile bool sawALRM = false;
+volatile bool sawHUP = false;
+volatile bool sawQuit = false; /* SIGQUIT, SIGINT, SIGTERM */
+sigset_t blockMask;
void
maintain_activefds(
@@ -430,6 +437,16 @@ init_io(void)
/* update interface every 5 minutes as default */
interface_interval = 300;
+ sigemptyset(&blockMask);
+ sigaddset(&blockMask, SIGALRM);
+ sigaddset(&blockMask, MOREDEBUGSIG);
+ sigaddset(&blockMask, LESSDEBUGSIG);
+ sigaddset(&blockMask, SIGINT);
+ sigaddset(&blockMask, SIGQUIT);
+ sigaddset(&blockMask, SIGTERM);
+ sigaddset(&blockMask, SIGHUP);
+
+
#ifdef USE_WORK_PIPE
addremove_io_fd = &ntpd_addremove_io_fd;
#endif
@@ -3437,12 +3454,9 @@ io_handler(void)
int nfound;
/*
- * Use select() on all on all input fd's for unlimited
+ * Use select() 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.
+ * reception of input.
*/
rdfdes = activefds;
nfound = intercept_select(maxactivefd, &rdfdes);
@@ -3517,8 +3531,8 @@ input_handler(
fds = activefds;
tvzero.tv_sec = tvzero.tv_usec = 0;
- n = select(maxactivefd + 1, &fds, (fd_set *)0, (fd_set *)0,
- &tvzero);
+ /* Doesn't wait, just scans. */
+ n = select(maxactivefd + 1, &fds, NULL, NULL, &tvzero);
/*
* If there are no packets waiting just return
=====================================
ntpd/ntp_monitor.c
=====================================
--- a/ntpd/ntp_monitor.c
+++ b/ntpd/ntp_monitor.c
@@ -11,12 +11,6 @@
#include "ntp_random.h"
#include "ntp_intercept.h"
-#include <stdio.h>
-#include <signal.h>
-#ifdef HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-#endif
-
/*
* Record statistics based on source address, mode and version. The
* receive procedure calls us with the incoming rbufp before it does
=====================================
ntpd/ntp_sandbox.c
=====================================
--- a/ntpd/ntp_sandbox.c
+++ b/ntpd/ntp_sandbox.c
@@ -319,6 +319,7 @@ int scmp_sc[] = {
SCMP_SYS(munmap),
SCMP_SYS(open),
SCMP_SYS(poll),
+ SCMP_SYS(pselect6),
SCMP_SYS(read),
SCMP_SYS(recvfrom),
SCMP_SYS(recvmsg),
=====================================
ntpd/ntp_timer.c
=====================================
--- a/ntpd/ntp_timer.c
+++ b/ntpd/ntp_timer.c
@@ -36,11 +36,6 @@ static void check_leapsec(uint32_t, const time_t*, bool);
volatile int interface_interval; /* init_io() sets def. 300s */
/*
- * Alarm flag. The mainline code imports this.
- */
-volatile bool alarm_flag;
-
-/*
* The counters and timeouts
*/
static u_long interface_timer; /* interface update timer */
@@ -66,7 +61,7 @@ u_long current_time; /* seconds since startup */
u_long timer_timereset;
u_long timer_xmtcalls;
-static void alarming (int);
+static void catchALRM (int);
#ifdef HAVE_TIMER_CREATE
static timer_t timer_id;
@@ -141,7 +136,7 @@ init_timer(void)
/*
* Initialize...
*/
- alarm_flag = false;
+ sawALRM = false;
alarm_overflow = 0;
adjust_timer = 1;
stats_timer = SECSPERHR;
@@ -163,7 +158,7 @@ init_timer(void)
exit(1);
}
#endif
- signal_no_reset(SIGALRM, alarming);
+ signal_no_reset(SIGALRM, catchALRM);
itimer.it_interval.tv_sec =
itimer.it_value.tv_sec = (1 << EVENT_TIMEOUT);
itimer.it_interval.itv_frac = itimer.it_value.itv_frac = 0;
@@ -329,10 +324,10 @@ timer(void)
/*
- * alarming - tell the world we've been alarmed
+ * catchALRM - tell the world we've been alarmed
*/
static void
-alarming(
+catchALRM(
int sig
)
{
@@ -341,15 +336,15 @@ alarming(
# ifdef DEBUG
const char *msg = NULL;
# endif
- if (alarm_flag) {
+ if (sawALRM) {
alarm_overflow++;
# ifdef DEBUG
- msg = "alarming: overflow\n";
+ msg = "catchALRM: overflow\n";
# endif
} else {
- alarm_flag++;
+ sawALRM = true;
# ifdef DEBUG
- msg = "alarming: normal\n";
+ msg = "catchALRM: normal\n";
# endif
}
# ifdef DEBUG
=====================================
ntpd/ntpd.c
=====================================
--- a/ntpd/ntpd.c
+++ b/ntpd/ntpd.c
@@ -37,8 +37,8 @@ extern bool sandbox(const bool droproot,
const char *chrootdir,
bool want_dynamic_interface_tracking);
-static volatile bool signalled = false;
-static volatile int signo = 0;
+void catchQuit (int sig);
+static volatile int signo = 0;
/* In an ideal world, 'finish_safe()' would declared as noreturn... */
static void finish_safe (int);
@@ -96,16 +96,11 @@ char const *progname;
extern bool check_netinfo;
#endif
-bool was_alarmed;
-
#if defined(HAVE_WORKING_FORK)
static int wait_child_sync_if (int, long);
#endif
-#if defined(SIGHUP)
static void catchHUP (int);
-volatile int sawHUP = false;
-#endif
# ifdef DEBUG
static void moredebug (int);
@@ -687,11 +682,11 @@ ntpdmain(
/*
* Set up signals we pay attention to locally.
*/
- signal_no_reset(SIGINT, finish);
- signal_no_reset(SIGQUIT, finish);
- signal_no_reset(SIGTERM, finish);
+ signal_no_reset(SIGINT, catchQuit);
+ signal_no_reset(SIGQUIT, catchQuit);
+ signal_no_reset(SIGTERM, catchQuit);
signal_no_reset(SIGHUP, catchHUP);
- signal_no_reset(SIGBUS, finish); /* FIXME: It's broken, can't continue. */
+ signal_no_reset(SIGBUS, catchQuit); /* FIXME: It's broken, can't continue. */
# ifdef DEBUG
(void) signal_no_reset(MOREDEBUGSIG, moredebug);
@@ -915,35 +910,24 @@ static void mainloop(void)
init_timer();
- was_alarmed = false;
-
for (;;) {
- if (signalled)
+ if (sawQuit)
finish_safe(signo);
- if (alarm_flag) { /* alarmed? */
- was_alarmed = true;
- alarm_flag = false;
- }
- if (!was_alarmed && !has_full_recv_buffer()) {
+ if (!sawALRM && !has_full_recv_buffer()) {
/*
* Nothing to do. Wait for something.
*/
io_handler();
}
- if (alarm_flag) { /* alarmed? */
- was_alarmed = true;
- alarm_flag = false;
- }
-
- if (was_alarmed) {
+ if (sawALRM) {
/*
* Out here, signals are unblocked. Call timer routine
* to process expiry.
*/
timer();
- was_alarmed = false;
+ sawALRM = false;
}
# ifdef ENABLE_DEBUG_TIMING
@@ -957,15 +941,11 @@ static void mainloop(void)
# endif
rbuf = get_full_recv_buffer();
while (rbuf != NULL) {
- if (alarm_flag) {
- was_alarmed = true;
- alarm_flag = false;
- }
- if (was_alarmed) {
+ if (sawALRM) {
/* avoid timer starvation during lengthy I/O handling */
timer();
- was_alarmed = false;
+ sawALRM = false;
}
/*
@@ -1045,7 +1025,7 @@ static void mainloop(void)
/*
- * finish - exit gracefully
+ * finish_safe - exit gracefully
*/
static void
finish_safe(
@@ -1069,11 +1049,11 @@ finish_safe(
}
void
-finish(
+catchQuit(
int sig
)
{
- signalled = true;
+ sawQuit = true;
signo = sig;
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/c7779aea2cb3ef4d65828fd7254416df21bb7f1c...966871edb5e71f17a40ec8a687fc74d3f124384b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160916/2e5359ea/attachment.html>
More information about the vc
mailing list