diff options
Diffstat (limited to 'ntpshmread.c')
-rw-r--r-- | ntpshmread.c | 11 |
1 files changed, 9 insertions, 2 deletions
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(); /* |