tools: Add option --clock to watchgnupg

* tools/watchgnupg.c (print_fd_and_time) [ENABLE_LOG_CLOCK]: Use
clock_gettime.
(print_version): New option --clock.
This commit is contained in:
Werner Koch 2021-01-12 09:30:34 +01:00
parent ecaabc2d8f
commit 93d5d7ea2a
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 28 additions and 1 deletions

View File

@ -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;