aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2021-01-12 09:30:34 +0100
committerWerner Koch <wk@gnupg.org>2021-01-12 09:31:20 +0100
commit93d5d7ea2a8b110b3ad88be25f2f67d706361e44 (patch)
tree40bb8e13cb372a0e1cad329c1f1e08b8250109c5
parentecaabc2d8f878217c6e5c5eab266405571e0f9da (diff)
downloadgnupg-93d5d7ea2a8b110b3ad88be25f2f67d706361e44.tar.gz
tools: Add option --clock to watchgnupg
* tools/watchgnupg.c (print_fd_and_time) [ENABLE_LOG_CLOCK]: Use clock_gettime. (print_version): New option --clock.
-rw-r--r--tools/watchgnupg.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/tools/watchgnupg.c b/tools/watchgnupg.c
index 8cdc257f8..7a7544bb5 100644
--- a/tools/watchgnupg.c
+++ b/tools/watchgnupg.c
@@ -143,8 +143,29 @@ static void
print_fd_and_time (int fd)
{
struct tm *tp;
- time_t atime = time (NULL);
+ time_t atime;
+#ifdef ENABLE_LOG_CLOCK
+ if (time_only == 2)
+ {
+ struct timespec tv;
+ unsigned long long now;
+
+ if (clock_gettime (CLOCK_REALTIME, &tv))
+ now = 0; /* Error getting clock. */
+ else
+ {
+ now = tv.tv_sec * 1000000000ull;
+ now += tv.tv_nsec;
+ now /= 1000000;
+ }
+
+ printf ("%3d - %6llu ", fd, now);
+ return;
+ }
+#endif /* ENABLE_LOG_CLOCK */
+
+ atime = time (NULL);
tp = localtime (&atime);
if (time_only)
printf ("%3d - %02d:%02d:%02d ",
@@ -359,6 +380,7 @@ print_version (int with_help)
" --force delete an already existing socket file\n"
" --verbose enable extra informational output\n"
" --time-only print only the time; not a full timestamp\n"
+ " --clock print only a millisecond timestamp\n"
" --homedir DIR use DIR for gpgconf's --homedir option\n"
" --version print version of the program and exit\n"
" --help display this help and exit\n"
@@ -411,6 +433,11 @@ main (int argc, char **argv)
time_only = 1;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--clock"))
+ {
+ time_only = 2;
+ argc--; argv++;
+ }
else if (!strcmp (*argv, "--force"))
{
force = 1;