libc: add clock_settime() system call.

This also adds the sys_settime() kernel call which allows for the adjusting
of the clock named realtime in the kernel. The existing sys_stime()
function is still needed for a separate job (setting the boottime). The
boottime is set in the readclock driver. The sys_settime() interface is
meant to be flexible and will support both clock_settime() and adjtime()
when adjtime() is implemented later.

settimeofday() was adjusted to use the clock_settime() interface.

One side note discovered during testing: uptime(1) (part of the last(1)),
uses wtmp to determine boottime (not Minix's times(2)). This leads `uptime`
to report odd results when you set the time to a time prior to boottime.
This isn't a new bug introduced by my changes. It's been there for a while.
This commit is contained in:
Thomas Cort
2013-03-30 16:59:21 +00:00
committed by Ben Gras
parent 18ad4c0799
commit 516fec97d9
24 changed files with 179 additions and 11 deletions

View File

@@ -20,6 +20,7 @@ int main(void);
void quit(void);
static void test_clock_getres();
static void test_clock_gettime();
static void test_clock_settime();
static void show_timespec(char *msg, struct timespec *ts);
static void test_clock_getres()
@@ -63,6 +64,37 @@ static void test_clock_gettime()
if (clock_gettime(-1, &ts) == 0) e(31);
}
static void test_clock_settime(void)
{
struct timespec ts;
struct timespec ts2;
/* shouldn't be able to set MONOTONIC */
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) e(50);
if (clock_settime(CLOCK_MONOTONIC, &ts) == 0) e(51);
if (errno != EINVAL) e(52); /* reponse should be EINVAL */
/* set the time of REALTIME to that of MONOTONIC */
if (clock_settime(CLOCK_REALTIME, &ts) == -1) e(53);
ts.tv_sec += 600; /* time travel 10 minutes into the future */
if (clock_gettime(CLOCK_REALTIME, &ts2) == -1) e(54);
if (clock_settime(CLOCK_REALTIME, &ts) == -1) e(55);
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) e(56);
/* get the value we set, if it's not about 10 minutes ahead, it failed */
if (ts.tv_sec - ts2.tv_sec < 500 ||
ts.tv_sec - ts2.tv_sec > 700) e(57);
/* back to current time - don't leave the system time 10 ahead */
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) e(58);
ts.tv_sec -= 600;
if (clock_settime(CLOCK_REALTIME, &ts) == -1) e(59);
/* Test with an invalid clock */
if (clock_settime(-1, &ts) == 0) e(60);
}
static void show_timespec(char *msg, struct timespec *ts)
{
#if DEBUG == 1
@@ -80,6 +112,7 @@ int main()
test_clock_getres();
test_clock_gettime();
test_clock_settime();
/* get test end time */
if (clock_gettime(CLOCK_MONOTONIC, &endtime) == -1) e(2);