summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-02-25 05:32:57 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-02-25 05:32:57 -0500
commit352b62f793892590fb61cfe8395c2e09b44fe3eb (patch)
treeea2eb18edb834d87420891d8f20f4ba328618045
parent4492295a686082f9832bcc38b612cc37612d37d9 (diff)
downloadgpsd-352b62f793892590fb61cfe8395c2e09b44fe3eb.tar.gz
In tpmon, timestamp reports properly and deal with bad status.
-rw-r--r--ntpmon.c25
-rw-r--r--ntpshm.h1
-rw-r--r--ntpshmread.c3
3 files changed, 24 insertions, 5 deletions
diff --git a/ntpmon.c b/ntpmon.c
index 2af07e54..1587189a 100644
--- a/ntpmon.c
+++ b/ntpmon.c
@@ -16,6 +16,7 @@
#define NTPSEGMENTS 256 /* NTPx for x any byte */
static struct shmTime *segments[NTPSEGMENTS + 1];
+static int tick[NTPSEGMENTS + 1];
static int shm_startup(int count)
/* open a specified number of segments */
@@ -85,11 +86,24 @@ int main(int argc, char **argv)
switch(status)
{
case OK:
- printf("%s %ld %ld %ld %ld %d\n",
- shm_name(i),
- shm_stat.tvr.tv_sec, shm_stat.tvr.tv_nsec,
- shm_stat.tvt.tv_sec, shm_stat.tvt.tv_nsec,
- shm_stat.leap);
+ if (shm_stat.now >= tick[i]) {
+ printf("%s %ld %ld %ld %ld %ld %d\n",
+ shm_name(i), shm_stat.now,
+ shm_stat.tvr.tv_sec, shm_stat.tvr.tv_nsec,
+ shm_stat.tvt.tv_sec, shm_stat.tvt.tv_nsec,
+ shm_stat.leap);
+ tick[i] = shm_stat.now;
+ }
+ break;
+ case NOT_READY:
+ /* do nothing, data not ready, wait another cycle */
+ break;
+ case BAD_MODE:
+ fprintf(stderr, "ntpmon: unknown mode on segment %s\n",
+ shm_name(i));
+ break;
+ case CLASH:
+ /* do nothing, data is corrupt, wait another cycle */
break;
default:
fprintf(stderr, "ntpmon: unknown status %d on segment %s\n",
@@ -97,6 +111,7 @@ int main(int argc, char **argv)
break;
}
}
+
sleep(1);
}
diff --git a/ntpshm.h b/ntpshm.h
index 5a29369f..086c94b8 100644
--- a/ntpshm.h
+++ b/ntpshm.h
@@ -7,6 +7,7 @@
#define GPSD_NTPSHM_H
#include <stdbool.h>
+#include <time.h>
#include <sys/time.h>
#include <sys/ipc.h>
#include <sys/shm.h>
diff --git a/ntpshmread.c b/ntpshmread.c
index e7362e8c..6ee03552 100644
--- a/ntpshmread.c
+++ b/ntpshmread.c
@@ -65,6 +65,9 @@ enum segstat_t shm_query(struct shmTime *shm_in, struct shm_stat_t *shm_stat)
unsigned int cns_new, rns_new;
int cnt;
+ shm_stat->now = 0;
+ time(&shm_stat->now);
+
if (shm == NULL)
return NO_SEGMENT;
if (!shm->valid) {