[Git][NTPsec/ntpsec][master] 3 commits: Clean up write_drift, see Issue #409
Hal Murray
gitlab at mg.gitlab.com
Tue Dec 19 10:55:21 UTC 2017
Hal Murray pushed to branch master at NTPsec / ntpsec
Commits:
228b8222 by Hal Murray at 2017-12-18T15:39:07-08:00
Clean up write_drift, see Issue #409
- - - - -
56dd5d7b by Hal Murray at 2017-12-18T16:50:56-08:00
More uptime_t cleanup
- - - - -
e869f3ce by Hal Murray at 2017-12-18T17:18:24-08:00
Remove leftover volatiles
There used to be a signal handler for received packets.
It's not needed now that the kernel supports time stamps.
and one more uptime_t
- - - - -
4 changed files:
- include/ntpd.h
- ntpd/ntp_io.c
- ntpd/ntp_timer.c
- ntpd/ntp_util.c
Changes:
=====================================
include/ntpd.h
=====================================
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -176,9 +176,9 @@ extern void init_timer (void);
extern void reinit_timer (void);
extern void timer (void);
extern void timer_clr_stats (void);
-extern void timer_interfacetimeout (unsigned long);
-extern volatile int interface_interval;
-extern unsigned long orphwait; /* orphan wait time */
+extern void timer_interfacetimeout (uptime_t);
+extern int interface_interval;
+extern uptime_t orphwait; /* orphan wait time */
/* ntp_util.c */
extern void init_util (void);
@@ -238,9 +238,11 @@ extern uint64_t packets_received; /* total number of packets received */
extern uint64_t packets_sent; /* total number of packets sent */
extern uint64_t packets_notsent; /* total number of packets which couldn't be sent */
-extern volatile uint64_t handler_calls; /* number of calls to interrupt handler */
-extern volatile uint64_t handler_pkts; /* number of pkts received by handler */
-extern unsigned long io_timereset; /* time counters were reset */
+/* There used to be a signal handler for received packets. */
+/* It's not needed now that the kernel time stamps packets. */
+extern uint64_t handler_calls; /* number of calls to interrupt handler */
+extern uint64_t handler_pkts; /* number of pkts received by handler */
+extern uptime_t io_timereset; /* time counters were reset */
/* ntp_io.c */
extern bool disable_dynamic_updates;
@@ -346,7 +348,7 @@ extern uint64_t sys_limitrejected; /* rate exceeded */
extern uint64_t sys_kodsent; /* KoD sent */
extern uptime_t use_stattime; /* time since usestats reset */
-/* Signalling */
+/* Signalling: Set by signal handlers */
extern volatile bool sawALRM;
extern volatile bool sawHUP;
extern volatile bool sawDNS;
@@ -367,7 +369,7 @@ extern void send_via_ntp_signd(struct recvbuf *, int, keyid_t, int,
#endif
/* ntp_timer.c */
-extern volatile unsigned long alarm_overflow;
+extern unsigned long alarm_overflow;
extern uptime_t current_time; /* seconds since startup */
extern uptime_t timer_timereset;
extern unsigned long timer_xmtcalls;
=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -103,9 +103,9 @@ uint64_t packets_received; /* total # of packets received */
uint64_t packets_sent; /* total # of packets sent */
uint64_t packets_notsent; /* total # of packets which couldn't be sent */
-volatile uint64_t handler_calls; /* # of calls to interrupt handler */
-volatile uint64_t handler_pkts; /* number of pkts received by handler */
-unsigned long io_timereset; /* time counters were reset */
+uint64_t handler_calls; /* # of calls to interrupt handler */
+uint64_t handler_pkts; /* number of pkts received by handler */
+uptime_t io_timereset; /* time counters were reset */
/*
* Interface stuff
=====================================
ntpd/ntp_timer.c
=====================================
--- a/ntpd/ntp_timer.c
+++ b/ntpd/ntp_timer.c
@@ -34,25 +34,25 @@ static void check_leapsec(time_t, bool);
* Finally, we call the hourly procedure to do cleanup and print a
* message.
*/
-volatile int interface_interval; /* init_io() sets def. 300s */
+int interface_interval; /* init_io() sets def. 300s */
/*
* The counters and timeouts
*/
-static unsigned long interface_timer; /* interface update timer */
-static unsigned long adjust_timer; /* second timer */
-static unsigned long stats_timer; /* stats timer */
-static unsigned long leapf_timer; /* Report leapfile problems once/day */
-static unsigned long huffpuff_timer; /* huff-n'-puff timer */
-unsigned long leapsec; /* secs to next leap (proximity class) */
+static uptime_t interface_timer; /* interface update timer */
+static uptime_t adjust_timer; /* second timer */
+static uptime_t stats_timer; /* stats timer */
+static uptime_t leapf_timer; /* Report leapfile problems once/day */
+static uptime_t huffpuff_timer; /* huff-n'-puff timer */
+static unsigned long leapsec; /* secs to next leap (proximity class) */
unsigned int leap_smear_intv; /* Duration of smear. Enables smear mode. */
int leapdif; /* TAI difference step at next leap second*/
-unsigned long orphwait; /* orphan wait time */
+uptime_t orphwait; /* orphan wait time */
/*
* Statistics counter for the interested.
*/
-volatile unsigned long alarm_overflow;
+unsigned long alarm_overflow;
uptime_t current_time; /* seconds since startup */
@@ -275,8 +275,7 @@ timer(void)
* Interface update timer
*/
if (interface_interval && interface_timer <= current_time) {
- timer_interfacetimeout(current_time +
- (unsigned long)interface_interval);
+ timer_interfacetimeout(current_time + interface_interval);
DPRINT(2, ("timer: interface update\n"));
interface_update(NULL, NULL);
}
@@ -330,7 +329,7 @@ if (debug >= 4 && msg != NULL)
void
-timer_interfacetimeout(unsigned long timeout)
+timer_interfacetimeout(uptime_t timeout)
{
interface_timer = timeout;
}
=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -144,30 +144,39 @@ init_util(void)
/*
- * hourly_stats - print some interesting stats
+ * drift_write - write drift to file, speeds up restart
+ * drift can be off significantly if the system has cooled off
+ *
+ * This used to use mkstemp, but that uses mode 600, user ntp
+ * apparmor keeps root from reading that during initialization
+ * See Issue #409
+ * We don't need a unique filename. No other job is writing driftfile.
+ * There is no security problem with reading the drift file since
+ * you can get the data via ntp_adjtime(2) or ntptime(8).
*/
static void drift_write(char *driftfile, double drift)
{
- int fd;
- char tempfile[PATH_MAX], driftcopy[PATH_MAX];
- char driftval[32];
- strlcpy(driftcopy, driftfile, PATH_MAX);
- strlcpy(tempfile, dirname(driftcopy), sizeof(tempfile));
- strlcat(tempfile, "/driftXXXXXX", sizeof(tempfile));
- /* coverity[secure_temp] Warning is bogus on POSIX-compliant systems */
- if ((fd = mkstemp(tempfile)) < 0) {
+ FILE *new;
+ char tempfile[PATH_MAX];
+ strlcpy(tempfile, driftfile, sizeof(tempfile));
+ strlcat(tempfile, "-tmp", sizeof(tempfile));
+ if ((new = fopen(tempfile, "w")) == NULL) {
msyslog(LOG_ERR, "LOG: frequency file %s: %m", tempfile);
return;
}
- snprintf(driftval, sizeof(driftval), "%.6f\n", drift);
- IGNORE(write(fd, driftval, strlen(driftval)));
- (void)close(fd);
+ fprintf(new, "%.6f\n", drift);
+ (void)fclose(new);
/* atomic */
if (rename(tempfile, driftfile))
msyslog(LOG_WARNING,
"LOG: Unable to rename temp drift file %s to %s, %m",
tempfile, driftfile);
}
+
+
+/*
+ * write_stats - hourly: sysstats, usestats, and maybe drift
+ */
void
write_stats(void)
{
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/36b0d5c4f14bfcaeac548e70d72dcff5b927886d...e869f3ce9c2c6221ceeca1b0d8f7b5559f4dd9dc
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/36b0d5c4f14bfcaeac548e70d72dcff5b927886d...e869f3ce9c2c6221ceeca1b0d8f7b5559f4dd9dc
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20171219/a9d19819/attachment.html>
More information about the vc
mailing list