From c51c7f5a8135d1a91ed50f49cf4b7b8c437e7a76 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 27 Jan 2026 16:33:01 +0100 Subject: [PATCH] client+test: switch from gettimeofday() to clock_gettime() Replace the remaining calls of gettimeofday(). --- client.c | 6 ++---- test/unit/test.c | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/client.c b/client.c index 1d6d3d5..a3c2ab3 100644 --- a/client.c +++ b/client.c @@ -1396,7 +1396,7 @@ submit_request(CMD_Request *request, CMD_Reply *reply) new_attempt = 1; do { - if (gettimeofday(&tv, NULL)) + if (clock_gettime(CLOCK_REALTIME, &ts_now) < 0) return 0; if (new_attempt) { @@ -1405,7 +1405,7 @@ submit_request(CMD_Request *request, CMD_Reply *reply) if (n_attempts > max_retries) return 0; - UTI_TimevalToTimespec(&tv, &ts_start); + ts_start = ts_now; UTI_GetRandomBytes(&request->sequence, sizeof (request->sequence)); request->attempt = htons(n_attempts); @@ -1428,8 +1428,6 @@ submit_request(CMD_Request *request, CMD_Reply *reply) return 0; } - UTI_TimevalToTimespec(&tv, &ts_now); - /* Check if the clock wasn't stepped back */ if (UTI_CompareTimespecs(&ts_now, &ts_start) < 0) ts_start = ts_now; diff --git a/test/unit/test.c b/test/unit/test.c index 1ebb11a..12c4bd8 100644 --- a/test/unit/test.c +++ b/test/unit/test.c @@ -45,8 +45,8 @@ main(int argc, char **argv) { LOG_Severity log_severity; char *test_name, *s; + struct timespec ts; int i, seed = 0; - struct timeval tv; test_name = argv[0]; s = strrchr(test_name, '.'); @@ -69,8 +69,8 @@ main(int argc, char **argv) } } - gettimeofday(&tv, NULL); - srandom(seed ? seed : tv.tv_sec ^ (tv.tv_usec << 10)); + clock_gettime(CLOCK_REALTIME, &ts); + srandom(seed ? seed : ts.tv_sec ^ (ts.tv_nsec << 10)); printf("Testing %-30s ", test_name); fflush(stdout);