From: Juergen Perlinger Date: Tue, 12 Aug 2014 18:29:54 +0000 (+0200) Subject: [Bug 2622] Synchronisation problem using SHM [...] X-Git-Tag: NTP_4_2_7P462~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6247226b0760013900fe869f277f3c0f2c255e6a;p=thirdparty%2Fntp.git [Bug 2622] Synchronisation problem using SHM [...] Add 'control' function to SHM driver-- fudge values not available during start. bk: 53ea5d229jZMfu7N4xTqNXKxrfa8Hw --- diff --git a/ChangeLog b/ChangeLog index 625f50226..50df8222c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +* [Bug 2622] Synchronisation problem using SHM [...] + Add 'control' function -- fudge values not available during start. * [Bug 2630] Limit the ntpq command buffer to 512 bytes. * FlexeLint cleanups. * Try bison-3.0.2 instead of bison-2.5. diff --git a/ntpd/refclock_shm.c b/ntpd/refclock_shm.c index 5c32b81aa..6540e6f37 100644 --- a/ntpd/refclock_shm.c +++ b/ntpd/refclock_shm.c @@ -59,6 +59,8 @@ static void shm_poll (int unit, struct peer *peer); static void shm_timer (int unit, struct peer *peer); static void shm_peek (int unit, struct peer *peer); static void shm_clockstats (int unit, struct peer *peer); +static void shm_control (int unit, const struct refclockstat * in_st, + struct refclockstat * out_st, struct peer *peer); /* * Transfer vector @@ -67,7 +69,7 @@ struct refclock refclock_shm = { shm_start, /* start up driver */ shm_shutdown, /* shut down driver */ shm_poll, /* transmit poll message */ - noentry, /* not used: control */ + shm_control, /* control settings */ noentry, /* not used: init */ noentry, /* not used: buginfo */ shm_timer, /* once per second */ @@ -214,23 +216,50 @@ shm_start( up->shm->valid = 0; up->shm->nsamples = NSAMPLES; pp->clockdesc = DESCRIPTION; - + /* items to be changed later in 'shm_control()': */ up->max_delay = 5; - if (pp->sloppyclockflag & CLK_FLAG1) - up->max_delta = 0; - else if (pp->fudgetime2 < 1. || pp->fudgetime2 > 86400.) - up->max_delta = 4*3600; - else - up->max_delta = (time_t)floor(pp->fudgetime2 + 0.5); - + up->max_delta = 4*3600; return 1; } else { free(up); + pp->unitptr = NULL; return 0; } } +/* + * shm_control - configure flag1/time2 params + * + * These are not yet available during 'shm_start', so we have to do any + * pre-computations we want to avoid during regular poll/timer callbacks + * in this callback. + */ +static void +shm_control( + int unit, + const struct refclockstat * in_st, + struct refclockstat * out_st, + struct peer * peer + ) +{ + struct refclockproc *pp; + struct shmunit *up; + + pp = peer->procptr; + up = pp->unitptr; + + if (NULL == up) + return; + if (pp->sloppyclockflag & CLK_FLAG1) + up->max_delta = 0; + else if (pp->fudgetime2 < 1. || pp->fudgetime2 > 86400.) + up->max_delta = 4*3600; + else + up->max_delta = (time_t)floor(pp->fudgetime2 + 0.5); +} + + /* * shm_shutdown - shut down the clock */