]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2048] add the clock variable timecode to SHM refclock.
authorDave Hart <hart@ntp.org>
Fri, 24 Feb 2012 08:07:56 +0000 (08:07 +0000)
committerDave Hart <hart@ntp.org>
Fri, 24 Feb 2012 08:07:56 +0000 (08:07 +0000)
  Thanks to Michael Tatarinov.

bk: 4f47455cenlYBRLGtMHbWa7h14tWzw

ChangeLog
ntpd/refclock_shm.c

index c88569f92061a947e0520c7323042a648c4ecc21..c2f667d15c2fe0d727e56c8d6d6812a5a18de722 100644 (file)
--- 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 <stenn@ntp.org>
 * [Bug 2148] ntpd 4.2.7p258 segfault with 0x0100000 bit in NMEA mode.
index a0d66b51b29803f396629512aa0b240fd453b3a9..94cd4240e6cdd0c1574fcf6f3deafaaeb353b570 100644 (file)
@@ -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++;