diff options
-rw-r--r-- | ntpshm.h | 4 | ||||
-rw-r--r-- | ntpshmmon.c | 2 | ||||
-rw-r--r-- | ntpshmread.c | 11 |
3 files changed, 13 insertions, 4 deletions
@@ -68,6 +68,8 @@ struct shm_stat_t { struct shmTime /*@null@*/ *shm_get(int, bool, bool); extern char *shm_name(const int); -enum segstat_t shm_query(/*@null@*/struct shmTime *, /*@out@*/struct shm_stat_t *); +enum segstat_t shm_query(/*@null@*/struct shmTime *, + /*@out@*/struct shm_stat_t *, + const bool); /* end */ diff --git a/ntpshmmon.c b/ntpshmmon.c index ab2e0538..f272ebd2 100644 --- a/ntpshmmon.c +++ b/ntpshmmon.c @@ -84,7 +84,7 @@ int main(int argc, char **argv) struct shm_stat_t shm_stat; for (i = 0; i < NTPSEGMENTS; i++) { - enum segstat_t status = shm_query(segments[i], &shm_stat); + enum segstat_t status = shm_query(segments[i], &shm_stat, false); if (verbose) fprintf(stderr, "unit %d status %d\n", i, status); switch(status) diff --git a/ntpshmread.c b/ntpshmread.c index 7a9206e3..33f9c8e5 100644 --- a/ntpshmread.c +++ b/ntpshmread.c @@ -58,7 +58,7 @@ char *shm_name(const int unit) } /*@+statictrans@*/ -enum segstat_t shm_query(/*@null@*/struct shmTime *shm_in, /*@out@*/struct shm_stat_t *shm_stat) +enum segstat_t shm_query(/*@null@*/struct shmTime *shm_in, /*@out@*/struct shm_stat_t *shm_stat, const bool consume) /* try to grab a sample from the specified SHM segment */ { volatile struct shmTime shmcopy, *shm = shm_in; @@ -91,7 +91,14 @@ enum segstat_t shm_query(/*@null@*/struct shmTime *shm_in, /*@out@*/struct shm_s */ memory_barrier(); memcpy((void *)&shmcopy, (void *)shm, sizeof(struct shmTime)); - shm->valid = 0; + + /* + * An update consumer such as ntp should zero the valid flag at this point. + * A program snooping the updates to collect statistics should not, lest + * it make the data unavailable for consumers. + */ + if (consume) + shm->valid = 0; memory_barrier(); /* |