about summary refs log tree commit diff
path: root/sysdeps/unix/settimeofday.c
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2019-07-27 19:26:23 -0400
committerZack Weinberg <zackw@panix.com>2019-07-27 20:14:35 -0400
commit3f649995a112b91754b49b7fff389385ce55f54f (patch)
tree3999bdce24cbfc67c223f3610ba6dd92d59d0994 /sysdeps/unix/settimeofday.c
parent50ce3eae5ba304650459d4441d7d246a7cefc26f (diff)
downloadglibc-3f649995a112b91754b49b7fff389385ce55f54f.tar.gz
glibc-3f649995a112b91754b49b7fff389385ce55f54f.tar.xz
glibc-3f649995a112b91754b49b7fff389385ce55f54f.zip
Remove access to legacy time zone support in gettimeofday etc. zack/gtod-no-timezone
gettimeofday and ftime are not quite fully implementable on systems
that only provide a primitive equivalent to clock_gettime, because
they can also report information about a system-wide time zone.  This
mechanism has been deprecated for many years because it can only be
configured on a system-wide basis, and because it only supports the
simplest kinds of daylight-savings rules, but we’ve supported it on a
best-effort basis until now.  This patch removes our support for it:

 * The type 'struct timezone' is still declared as a complete type in
   <sys/time.h>, but code that uses its fields (tz_minuteswest and
   tz_dsttime) will not compile.

 * Similarly, code that uses the 'timezone' and 'dstflag' fields of
   struct timeb will not compile anymore.  (This is a willful
   violation of the older iterations of XPG that included
   sys/timeb.h; the relevant conformance tests are XFAILed.)

 * Old binaries that pass a non-NULL 'tzp' pointer to gettimeofday
   will always receive a 'struct timezone' whose tz_minuteswest and
   tz_dsttime fields are zero (as if the system were operating on UTC).

 * Similarly, old binaries that call ftime will always receive a
   'struct timeb' whose timezone and dstflag fields are zero.

 * If the 'tzp' argument to settimeofday is not NULL, the call will fail
   and set errno to ENOSYS.  (This was already the case on the Hurd.)

 * glibc will always pass a second argument of NULL when invoking a
   kernel-provided gettimeofday.

 * On Alpha, the compat symbols gettimeofday@GLIBC_2.0 and
   settimeofday@GLIBC_2.0 (which used 32-bit time_t) now convert
   their arguments and call system primitives that use 64-bit time_t,
   instead of invoking legacy “osf” system calls.

ChangeLog:

	* time/sys/time.h (struct timezone): Remove tz_minuteswest
	and tz_dsttime fields; replace with padding to preserve the size.
	* time/sys/timeb.h (struct timeb): Remove timezone and dstflag
	fields; replace with padding to preserve the size.
	* conform/Makefile: XFAIL tests because struct timeb is no longer
	fully conformant with Unix98.

	* sysdeps/posix/gettimeofday.c
	* sysdeps/unix/sysv/linux/gettimeofday.c
	* sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
	* sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
	* sysdeps/unix/sysv/linux/x86/gettimeofday.c
	(gettimeofday): When ‘tz’ argument is not NULL, just clear it.
	Always pass a null pointer as the second argument to a
	gettimeofday (v)syscall.

	* sysdeps/unix/bsd/ftime.c: Unconditionally clear the memory that
	was formerly the ‘timezone’ and ‘dstflag’ fields of struct timeb.

	* sysdeps/unix/syscalls.list: Remove entry for settimeofday.
	* sysdeps/unix/settimeofday.c: New file.
	(settimeofday): Fail with ENOSYS if ‘tz’ argument is not NULL.

	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove entries for
        osf_gettimeofday, osf_settimeofday, and settimeofday.
	* sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c:
	New file.  Call the 64-bit gettimeofday, then convert to a
	32-bit struct timeval.  On overflow, saturate the struct timeval
	and fail with EOVERFLOW.
	* sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c: New file.
        Convert to a 64-bit struct timeval and call 64-bit settimeofday.
        Fail with ENOSYS if ‘tz’ argument is not NULL.

	* sunrpc/auth_des.c, sunrpc/auth_unix.c
	* sysdeps/posix/time.c, sysdeps/unix/stime.c:
	Remove unnecessary casts of NULL.

	* sysdeps/unix/sysv/linux/powerpc/time.c (time_syscall):
	Use (void *)0 instead of NULL when passing a null pointer
	as an untyped argument.

	* manual/time.texi: Remove documentation of fields of
	struct timezone.  Revise text to further emphasize that
	the second argument to gettimeofday/settimeofday should
	always be a null pointer.
Diffstat (limited to 'sysdeps/unix/settimeofday.c')
-rw-r--r--sysdeps/unix/settimeofday.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/sysdeps/unix/settimeofday.c b/sysdeps/unix/settimeofday.c
new file mode 100644
index 0000000000..741493b470
--- /dev/null
+++ b/sysdeps/unix/settimeofday.c
@@ -0,0 +1,36 @@
+/* settimeofday -- Set the current time of day.  Unix version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/time.h>
+#include <sysdep.h>
+#include <libc-symbols.h>
+
+/* Set the current time of day and timezone information.
+   This call is restricted to the super-user.  */
+int
+__settimeofday (const struct timeval *tv, const struct timezone *tz)
+{
+  if (tz)
+    {
+      __set_errno (ENOSYS);
+      return -1;
+    }
+  return INLINE_SYSCALL_CALL (settimeofday, tv, (void *)0);
+}
+weak_alias (__settimeofday, settimeofday);