From: Dave Hart Date: Fri, 24 Feb 2012 08:07:56 +0000 (+0000) Subject: [Bug 2048] add the clock variable timecode to SHM refclock. X-Git-Tag: NTP_4_2_7P261~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab412e56926a87630c7f3fcb8d1b966cd0f0d268;p=thirdparty%2Fntp.git [Bug 2048] add the clock variable timecode to SHM refclock. Thanks to Michael Tatarinov. bk: 4f47455cenlYBRLGtMHbWa7h14tWzw --- diff --git a/ChangeLog b/ChangeLog index c88569f92..c2f667d15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* [Bug 2048] add the clock variable timecode to SHM refclock. * Fix the check-scm-rev invocation in several Makefile.am's. (4.2.7p259) 2012/02/22 Released by Harlan Stenn * [Bug 2148] ntpd 4.2.7p258 segfault with 0x0100000 bit in NMEA mode. diff --git a/ntpd/refclock_shm.c b/ntpd/refclock_shm.c index a0d66b51b..94cd4240e 100644 --- a/ntpd/refclock_shm.c +++ b/ntpd/refclock_shm.c @@ -325,7 +325,10 @@ int shm_peek( struct timeval tvr; struct timeval tvt; struct tm *t; + char timestr[20]; /* "%Y-%m-%dT%H:%M:%S" + 1 */ + int c; int ok=1; + tvr.tv_sec = 0; tvr.tv_usec = 0; tvt.tv_sec = 0; @@ -350,16 +353,24 @@ int shm_peek( default: msyslog (LOG_ERR, "SHM: bad mode found in shared memory: %d",shm->mode); } + + /* XXX NetBSD has incompatible tv_sec */ + t = gmtime((const time_t *)&tvt.tv_sec); + + /* add ntpq -c cv timecode in ISO 8601 format */ + strftime(timestr, sizeof(timestr), "%Y-%m-%dT%H:%M:%S", t); + c = snprintf(pp->a_lastcode, sizeof(pp->a_lastcode), + "%s.%06ldZ", timestr, (long)tvt.tv_usec); + pp->lencode = (c < sizeof(pp->a_lastcode)) + ? c + : 0; + shm->valid=0; if (ok) { - time_t help; /* XXX NetBSD has incompatible tv_sec */ - TVTOTS(&tvr,&pp->lastrec); pp->lastrec.l_ui += JAN_1970; /* pp->lasttime = current_time; */ pp->polls++; - help = tvt.tv_sec; - t = gmtime (&help); pp->day=t->tm_yday+1; pp->hour=t->tm_hour; pp->minute=t->tm_min; @@ -367,8 +378,7 @@ int shm_peek( pp->nsec=tvt.tv_usec * 1000; peer->precision=shm->precision; pp->leap=shm->leap; - } - else { + } else { refclock_report(peer, CEVNT_FAULT); msyslog (LOG_NOTICE, "SHM: access clash in shared memory"); up->clash++;