mirror of
https://gitlab.com/chrony/chrony.git
synced 2026-03-11 00:59:38 -04:00
privops: switch from settimeofday() to clock_settime()
Following the removal of gettimeofday() calls, change PRV_SetTime() to use clock_settime() instead of settimeofday(). Only CLOCK_REALTIME is supported for now.
This commit is contained in:
19
privops.c
19
privops.c
@@ -65,7 +65,7 @@ typedef struct {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct timeval tv;
|
struct timespec ts;
|
||||||
} ReqSetTime;
|
} ReqSetTime;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -225,13 +225,13 @@ do_adjust_timex(const ReqAdjustTimex *req, PrvResponse *res)
|
|||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
||||||
/* HELPER - perform settimeofday() */
|
/* HELPER - perform clock_settime() */
|
||||||
|
|
||||||
#ifdef PRIVOPS_SETTIME
|
#ifdef PRIVOPS_SETTIME
|
||||||
static void
|
static void
|
||||||
do_set_time(const ReqSetTime *req, PrvResponse *res)
|
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)
|
if (res->rc)
|
||||||
res->res_errno = errno;
|
res->res_errno = errno;
|
||||||
}
|
}
|
||||||
@@ -508,25 +508,24 @@ PRV_AdjustTimex(struct timex *tmx)
|
|||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
||||||
/* DAEMON - request settimeofday() */
|
/* DAEMON - request clock_settime() */
|
||||||
|
|
||||||
#ifdef PRIVOPS_SETTIME
|
#ifdef PRIVOPS_SETTIME
|
||||||
int
|
int
|
||||||
PRV_SetTime(const struct timeval *tp, const struct timezone *tzp)
|
PRV_SetTime(clockid_t clockid, const struct timespec *tp)
|
||||||
{
|
{
|
||||||
PrvRequest req;
|
PrvRequest req;
|
||||||
PrvResponse res;
|
PrvResponse res;
|
||||||
|
|
||||||
/* only support setting the time */
|
if (clockid != CLOCK_REALTIME)
|
||||||
assert(tp != NULL);
|
return -1;
|
||||||
assert(tzp == NULL);
|
|
||||||
|
|
||||||
if (!have_helper())
|
if (!have_helper())
|
||||||
return settimeofday(tp, NULL);
|
return clock_settime(clockid, tp);
|
||||||
|
|
||||||
memset(&req, 0, sizeof (req));
|
memset(&req, 0, sizeof (req));
|
||||||
req.op = OP_SETTIME;
|
req.op = OP_SETTIME;
|
||||||
req.data.set_time.tv = *tp;
|
req.data.set_time.ts = *tp;
|
||||||
|
|
||||||
submit_request(&req, &res);
|
submit_request(&req, &res);
|
||||||
|
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ int PRV_AdjustTimex(struct timex *txc);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PRIVOPS_SETTIME
|
#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
|
#else
|
||||||
#define PRV_SetTime settimeofday
|
#define PRV_SetTime clock_settime
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PRIVOPS_BINDSOCKET
|
#ifdef PRIVOPS_BINDSOCKET
|
||||||
|
|||||||
@@ -349,15 +349,13 @@ static int
|
|||||||
apply_step_offset(double offset)
|
apply_step_offset(double offset)
|
||||||
{
|
{
|
||||||
struct timespec old_time, new_time;
|
struct timespec old_time, new_time;
|
||||||
struct timeval new_time_tv;
|
|
||||||
double err;
|
double err;
|
||||||
|
|
||||||
LCL_ReadRawTime(&old_time);
|
LCL_ReadRawTime(&old_time);
|
||||||
UTI_AddDoubleToTimespec(&old_time, -offset, &new_time);
|
UTI_AddDoubleToTimespec(&old_time, -offset, &new_time);
|
||||||
UTI_TimespecToTimeval(&new_time, &new_time_tv);
|
|
||||||
|
|
||||||
if (PRV_SetTime(&new_time_tv, NULL) < 0) {
|
if (PRV_SetTime(CLOCK_REALTIME, &new_time) < 0) {
|
||||||
DEBUG_LOG("settimeofday() failed");
|
DEBUG_LOG("clock_settime() failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ SYS_Linux_EnableSystemCallFilter(int level, SYS_ProcessContext context)
|
|||||||
SCMP_SYS(clock_gettime64),
|
SCMP_SYS(clock_gettime64),
|
||||||
#endif
|
#endif
|
||||||
SCMP_SYS(gettimeofday),
|
SCMP_SYS(gettimeofday),
|
||||||
SCMP_SYS(settimeofday),
|
SCMP_SYS(clock_settime),
|
||||||
SCMP_SYS(time),
|
SCMP_SYS(time),
|
||||||
|
|
||||||
/* Process */
|
/* Process */
|
||||||
|
|||||||
@@ -245,8 +245,8 @@ apply_step_offset(double offset)
|
|||||||
UTI_AddDoubleToTimespec(&old_time, -offset, &new_time);
|
UTI_AddDoubleToTimespec(&old_time, -offset, &new_time);
|
||||||
UTI_TimespecToTimeval(&new_time, &new_time_tv);
|
UTI_TimespecToTimeval(&new_time, &new_time_tv);
|
||||||
|
|
||||||
if (PRV_SetTime(&new_time_tv, NULL) < 0) {
|
if (PRV_SetTime(CLOCK_REALTIME, &new_time_tv) < 0) {
|
||||||
DEBUG_LOG("settimeofday() failed");
|
DEBUG_LOG("clock_settime() failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user