attempting to bind() an already bound UNIX domain socket returns EINVAL (kre)
[unix-history] / usr / src / sys / kern / kern_time.c
index 28607a7..19009e2 100644 (file)
@@ -1,13 +1,19 @@
-/*     kern_time.c     5.14    82/12/30        */
+/*
+ * Copyright (c) 1982 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)kern_time.c 6.7 (Berkeley) %G%
+ */
 
 #include "../machine/reg.h"
 
 
 #include "../machine/reg.h"
 
-#include "../h/param.h"
-#include "../h/dir.h"          /* XXX */
-#include "../h/user.h"
-#include "../h/kernel.h"
-#include "../h/inode.h"
-#include "../h/proc.h"
+#include "param.h"
+#include "dir.h"               /* XXX */
+#include "user.h"
+#include "kernel.h"
+#include "inode.h"
+#include "proc.h"
 
 /* 
  * Time of day and interval timer support.
 
 /* 
  * Time of day and interval timer support.
@@ -55,8 +61,8 @@ settimeofday()
        if (uap->tzp && suser()) {
                u.u_error = copyin((caddr_t)uap->tzp, (caddr_t)&atz,
                        sizeof (atz));
        if (uap->tzp && suser()) {
                u.u_error = copyin((caddr_t)uap->tzp, (caddr_t)&atz,
                        sizeof (atz));
-               if (u.u_error)
-                       return;
+               if (u.u_error == 0)
+                       tz = atz;
        }
 }
 
        }
 }
 
@@ -73,6 +79,37 @@ setthetime(tv)
        resettodr();
 }
 
        resettodr();
 }
 
+int adjtimedelta;
+extern int tickadj;
+
+adjtime()
+{
+       register struct a {
+               struct timeval *delta;
+               struct timeval *olddelta;
+       } *uap = (struct a *)u.u_ap;
+       struct timeval atv, oatv;
+       int s;
+
+       if (!suser()) 
+               return;
+       u.u_error = copyin((caddr_t)uap->delta, (caddr_t)&atv,
+               sizeof (struct timeval));
+       if (u.u_error)
+               return;
+       s = splclock();
+       if (uap->olddelta) {
+               oatv.tv_sec = adjtimedelta / 1000000;
+               oatv.tv_usec = adjtimedelta % 1000000;
+               (void) copyout((caddr_t)&oatv, (caddr_t)uap->olddelta,
+                       sizeof (struct timeval));
+       }
+       adjtimedelta = atv.tv_sec * 1000000 + atv.tv_usec;
+       if (adjtimedelta % tickadj)
+               adjtimedelta = adjtimedelta / tickadj * tickadj;
+       splx(s);
+}
+
 /*
  * Get value of an interval timer.  The process virtual and
  * profiling virtual time timers are kept in the u. area, since
 /*
  * Get value of an interval timer.  The process virtual and
  * profiling virtual time timers are kept in the u. area, since
@@ -135,7 +172,7 @@ setitimer()
                u_int   which;
                struct  itimerval *itv, *oitv;
        } *uap = (struct a *)u.u_ap;
                u_int   which;
                struct  itimerval *itv, *oitv;
        } *uap = (struct a *)u.u_ap;
-       struct itimerval aitv;
+       struct itimerval aitv, *aitvp;
        int s;
        register struct proc *p = u.u_procp;
 
        int s;
        register struct proc *p = u.u_procp;
 
@@ -143,14 +180,16 @@ setitimer()
                u.u_error = EINVAL;
                return;
        }
                u.u_error = EINVAL;
                return;
        }
-       u.u_error = copyin((caddr_t)uap->itv, (caddr_t)&aitv,
-           sizeof (struct itimerval));
-       if (u.u_error)
-               return;
+       aitvp = uap->itv;
        if (uap->oitv) {
                uap->itv = uap->oitv;
                getitimer();
        }
        if (uap->oitv) {
                uap->itv = uap->oitv;
                getitimer();
        }
+       if (aitvp == 0)
+               return;
+       u.u_error = copyin(aitvp, (caddr_t)&aitv, sizeof (struct itimerval));
+       if (u.u_error)
+               return;
        if (itimerfix(&aitv.it_value) || itimerfix(&aitv.it_interval)) {
                u.u_error = EINVAL;
                return;
        if (itimerfix(&aitv.it_value) || itimerfix(&aitv.it_interval)) {
                u.u_error = EINVAL;
                return;
@@ -213,7 +252,7 @@ itimerfix(tv)
        if (tv->tv_sec < 0 || tv->tv_sec > 100000000 ||
            tv->tv_usec < 0 || tv->tv_usec >= 1000000)
                return (EINVAL);
        if (tv->tv_sec < 0 || tv->tv_sec > 100000000 ||
            tv->tv_usec < 0 || tv->tv_usec >= 1000000)
                return (EINVAL);
-       if (tv->tv_sec == 0 && tv->tv_usec < tick)
+       if (tv->tv_sec == 0 && tv->tv_usec != 0 && tv->tv_usec < tick)
                tv->tv_usec = tick;
        return (0);
 }
                tv->tv_usec = tick;
        return (0);
 }
@@ -298,73 +337,3 @@ timevalfix(t1)
                t1->tv_usec -= 1000000;
        }
 }
                t1->tv_usec -= 1000000;
        }
 }
-
-#ifndef NOCOMPAT
-otime()
-{
-
-       u.u_r.r_time = time.tv_sec;
-}
-
-ostime()
-{
-       register struct a {
-               int     time;
-       } *uap = (struct a *)u.u_ap;
-       struct timeval tv;
-
-       tv.tv_sec = uap->time;
-       tv.tv_usec = 0;
-       setthetime(&tv);
-}
-
-/* from old timeb.h */
-struct timeb {
-       time_t  time;
-       u_short millitm;
-       short   timezone;
-       short   dstflag;
-};
-
-oftime()
-{
-       register struct a {
-               struct  timeb   *tp;
-       } *uap;
-       struct timeb tb;
-
-       uap = (struct a *)u.u_ap;
-       (void) spl7();
-       tb.time = time.tv_sec;
-       tb.millitm = time.tv_usec / 1000;
-       (void) spl0();
-       tb.timezone = tz.tz_minuteswest;
-       tb.dstflag = tz.tz_dsttime;
-       u.u_error = copyout((caddr_t)&tb, (caddr_t)uap->tp, sizeof (tb));
-}
-
-oalarm()
-{
-       register struct a {
-               int     deltat;
-       } *uap = (struct a *)u.u_ap;
-       register struct proc *p = u.u_procp;
-       int s = spl7();
-
-       untimeout(realitexpire, (caddr_t)p);
-       timerclear(&p->p_realtimer.it_interval);
-       u.u_r.r_val1 = 0;
-       if (timerisset(&p->p_realtimer.it_value) &&
-           timercmp(&p->p_realtimer.it_value, &time, >))
-               u.u_r.r_val1 = p->p_realtimer.it_value.tv_sec - time.tv_sec;
-       if (uap->deltat == 0) {
-               timerclear(&p->p_realtimer.it_value);
-               splx(s);
-               return;
-       }
-       p->p_realtimer.it_value = time;
-       p->p_realtimer.it_value.tv_sec += uap->deltat;
-       timeout(realitexpire, (caddr_t)p, hzto(&p->p_realtimer.it_value));
-       splx(s);
-}
-#endif