client+test: switch from gettimeofday() to clock_gettime()

Replace the remaining calls of gettimeofday().
This commit is contained in:
Miroslav Lichvar
2026-01-27 16:33:01 +01:00
parent b213719c3f
commit c51c7f5a81
2 changed files with 5 additions and 7 deletions

View File

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

View File

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