Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Split root-only time-related system calls so that w...



details:   https://anonhg.NetBSD.org/src/rev/88313dc834e0
branches:  trunk
changeset: 515058:88313dc834e0
user:      manu <manu%NetBSD.org@localhost>
date:      Sun Sep 16 06:50:06 2001 +0000

description:
Split root-only time-related system calls so that we have an upper part, that
checks root privs, and a lower part that does the actual job. The lower part
will be called by the upcoming clockctl driver. Approved by Christos
Also fixed a few cosmetic things

diffstat:

 sys/kern/kern_ntptime.c |   33 ++++++++++-----
 sys/kern/kern_time.c    |  102 ++++++++++++++++++++++++++++++++++-------------
 2 files changed, 96 insertions(+), 39 deletions(-)

diffs (233 lines):

diff -r 978cd12e7cc9 -r 88313dc834e0 sys/kern/kern_ntptime.c
--- a/sys/kern/kern_ntptime.c   Sun Sep 16 05:40:46 2001 +0000
+++ b/sys/kern/kern_ntptime.c   Sun Sep 16 06:50:06 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_ntptime.c,v 1.13 2000/08/07 18:10:21 bjh21 Exp $  */
+/*     $NetBSD: kern_ntptime.c,v 1.14 2001/09/16 06:50:06 manu Exp $   */
 
 /******************************************************************************
  *                                                                            *
@@ -201,22 +201,33 @@
        } */ *uap = v;
        struct timex ntv;
        int error = 0;
+
+       if ((error = copyin((caddr_t)SCARG(uap, tp), (caddr_t)&ntv,
+                       sizeof(ntv))) != 0)
+               return (error);
+
+
+       if (ntv.modes != 0 && (error = suser(p->p_ucred, &p->p_acflag)) != 0)
+               return (error);
+
+       return (ntp_adjtime1(&ntv, retval));
+}
+
+int
+ntp_adjtime1(struct timex *, register_t*)
+       struct timex *ntv;
+       register_t      *retval;
+{
+       int error = 0;
        int modes;
        int s;
 
-       if ((error = copyin((caddr_t)SCARG(uap, tp), (caddr_t)&ntv,
-                       sizeof(ntv))))
-               return (error);
-
        /*
-        * Update selected clock variables - only the superuser can
-        * change anything. Note that there is no error checking here on
-        * the assumption the superuser should know what it is doing.
+        * Update selected clock variables. Note that there is no error 
+        * checking here on the assumption the superuser should know 
+        * what it is doing.
         */
        modes = ntv.modes;
-       if (modes != 0 && (error = suser(p->p_ucred, &p->p_acflag)))
-               return (error);
-
        s = splclock();
        if (modes & MOD_FREQUENCY)
 #ifdef PPS_SYNC
diff -r 978cd12e7cc9 -r 88313dc834e0 sys/kern/kern_time.c
--- a/sys/kern/kern_time.c      Sun Sep 16 05:40:46 2001 +0000
+++ b/sys/kern/kern_time.c      Sun Sep 16 06:50:06 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_time.c,v 1.55 2001/06/11 07:07:12 tron Exp $      */
+/*     $NetBSD: kern_time.c,v 1.56 2001/09/16 06:50:06 manu Exp $      */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -186,7 +186,6 @@
                syscallarg(const struct timespec *) tp;
        } */ *uap = v;
        clockid_t clock_id;
-       struct timeval atv;
        struct timespec ats;
        int error;
 
@@ -194,14 +193,27 @@
                return (error);
 
        clock_id = SCARG(uap, clock_id);
-       if (clock_id != CLOCK_REALTIME)
-               return (EINVAL);
 
        if ((error = copyin(SCARG(uap, tp), &ats, sizeof(ats))) != 0)
                return (error);
 
-       TIMESPEC_TO_TIMEVAL(&atv,&ats);
-       if ((error = settime(&atv)))
+       return (clock_settime1(clock_id, &ats));
+}
+
+
+int
+clock_settime1(clock_id, ats)
+       clockid_t clock_id;
+       struct timespec *ats;
+{
+       struct timeval atv;
+       int error;
+
+       if (clock_id != CLOCK_REALTIME)
+               return (EINVAL);
+
+       TIMESPEC_TO_TIMEVAL(&atv, ats);
+       if ((error = settime(&atv)) != 0)
                return (error);
 
        return 0;
@@ -344,26 +356,45 @@
        } */ *uap = v;
        struct timeval atv;
        struct timezone atz;
