]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
privops: switch from settimeofday() to clock_settime() master
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 29 Jan 2026 08:29:30 +0000 (09:29 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 29 Jan 2026 08:51:33 +0000 (09:51 +0100)
Following the removal of gettimeofday() calls, change PRV_SetTime() to
use clock_settime() instead of settimeofday(). Only CLOCK_REALTIME is
supported for now.

privops.c
privops.h
sys_generic.c
sys_linux.c
sys_macosx.c

index 3bc76d140c8d59df01a3e9e67d7237d485e49906..57dc5a3bd1b556d364776b4b61eea9d940d1d3d1 100644 (file)
--- a/privops.c
+++ b/privops.c
@@ -65,7 +65,7 @@ typedef struct {
 #endif
 
 typedef struct {
-  struct timeval tv;
+  struct timespec ts;
 } ReqSetTime;
 
 typedef struct {
@@ -225,13 +225,13 @@ do_adjust_timex(const ReqAdjustTimex *req, PrvResponse *res)
 
 /* ======================================================================= */
 
-/* HELPER - perform settimeofday() */
+/* HELPER - perform clock_settime() */
 
 #ifdef PRIVOPS_SETTIME
 static void
 do_set_time(const ReqSetTime *req, PrvResponse *res)
 {
-  res->rc = settimeofday(&req->tv, NULL);
+  res->rc = clock_settime(CLOCK_REALTIME, &req->ts);
   if (res->rc)
     res->res_errno = errno;
 }
@@ -508,25 +508,24 @@ PRV_AdjustTimex(struct timex *tmx)
 
 /* ======================================================================= */
 
-/* DAEMON - request settimeofday() */
+/* DAEMON - request clock_settime() */
 
 #ifdef PRIVOPS_SETTIME
 int
-PRV_SetTime(const struct timeval *tp, const struct timezone *tzp)
+PRV_SetTime(clockid_t clockid, const struct timespec *tp)
 {
   PrvRequest req;
   PrvResponse res;
 
-  /* only support setting the time */
-  assert(tp != NULL);
-  assert(tzp == NULL);
+  if (clockid != CLOCK_REALTIME)
+    return -1;
 
   if (!have_helper())
-    return settimeofday(tp, NULL);
+    return clock_settime(clockid, tp);
 
   memset(&req, 0, sizeof (req));
   req.op = OP_SETTIME;
-  req.data.set_time.tv = *tp;
+  req.data.set_time.ts = *tp;
 
   submit_request(&req, &res);
 
index 146580b7f9d0a0d335858dd3c4f88848adf10c39..4a6a3a494979fa5e8959b9dc28c30b134a64bf3b 100644 (file)
--- a/privops.h
+++ b/privops.h
@@ -41,9 +41,9 @@ int PRV_AdjustTimex(struct timex *txc);
 #endif
 
 #ifdef PRIVOPS_SETTIME
-int PRV_SetTime(const struct timeval *tp, const struct timezone *tzp);
+int PRV_SetTime(clockid_t clockid, const struct timespec *tp);
 #else
-#define PRV_SetTime settimeofday
+#define PRV_SetTime clock_settime
 #endif
 
 #ifdef PRIVOPS_BINDSOCKET
index 5c42df1dcb85c3ee5962951fe23f09ba1e2d8b32..95c9eede9699a58d6ed9368c2f803f90ac802a35 100644 (file)
@@ -349,15 +349,13 @@ static int
 apply_step_offset(double offset)
 {
   struct timespec old_time, new_time;
-  struct timeval new_time_tv;
   double err;
 
   LCL_ReadRawTime(&old_time);
   UTI_AddDoubleToTimespec(&old_time, -offset, &new_time);
-  UTI_TimespecToTimeval(&new_time, &new_time_tv);
 
-  if (PRV_SetTime(&new_time_tv, NULL) < 0) {
-    DEBUG_LOG("settimeofday() failed");
+  if (PRV_SetTime(CLOCK_REALTIME, &new_time) < 0) {
+    DEBUG_LOG("clock_settime() failed");
     return 0;
   }
 
index c64bce4584295986fc2c2581135969ba66b3234e..19ba00444096add8435324667a91ed125dfbf6e5 100644 (file)
@@ -427,7 +427,7 @@ SYS_Linux_EnableSystemCallFilter(int level, SYS_ProcessContext context)
     SCMP_SYS(clock_gettime64),
 #endif
     SCMP_SYS(gettimeofday),
-    SCMP_SYS(settimeofday),
+    SCMP_SYS(clock_settime),
     SCMP_SYS(time),
 
     /* Process */
index c668bd4b3646c14f403eaf7448e489a646eb9403..e233e98b7d3179dce46cd2166b83c7b1ba62adac 100644 (file)
@@ -245,8 +245,8 @@ apply_step_offset(double offset)
   UTI_AddDoubleToTimespec(&old_time, -offset, &new_time);
   UTI_TimespecToTimeval(&new_time, &new_time_tv);
 
-  if (PRV_SetTime(&new_time_tv, NULL) < 0) {
-    DEBUG_LOG("settimeofday() failed");
+  if (PRV_SetTime(CLOCK_REALTIME, &new_time_tv) < 0) {
+    DEBUG_LOG("clock_settime() failed");
     return 0;
   }