[Git][NTPsec/ntpsec][master] 4 commits: In documentation, reference POSIX clock_settime()...
Eric S. Raymond
gitlab at mg.gitlab.com
Wed Sep 28 17:07:45 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
567c2f20 by Eric S. Raymond at 2016-09-28T11:46:52-04:00
In documentation, reference POSIX clock_settime()...
...rather than the nonportable settimeofday() call.
- - - - -
194d9422 by Eric S. Raymond at 2016-09-28T12:00:28-04:00
Remove historical relic.
- - - - -
c9eb9dc6 by Eric S. Raymond at 2016-09-28T12:28:01-04:00
Fix build error on Non-PosIX, non-OS-X systems.
- - - - -
3bda5470 by Eric S. Raymond at 2016-09-28T13:04:20-04:00
Eliminate use of nonstandard settimeofday() call.
This leaves POSIX clock_settime() as the only primitive used for stepping.
Won't work on systems with poor POSIX conformance. Good thing we're not
targeting systems with poor POSIX conformance.
- - - - -
7 changed files:
- docs/includes/ntpdig-body.txt
- docs/leap.txt
- libntp/machines.c
- ntpd/ntp_config.c
- ntpd/ntp_control.c
- ntpdig/main.c
- wafhelpers/configure.py
Changes:
=====================================
docs/includes/ntpdig-body.txt
=====================================
--- a/docs/includes/ntpdig-body.txt
+++ b/docs/includes/ntpdig-body.txt
@@ -157,7 +157,7 @@ _logfile_.
+
If the time adjustment is less than _steplimit_ milliseconds, slew the
amount using _adjtime(2)_. Otherwise, step the correction using
-_clock_settime()_ or _settimeofday(2)_. The default value is 0, which
+_clock_settime()_ or local equivalent. The default value is 0, which
means all adjustments will be stepped. This is a feature, as different
situations demand different values.
=====================================
docs/leap.txt
=====================================
--- a/docs/leap.txt
+++ b/docs/leap.txt
@@ -51,7 +51,7 @@ end of the day. The kernel automatically inserts one second exactly at
the time of the leap, after which the leap bits are turned off. If the
kernel support is not availed or disabled, the leap is implemented as a
crude hack by setting the clock back one second using the Unix
-+settimeofday()+ system call, which effectively repeats the last second.
++clock_settime()+ system call, which effectively repeats the last second.
Note however that in any case setting the time backwards by one second
does not actually set the system clock backwards, but effectively stalls
the clock for one second. These points are expanded in the white paper
=====================================
libntp/machines.c
=====================================
--- a/libntp/machines.c
+++ b/libntp/machines.c
@@ -53,6 +53,7 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp)
mach_port_deallocate(mach_task_self(), cclock);
tp->tv_sec = mts.tv_sec;
tp->tv_nsec = mts.tv_nsec;
+#else
#error POSIX clock_gettime(2) is required
#endif
return 0;
@@ -80,27 +81,11 @@ int ntp_gettime(struct ntptimeval *ntv)
}
#endif /* !HAVE_NTP_GETTIME */
-#define SET_TOD_UNDETERMINED 0
-#define SET_TOD_CLOCK_SETTIME 1
-#define SET_TOD_SETTIMEOFDAY 2
-#define SET_TOD_STIME 3
-
-const char * const set_tod_used[] = {
- "undetermined",
- "clock_settime",
- "settimeofday",
- "stime"
-};
-
-pset_tod_using set_tod_using = NULL;
-
-
int
ntp_set_tod(
struct timespec *tvs
)
{
- static int tod;
int rc;
int saved_errno;
@@ -109,47 +94,15 @@ ntp_set_tod(
saved_errno = 0;
#ifdef HAVE_CLOCK_SETTIME
- if (rc && (SET_TOD_CLOCK_SETTIME == tod || !tod)) {
- errno = 0;
- rc = clock_settime(CLOCK_REALTIME, tvs);
- saved_errno = errno;
- TRACE(1, ("ntp_set_tod: clock_settime: %d %m\n", rc));
- if (!tod && !rc)
- tod = SET_TOD_CLOCK_SETTIME;
-
- }
+ errno = 0;
+ rc = clock_settime(CLOCK_REALTIME, tvs);
+ saved_errno = errno;
+ TRACE(1, ("ntp_set_tod: clock_settime: %d %m\n", rc));
+#else
+#error POSIX clock_gettime(2) is required
#endif /* HAVE_CLOCK_SETTIME */
-#ifdef HAVE_SETTIMEOFDAY
- if (rc && (SET_TOD_SETTIMEOFDAY == tod || !tod)) {
- struct timeval adjtv;
-
- /*
- * Some broken systems don't reset adjtime() when the
- * clock is stepped.
- */
- adjtv.tv_sec = adjtv.tv_usec = 0;
- adjtime(&adjtv, NULL);
- errno = 0;
-
- adjtv.tv_sec = tvs->tv_sec;
- adjtv.tv_usec = (tvs->tv_nsec + 500) / 1000;
- rc = settimeofday(&adjtv, NULL);
- saved_errno = errno;
- TRACE(1, ("ntp_set_tod: settimeofday: %d %m\n", rc));
- if (!tod && !rc)
- tod = SET_TOD_SETTIMEOFDAY;
- }
-#endif /* HAVE_SETTIMEOFDAY */
errno = saved_errno; /* for %m below */
- TRACE(1, ("ntp_set_tod: Final result: %s: %d %m\n",
- set_tod_used[tod], rc));
- /*
- * Say how we're setting the time of day
- */
- if (!rc && NULL != set_tod_using) {
- (*set_tod_using)(set_tod_used[tod]);
- set_tod_using = NULL;
- }
+ TRACE(1, ("ntp_set_tod: Final result: clock_settime: %d %m\n", rc));
if (rc)
errno = saved_errno;
=====================================
ntpd/ntp_config.c
=====================================
--- a/ntpd/ntp_config.c
+++ b/ntpd/ntp_config.c
@@ -317,7 +317,6 @@ enum gnn_type {
t_MSK /* Network Mask */
};
-static void ntpd_set_tod_using(const char *);
static uint32_t get_pfxmatch(const char **, struct masks *);
static uint32_t get_match(const char *, struct masks *);
static uint32_t get_logmask(const char *);
@@ -3400,12 +3399,6 @@ void readconfig(const char *config_file)
"daemon_version=\"ntpd %s\"", Version);
set_sys_var(line, strlen(line) + 1, RO);
- /*
- * Set up for the first time step to install a variable showing
- * which syscall is being used to step.
- */
- set_tod_using = &ntpd_set_tod_using;
-
init_syntax_tree(&cfgt);
if (
!lex_init_stack(config_file, "r")
@@ -3476,18 +3469,6 @@ save_and_apply_config_tree(bool input_from_file)
}
-static void
-ntpd_set_tod_using(
- const char *which
- )
-{
- char line[128];
-
- snprintf(line, sizeof(line), "settimeofday=\"%s\"", which);
- set_sys_var(line, strlen(line) + 1, RO);
-}
-
-
/* FUNCTIONS COPIED FROM THE OLDER ntp_config.c
* --------------------------------------------
*/
=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -658,6 +658,14 @@ init_control(void)
/* these may be unused with the old trap facility gone */
ctl_sys_last_event = EVNT_UNSPEC;
ctl_sys_num_events = 0;
+
+#ifdef ENABLE_CLASSIC_MODE
+ /* a relic from when there were multiple nonstandard ways to set time */
+#define PRESET "settimeofday=\"clock_settime\""
+ set_sys_var(PRESET, sizeof(PRESET), RO);
+#undef PRESET
+#endif /* ENABLE_CLASSIC_MODE */
+
}
=====================================
ntpdig/main.c
=====================================
--- a/ntpdig/main.c
+++ b/ntpdig/main.c
@@ -177,7 +177,7 @@ static void ntpdig_usage(void)
P(" - prohibits the option 'logfile'\n");
P(" -l Str logfile Log to specified logfile\n");
P(" - prohibits the option 'syslog'\n");
- P(" -s no settod Set (step) the time with settimeofday()\n");
+ P(" -s no settod Set (step) the time with clock_settime()\n");
P(" - prohibits the option 'adjtime'\n");
P(" -j no adjtime Set (slew) the time with adjtime()\n");
P(" - prohibits the option 'settod'\n");
=====================================
wafhelpers/configure.py
=====================================
--- a/wafhelpers/configure.py
+++ b/wafhelpers/configure.py
@@ -299,7 +299,6 @@ def cmd_configure(ctx, config):
('ntp_gettime', ["sys/time.h", "sys/timex.h"]), # BSD
('res_init', ["resolv.h"]),
('sched_setscheduler', ["sched.h"]),
- ('settimeofday', ["sys/time.h"], "RT"), # BSD
('strlcpy', ["string.h"]),
('strlcat', ["string.h"]),
('timer_create', ["time.h"])
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/b14ba537ba719c40389801197b2e4c01aaaf2334...3bda54704e2613bc52bf53c44b6e3a491b66ddb4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160928/81a01f61/attachment.html>
More information about the vc
mailing list