summaryrefslogtreecommitdiff
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
parenta0a836b2129e62cee0267dc5c6cb32e0576ee311 (diff)
downloadgpsd-f4e3a55aa9445bcd76578cdf86ee3cdcfbbb0bc2.tar.gz
Added -n and -t termination options to ntpshmmon.
-rw-r--r--ntpshmmon.c25
-rw-r--r--ntpshmmon.xml23
2 files changed, 38 insertions, 10 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 */
diff --git a/ntpshmmon.xml b/ntpshmmon.xml
index 6a67fc7b..e343ab6e 100644
--- a/ntpshmmon.xml
+++ b/ntpshmmon.xml
@@ -23,7 +23,9 @@ BSD terms apply: see the file COPYING in the distribution root for details.
<cmdsynopsis>
<command>ntpshmmon</command>
<arg choice='opt'>-h </arg>
+ <arg choice='opt'>-n <replaceable>nsamples</replaceable></arg>
<arg choice='opt'>-s </arg>
+ <arg choice='opt'>-t <replaceable>seconds</replaceable></arg>
<arg choice='opt'>-v </arg>
<arg choice='opt'>-V </arg>
</cmdsynopsis>
@@ -38,9 +40,10 @@ ntpd, the Network Time Protocol daemon. It reads these in exactly the way an
ntpd instance does. It can be run concurrently with ntpd without
interfering with ntpd's normal operation.</para>
-<para>This program runs forever or until interrupted, generating
-sample reports to standard output. Each line consists of
-whitespace-separated textual fields.</para>
+<para>This program runs forever, or until a termination option is
+matched, or until interrupted, generating sample reports to standard
+output. Each line consists of whitespace-separated textual
+fields.</para>
<para>Here is an example of the beginning of a report file:
@@ -94,6 +97,13 @@ nanoseconds part of receiver time to be zero.</para>
</varlistentry>
<varlistentry>
+<term>-n</term>
+<listitem>
+<para>Set maximum number of samples to collect.</para>
+</listitem>
+</varlistentry>
+
+<varlistentry>
<term>-s</term>
<listitem>
<para>Remove all segments specified by the units argument. This
@@ -102,6 +112,13 @@ option will normally only be of interest to GPSD developers.</para>
</varlistentry>
<varlistentry>
+<term>-t</term>
+<listitem>
+<para>Set maximum time to collect samples in seconds.</para>
+</listitem>
+</varlistentry>
+
+<varlistentry>
<term>-h</term>
<listitem>
<para>Display program usage and exit.</para>