Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc Added support to use the clockctl driver if present...
details: https://anonhg.NetBSD.org/src/rev/31cf41a5317c
branches: trunk
changeset: 515066:31cf41a5317c
user: manu <manu%NetBSD.org@localhost>
date: Sun Sep 16 07:41:56 2001 +0000
description:
Added support to use the clockctl driver if present for adjtime(),
clock_settime(), ntp_adjtime() and settimeofday(). The super-user still
always use the plain system call.
Approved by Christos
diffstat:
lib/libc/include/namespace.h | 6 ++-
lib/libc/sys/Makefile.inc | 16 +++---
lib/libc/sys/adjtime.2 | 18 ++++++-
lib/libc/sys/adjtime.c | 89 ++++++++++++++++++++++++++++++++++++++++++++
lib/libc/sys/clock_settime.2 | 20 ++++++++-
lib/libc/sys/clock_settime.c | 89 ++++++++++++++++++++++++++++++++++++++++++++
lib/libc/sys/gettimeofday.2 | 20 +++++++-
lib/libc/sys/ntp_adjtime.c | 87 +++++++++++++++++++++++++++++++++++++++++++
lib/libc/sys/settimeofday.c | 88 +++++++++++++++++++++++++++++++++++++++++++
9 files changed, 413 insertions(+), 20 deletions(-)
diffs (truncated from 594 to 300 lines):
diff -r 099722d3da9b -r 31cf41a5317c lib/libc/include/namespace.h
--- a/lib/libc/include/namespace.h Sun Sep 16 07:33:31 2001 +0000
+++ b/lib/libc/include/namespace.h Sun Sep 16 07:41:56 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: namespace.h,v 1.65 2001/05/07 17:25:58 kleink Exp $ */
+/* $NetBSD: namespace.h,v 1.66 2001/09/16 07:41:56 manu Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -38,10 +38,12 @@
#include <sys/cdefs.h>
+#define adjtime _adjtime
#define brk _brk
#define catclose _catclose
#define catgets _catgets
#define catopen _catopen
+#define clock_settime _clock_settime
#define daylight _daylight
#define err _err
#define errx _errx
@@ -332,6 +334,7 @@
#define nlist _nlist
#endif
#define nrand48 _nrand48
+#define ntp_adjtime _ntp_adjtime
#define nsdispatch _nsdispatch
#define offtime _offtime
#define opendir _opendir
@@ -401,6 +404,7 @@
#define setservent _setservent
#define setstate _setstate
#define setttyent _setttyent
+#define settimeofday _settimeofday
#define setusershell _setusershell
#define shm_open _shm_open
#define shm_unlink _shm_unlink
diff -r 099722d3da9b -r 31cf41a5317c lib/libc/sys/Makefile.inc
--- a/lib/libc/sys/Makefile.inc Sun Sep 16 07:33:31 2001 +0000
+++ b/lib/libc/sys/Makefile.inc Sun Sep 16 07:41:56 2001 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.115 2001/09/08 00:55:00 christos Exp $
+# $NetBSD: Makefile.inc,v 1.116 2001/09/16 07:41:57 manu Exp $
# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94
# sys sources
@@ -20,9 +20,9 @@
# glue to provide compatibility between GCC 1.X and 2.X and for compat
# with old syscall interfaces.
-SRCS+= ftruncate.c getdirentries.c lseek.c mmap.c msync.c \
- pread.c preadv.c pwrite.c pwritev.c semctl.c \
- sigaltstack.c stat.c swapon.c truncate.c
+SRCS+= adjtime.c clock_settime.c ftruncate.c getdirentries.c lseek.c mmap.c \
+ msync.c ntp_adjtime.c pread.c preadv.c pwrite.c pwritev.c semctl.c \
+ settimeofday.c sigaltstack.c stat.c swapon.c truncate.c
# glue to syscalls that may pass structs or unions, which cannot be
# handled portably and easily by the syscall interface. The glue
@@ -39,9 +39,9 @@
SRCS+= _brk.c _fork.c _pipe.c _sbrk.c
# modules with default implementations on all architectures:
-ASM= accept.o access.o acct.o adjtime.o bind.o chdir.o chflags.o \
+ASM= accept.o access.o acct.o bind.o chdir.o chflags.o \
chmod.o chown.o chroot.o clock_getres.o clock_gettime.o \
- clock_settime.o close.o connect.o dup.o dup2.o execve.o \
+ close.o connect.o dup.o dup2.o execve.o \
fchdir.o fchflags.o fchmod.o fchown.o fchroot.o fcntl.o \
fdatasync.o fhopen.o fhstat.o fhstatfs.o \
fktrace.o flock.o fpathconf.o __fstat13.o fstatfs.o \
@@ -55,13 +55,13 @@
madvise.o mincore.o minherit.o mkdir.o mkfifo.o mknod.o \
mlock.o mlockall.o mount.o mprotect.o __msgctl13.o msgget.o msgrcv.o \
msgsnd.o __msync13.o munlock.o munlockall.o munmap.o nanosleep.o \
- nfssvc.o ntp_adjtime.o ntp_gettime.o open.o pathconf.o \
+ nfssvc.o ntp_gettime.o open.o pathconf.o \
poll.o profil.o quotactl.o read.o \
readlink.o readv.o reboot.o recvfrom.o recvmsg.o rename.o revoke.o \
rmdir.o select.o semconfig.o semget.o semop.o ____semctl13.o sendmsg.o \
sendto.o setegid.o seteuid.o setgid.o setgroups.o setitimer.o \
setpgid.o setpriority.o setregid.o setreuid.o setrlimit.o \
- setsid.o setsockopt.o settimeofday.o setuid.o \
+ setsid.o setsockopt.o setuid.o \
__shmctl13.o shmdt.o shmget.o shutdown.o __sigaction14.o \
__sigaltstack14.o __sigpending14.o __sigprocmask14.o __sigsuspend14.o \
socket.o socketpair.o __stat13.o statfs.o \
diff -r 099722d3da9b -r 31cf41a5317c lib/libc/sys/adjtime.2
--- a/lib/libc/sys/adjtime.2 Sun Sep 16 07:33:31 2001 +0000
+++ b/lib/libc/sys/adjtime.2 Sun Sep 16 07:41:56 2001 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: adjtime.2,v 1.10 2001/09/16 01:38:59 wiz Exp $
+.\" $NetBSD: adjtime.2,v 1.11 2001/09/16 07:41:57 manu Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -81,9 +81,18 @@
Such time servers would slow down the clocks of some machines
and speed up the clocks of others to bring them to the average network time.
.Pp
-The call
+If the calling user is not the syper-user, then the
.Fn adjtime
-is restricted to the super-user.
+function in the standard C library will try to use the
+.Xr clockctl 4
+device if present, thus making possible for non privileged users to
+adjust the system time. If
+.Xr clockctl 4
+is not present or not accessible, then
+.Fn adjust
+reverts to the
+.Fn adjust
+system call, which is restricted to the super user.
.Sh RETURN VALUES
A return value of 0 indicates that the call succeeded.
A return value of -1 indicates that an error occurred, and in this
@@ -96,11 +105,12 @@
.It Bq Er EFAULT
An argument points outside the process's allocated address space.
.It Bq Er EPERM
-The process's effective user ID is not that of the super-user.
+The process's effective user ID is not that of the super user.
.El
.Sh SEE ALSO
.Xr date 1 ,
.Xr gettimeofday 2 ,
+.Xr clockctl 4 ,
.Xr timed 8 ,
.Xr timedc 8
.Rs
diff -r 099722d3da9b -r 31cf41a5317c lib/libc/sys/adjtime.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/sys/adjtime.c Sun Sep 16 07:41:56 2001 +0000
@@ -0,0 +1,89 @@
+/* $NetBSD: adjtime.c,v 1.1 2001/09/16 07:41:57 manu Exp $ */
+
+/*
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "namespace.h"
+#include <fcntl.h>
+#include <paths.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/syscall.h>
+#include <sys/clockctl.h>
+
+#ifdef __weak_alias
+__weak_alias(adjtime,_adjtime)
+#endif
+
+int
+adjtime(delta, olddelta)
+ const struct timeval *delta;
+ struct timeval *olddelta;
+{
+ struct clockctl_adjtime_args args;
+ int error;
+ int fd;
+ quad_t q;
+ int rv;
+
+ /*
+ * Root always uses the adjtime syscall
+ */
+ if (geteuid() == 0)
+ goto try_syscall;
+
+ /*
+ * Try to use /dev/clockctl, and revert to
+ * adjtime syscall if it fails.
+ */
+ fd = open(_PATH_CLOCKCTL, O_WRONLY, 0);
+ if (fd == -1)
+ goto try_syscall;
+
+ (void)memcpy(&args.delta, delta, sizeof(delta));
+ error = ioctl(fd, CLOCKCTL_ADJTIME, &args);
+ (void)close(fd);
+ if (!error && olddelta) {
+ (void)memcpy(olddelta, &args.olddelta, sizeof(olddelta));
+ return 0;
+ }
+
+try_syscall:
+ q = __syscall((quad_t)SYS_adjtime, delta, olddelta);
+ if (/* LINTED constant */ sizeof (quad_t) == sizeof (register_t) ||
+ /* LINTED constant */ BYTE_ORDER == LITTLE_ENDIAN)
+ rv = (int)q;
+ else
+ rv = (int)((u_quad_t)q >> 32);
+ return rv;
+}
diff -r 099722d3da9b -r 31cf41a5317c lib/libc/sys/clock_settime.2
--- a/lib/libc/sys/clock_settime.2 Sun Sep 16 07:33:31 2001 +0000
+++ b/lib/libc/sys/clock_settime.2 Sun Sep 16 07:41:56 2001 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: clock_settime.2,v 1.7 2001/09/16 02:13:27 wiz Exp $
+.\" $NetBSD: clock_settime.2,v 1.8 2001/09/16 07:41:57 manu Exp $
.\"
.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -94,6 +94,19 @@
.Fn clock_gettime
represent the amount of time (in seconds and nanoseconds)
since 00:00 Universal Coordinated Time, January 1, 1970.
+.Pp
+If the calling user is not the syper-user, then the
+.Fn clock_settime
+function in the standard C library will try to use the
+.Xr clockctl 4
+device if present, thus making possible for non privileged users to
+set the system time. If
+.Xr clockctl 4
+is not present or not accessible, then
+.Fn clock_settime
+reverts to the
+.Fn clock_settime
+system call, which is restricted to the super user.
.Sh RETURN VALUES
A value of 0 is returned on success. Otherwise, a value of -1 is returned and
.Va errno
@@ -147,8 +160,9 @@
.El
.Sh SEE ALSO
.Xr ctime 3 ,
-.Xr time 3
-.\" .Xr timer_gettime 3
+.Xr time 3 ,
+.\" .Xr timer_gettime 3 ,
+.Xr clockctl 4 .
.Sh STANDARDS
The
.Fn clock_settime ,
diff -r 099722d3da9b -r 31cf41a5317c lib/libc/sys/clock_settime.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/sys/clock_settime.c Sun Sep 16 07:41:56 2001 +0000
@@ -0,0 +1,89 @@
+/* $NetBSD: clock_settime.c,v 1.1 2001/09/16 07:41:57 manu Exp $ */
+
+/*
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Home |
Main Index |
Thread Index |
Old Index