From 6758d2a3aae6cc88a6c04fe8d3d6b9a1a0d664de Mon Sep 17 00:00:00 2001 From: Yaakov Selkowitz Date: Mon, 9 May 2011 08:57:46 +0000 Subject: [PATCH] * times.cc (settimeofday): Add EFAULT handler. Set errno to EINVAL if tv.tv_nsec is invalid, and to EPERM if SetSystemTime fails. Return -1 in case of failure, all for compatibility with BSD and Linux. (clock_settime): New function. * cygwin.din (clock_settime): Export. * posix.sgml (std-susv4): Add clock_settime. Move clock_setres from here... (std-deprec): ... to here. (std-notes): Correct limitation of clock_setres to only CLOCK_REALTIME. Add limitation of clock_settime to only CLOCK_REALTIME. * include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump. --- winsup/cygwin/ChangeLog | 15 ++++++++++++ winsup/cygwin/cygwin.din | 1 + winsup/cygwin/include/cygwin/version.h | 3 ++- winsup/cygwin/posix.sgml | 9 ++++---- winsup/cygwin/times.cc | 32 ++++++++++++++++++++++++-- 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 19a709e82..67cacac2a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,18 @@ +2011-05-08 Yaakov Selkowitz + + * times.cc (settimeofday): Add EFAULT handler. + Set errno to EINVAL if tv.tv_nsec is invalid, and to EPERM if + SetSystemTime fails. Return -1 in case of failure, all for + compatibility with BSD and Linux. + (clock_settime): New function. + * cygwin.din (clock_settime): Export. + * posix.sgml (std-susv4): Add clock_settime. + Move clock_setres from here... + (std-deprec): ... to here. + (std-notes): Correct limitation of clock_setres to only CLOCK_REALTIME. + Add limitation of clock_settime to only CLOCK_REALTIME. + * include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump. + 2011-05-07 Corinna Vinschen * registry.cc (get_registry_hive_path): Change system_printf to diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index e918b08ad..2eafd2c8c 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -220,6 +220,7 @@ _clock = clock SIGFE clock_getres SIGFE clock_gettime SIGFE clock_setres SIGFE +clock_settime SIGFE clog NOSIGFE clogf NOSIGFE close SIGFE diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index ef92244ad..cf03080df 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -409,12 +409,13 @@ details. */ pthread_getattr_np. 242: Export psiginfo, psignal, sys_siglist. 243: Export sysinfo. + 244: Export clock_settime. */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 243 +#define CYGWIN_VERSION_API_MINOR 244 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/posix.sgml b/winsup/cygwin/posix.sgml index cdc6a9382..235ee2f94 100644 --- a/winsup/cygwin/posix.sgml +++ b/winsup/cygwin/posix.sgml @@ -92,7 +92,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008). clock clock_getres (see chapter "Implementation Notes") clock_gettime (see chapter "Implementation Notes") - clock_setres (see chapter "Implementation Notes") + clock_settime (see chapter "Implementation Notes") clog clogf close @@ -1214,6 +1214,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008). bcmp (POSIX.1-2001, SUSv3) bcopy (SUSv3) bzero (SUSv3) + clock_setres (QNX, VxWorks) (see chapter "Implementation Notes") cuserid (POSIX.1-1988, SUSv2) ecvt (SUSv3) endutent (XPG2) @@ -1439,9 +1440,9 @@ by keeping track of the current root and accomodating this in the file related function calls. A real chroot functionality is not supported by Windows however. -clock_getres, clock_gettime -and clock_setres only support CLOCK_REALTIME and -CLOCK_MONOTONIC for now. +clock_getres and clock_gettime +only support CLOCK_REALTIME and CLOCK_MONOTONIC for now. clock_setres +and clock_settime only support CLOCK_REALTIME. BSD file locks created via flock are not propagated to the parent process and sibling processes. The locks are diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index c28c0bab6..4e6697e76 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -109,7 +109,15 @@ settimeofday (const struct timeval *tv, const struct timezone *tz) struct tm *ptm; int res; - tz = tz; /* silence warning about unused variable */ + myfault efault; + if (efault.faulted (EFAULT)) + return -1; + + if (tv->tv_usec < 0 || tv->tv_usec >= 1000000) + { + set_errno (EINVAL); + return -1; + } ptm = gmtime (&tv->tv_sec); st.wYear = ptm->tm_year + 1900; @@ -121,11 +129,14 @@ settimeofday (const struct timeval *tv, const struct timezone *tz) st.wSecond = ptm->tm_sec; st.wMilliseconds = tv->tv_usec / 1000; - res = !SetSystemTime (&st); + res = -!SetSystemTime (&st); gtod.reset (); syscall_printf ("%d = settimeofday (%x, %x)", res, tv, tz); + if (res != 0) + set_errno (EPERM); + return res; } @@ -614,6 +625,23 @@ clock_gettime (clockid_t clk_id, struct timespec *tp) return 0; } +extern "C" int +clock_settime (clockid_t clk_id, const struct timespec *tp) +{ + struct timeval tv; + + if (clk_id != CLOCK_REALTIME) + { + set_errno (EINVAL); + return -1; + } + + tv.tv_sec = tp->tv_sec; + tv.tv_usec = tp->tv_nsec / 1000; + + return settimeofday (&tv, NULL); +} + static DWORD minperiod; // FIXME: Maintain period after a fork. LONGLONG -- 2.43.5