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

@@ -4,7 +4,6 @@ adjtime
lchmod
lchown
clone
clock_settime
extattr_*
fhopen
fhstat

View File

@@ -2,7 +2,7 @@
SRCS+= accept.c access.c bind.c brk.c sbrk.c m_closefrom.c getsid.c \
chdir.c chmod.c fchmod.c chown.c fchown.c chroot.c close.c \
clock_getres.c clock_gettime.c \
clock_getres.c clock_gettime.c clock_settime.c \
connect.c dup.c dup2.c execve.c fcntl.c flock.c fpathconf.c fork.c \
fstatfs.c fstatvfs.c fsync.c ftruncate.c getdents.c getegid.c getgid.c \
getgroups.c getitimer.c setitimer.c __getlogin.c getpeername.c \

View File

@@ -12,7 +12,7 @@ int clock_getres(clockid_t clock_id, struct timespec *res)
{
message m;
m.m2_l1 = (clockid_t) clock_id;
m.m2_i1 = (clockid_t) clock_id;
if (_syscall(PM_PROC_NR, CLOCK_GETRES, &m) < 0)
return -1;

View File

@@ -12,7 +12,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *res)
{
message m;
m.m2_l1 = (clockid_t) clock_id;
m.m2_i1 = (clockid_t) clock_id;
if (_syscall(PM_PROC_NR, CLOCK_GETTIME, &m) < 0)
return -1;

View File

@@ -0,0 +1,24 @@
#include <sys/cdefs.h>
#include <lib.h>
#include "namespace.h"
#include <time.h>
#ifdef __weak_alias
__weak_alias(clock_settime, __clock_settime50);
#endif
int clock_settime(clockid_t clock_id, const struct timespec *ts)
{
message m;
m.m2_i1 = (clockid_t) clock_id;
m.m2_l1 = (time_t) ts->tv_sec;
m.m2_l2 = (long) ts->tv_nsec;
if (_syscall(PM_PROC_NR, CLOCK_SETTIME, &m) < 0)
return -1;
return 0;
}

View File

@@ -7,11 +7,13 @@
int settimeofday(const struct timeval *tp, const void *tzp)
{
/* Use intermediate variable because stime param is not const */
time_t sec = tp->tv_sec;
struct timespec ts;
ts.tv_sec = tp->tv_sec;
ts.tv_nsec = tp->tv_usec * 1000;
/* Ignore time zones */
return stime(&sec);
return clock_settime(CLOCK_REALTIME, &ts);
}
#if defined(__minix) && defined(__weak_alias)

View File

@@ -59,6 +59,7 @@ SRCS+= \
sys_schedule.c \
sys_setalarm.c \
sys_setgrant.c \
sys_settime.c \
sys_sigreturn.c \
sys_sigsend.c \
sys_sprof.c \

20
lib/libsys/sys_settime.c Normal file
View File

@@ -0,0 +1,20 @@
#include "syslib.h"
#include <time.h>
int sys_settime(now, clk_id, sec, nsec)
int now;
clockid_t clk_id;
time_t sec;
long nsec;
{
message m;
int r;
m.T_SETTIME_NOW = now;
m.T_CLOCK_ID = clk_id;
m.T_TIME_SEC = sec;
m.T_TIME_NSEC = nsec;
r = _kernel_call(SYS_SETTIME, &m);
return(r);
}