+       struct timeval *tv = NULL;
+       struct timezone *tzp = NULL;
        int error;
 
        if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
                return (error);
+
        /* Verify all parameters before changing time. */
-       if (SCARG(uap, tv) && (error = copyin(SCARG(uap, tv),
-           &atv, sizeof(atv))))
-               return (error);
+       if (SCARG(uap, tv)) {
+               if ((error = copyin(SCARG(uap, tv), &atv, sizeof(atv))) != 0)
+                       return (error);
+               tv = &atv;
+       }
        /* XXX since we don't use tz, probably no point in doing copyin. */
-       if (SCARG(uap, tzp) && (error = copyin(SCARG(uap, tzp),
-           &atz, sizeof(atz))))
-               return (error);
-       if (SCARG(uap, tv))
-               if ((error = settime(&atv)))
+       if (SCARG(uap, tzp)) {
+               if ((error = copyin(SCARG(uap, tzp), &atz, sizeof(atz))) != 0)
+                       return (error);
+               tzp = &atz;
+       }
+
+       return settimeofday1(tv, tzp, p);
+}
+
+int
+settimeofday1(tv, tzp, p)
+       struct timeval *tv;
+       struct timezone *tzp;
+       struct proc *p;
+{
+       int error;
+
+       if (tv)
+               if ((error = settime(tv)) != 0)
                        return (error);
        /*
         * NetBSD has no kernel notion of time zone, and only an
         * obsolete program would try to set it, so we log a warning.
         */
-       if (SCARG(uap, tzp))
+       if (tzp)
                log(LOG_WARNING, "pid %d attempted to set the "
                    "(obsolete) kernel time zone\n", p->p_pid); 
        return (0);
@@ -385,8 +416,8 @@
                syscallarg(struct timeval *) olddelta;
        } */ *uap = v;
        struct timeval atv;
-       long ndelta, ntickdelta, odelta;
-       int s, error;
+       struct timeval *oatv = NULL;
+       int error;
 
        if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
                return (error);
@@ -394,10 +425,25 @@
        error = copyin(SCARG(uap, delta), &atv, sizeof(struct timeval));
        if (error)
                return (error);
-       if (SCARG(uap, olddelta) != NULL &&
-           uvm_useracc((caddr_t)SCARG(uap, olddelta), sizeof(struct timeval),
-            B_WRITE) == FALSE)
-               return (EFAULT);
+
+       if (SCARG(uap, olddelta) != NULL) {
+               if (uvm_useracc((caddr_t)SCARG(uap, olddelta), 
+                   sizeof(struct timeval), B_WRITE) == FALSE)
+                       return (EFAULT);
+               oatv = SCARG(uap, olddelta);
+       }
+
+       return adjtime1(&atv, oatv, p);
+}
+
+int
+adjtime1(delta, olddelta, p)
+       struct timeval *delta;
+       struct timeval *olddelta;
+       struct proc *p;
+{
+       long ndelta, ntickdelta, odelta;
+       int s;
 
        /*
         * Compute the total correction and the rate at which to apply it.
@@ -406,7 +452,7 @@
         * hardclock(), tickdelta will become zero, lest the correction
         * overshoot and start taking us away from the desired final time.
         */
-       ndelta = atv.tv_sec * 1000000 + atv.tv_usec;
+       ndelta = delta->tv_sec * 1000000 + delta->tv_usec;
        if (ndelta > bigadj || ndelta < -bigadj)
                ntickdelta = 10 * tickadj;
        else
@@ -427,11 +473,10 @@
        tickdelta = ntickdelta;
        splx(s);
 
-       if (SCARG(uap, olddelta)) {
-               atv.tv_sec = odelta / 1000000;
-               atv.tv_usec = odelta % 1000000;
-               (void) copyout(&atv, SCARG(uap, olddelta),
-                   sizeof(struct timeval));
+       if (olddelta) {
+               delta->tv_sec = odelta / 1000000;
+               delta->tv_usec = odelta % 1000000;
+               (void) copyout(delta, olddelta, sizeof(struct timeval));
        }
        return (0);
 }
@@ -516,7 +561,8 @@
        if ((u_int)which > ITIMER_PROF)
                return (EINVAL);
        itvp = SCARG(uap, itv);
-       if (itvp && (error = copyin(itvp, &aitv, sizeof(struct itimerval))))
+       if (itvp && 
+           (error = copyin(itvp, &aitv, sizeof(struct itimerval)) != 0))
                return (error);
        if (SCARG(uap, oitv) != NULL) {
                SCARG(&getargs, which) = which;



Home | Main Index | Thread Index | Old Index