summaryrefslogtreecommitdiff
path: root/ntpshmmon.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-03-02 18:15:27 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-03-02 18:15:27 -0500
commitf4e3a55aa9445bcd76578cdf86ee3cdcfbbb0bc2 (patch)
tree9cc6ce97c4148d5e8a6c44c2ed1b2ec5f4a97678 /ntpshmmon.c
parenta0a836b2129e62cee0267dc5c6cb32e0576ee311 (diff)
downloadgpsd-f4e3a55aa9445bcd76578cdf86ee3cdcfbbb0bc2.tar.gz
Added -n and -t termination options to ntpshmmon.
Diffstat (limited to 'ntpshmmon.c')
-rw-r--r--ntpshmmon.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/ntpshmmon.c b/ntpshmmon.c
index 56d7a66f..3e99f17d 100644
--- a/ntpshmmon.c
+++ b/ntpshmmon.c
@@ -7,6 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
+#include <limits.h>
#ifndef S_SPLINT_S
#include <unistd.h>
#endif /* S_SPLINT_S */
@@ -36,10 +37,15 @@ int main(int argc, char **argv)
int option;
int i;
bool verbose = false;
+ int timeout = INT_MAX, nsamples = INT_MAX;
+ time_t starttime = time(NULL);
-#define USAGE "usage: ntpshmmon [-s] [-v] [-h] [-V]\n"
- while ((option = getopt(argc, argv, "hsvV")) != -1) {
+#define USAGE "usage: ntpshmmon [-s] [-n max] [-t timeout] [-v] [-h] [-V]\n"
+ while ((option = getopt(argc, argv, "hn:st:vV")) != -1) {
switch (option) {
+ case 'n':
+ nsamples = atoi(optarg);
+ break;
case 's':
if (units > 0) {
shm_shutdown();
@@ -48,7 +54,10 @@ int main(int argc, char **argv)
fprintf(stderr, "ntpshmmon: zero units declared.\n");
exit(EXIT_FAILURE);
}
- //0break;
+ //break;
+ case 't':
+ timeout = atoi(optarg);
+ break;
case 'v':
verbose = true;
break;
@@ -71,7 +80,7 @@ int main(int argc, char **argv)
}
(void)printf("ntpshmmon version 1\n");
- for (;;) {
+ do {
struct shm_stat_t shm_stat;
for (i = 0; i < NTPSEGMENTS; i++) {
@@ -91,6 +100,7 @@ int main(int argc, char **argv)
shm_stat.tvt.tv_sec, shm_stat.tvt.tv_nsec,
shm_stat.leap, shm_stat.precision);
tick[i] = shm_stat.tvc;
+ --nsamples;
}
/*@+type@*/
/*@+mustfreefresh +formattype@*/
@@ -113,7 +123,7 @@ int main(int argc, char **argv)
/*@-mustfreefresh@*/
fprintf(stderr, "ntpshmmon: unknown status %d on segment %s\n",
status, shm_name(i));
- /*@+mustfreefresh@*/
+ /*@+mustfreefresh@*/
break;
}
}
@@ -125,9 +135,10 @@ int main(int argc, char **argv)
* at interval < 1 sec shouldn't be a problem.
*/
(void)usleep(1000);
- }
+ } while
+ (nsamples != 0 && time(NULL) - starttime < timeout);
- //exit(EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
/* end */