diff options
Diffstat (limited to 'support')
-rw-r--r-- | support/support_test_main.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/support/support_test_main.c b/support/support_test_main.c index 0be1bd3d78..1df6e4f976 100644 --- a/support/support_test_main.c +++ b/support/support_test_main.c @@ -91,16 +91,18 @@ static pid_t test_pid; static void (*cleanup_function) (void); static void -print_timestamp (const char *what, struct timeval tv) +print_timestamp (const char *what, struct timespec tv) { struct tm tm; + /* Casts of tv.tv_nsec below are necessary because the type of + tv_nsec is not literally long int on all supported platforms. */ if (gmtime_r (&tv.tv_sec, &tm) == NULL) - printf ("%s: %lld.%06d\n", - what, (long long int) tv.tv_sec, (int) tv.tv_usec); + printf ("%s: %lld.%09ld\n", + what, (long long int) tv.tv_sec, (long int) tv.tv_nsec); else - printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%06d\n", + printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%09ld\n", what, 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec); + tm.tm_hour, tm.tm_min, tm.tm_sec, (long int) tv.tv_nsec); } /* Timeout handler. We kill the child and exit with an error. */ @@ -113,8 +115,8 @@ signal_handler (int sig) /* Do this first to avoid further interference from the subprocess. */ - struct timeval now; - bool now_available = gettimeofday (&now, NULL) == 0; + struct timespec now; + clock_gettime (CLOCK_REALTIME, &now); struct stat64 st; bool st_available = fstat64 (STDOUT_FILENO, &st) == 0 && st.st_mtime != 0; @@ -168,12 +170,9 @@ signal_handler (int sig) printf ("Timed out: killed the child process but it exited %d\n", WEXITSTATUS (status)); - if (now_available) - print_timestamp ("Termination time", now); + print_timestamp ("Termination time", now); if (st_available) - print_timestamp ("Last write to standard output", - (struct timeval) { st.st_mtim.tv_sec, - st.st_mtim.tv_nsec / 1000 }); + print_timestamp ("Last write to standard output", st.st_mtim); /* Exit with an error. */ exit (1); |