(no message)
authorBill Joy <root@ucbvax.Berkeley.EDU>
Tue, 7 Sep 1982 13:54:34 +0000 (05:54 -0800)
committerBill Joy <root@ucbvax.Berkeley.EDU>
Tue, 7 Sep 1982 13:54:34 +0000 (05:54 -0800)
SCCS-vsn: sys/kern/kern_proc.c 4.37
SCCS-vsn: sys/kern/kern_prot.c 5.6
SCCS-vsn: sys/kern/kern_resource.c 4.13
SCCS-vsn: sys/kern/kern_sig.c 5.6
SCCS-vsn: sys/kern/kern_synch.c 4.20
SCCS-vsn: sys/kern/kern_time.c 5.4
SCCS-vsn: sys/kern/sys_generic.c 5.13
SCCS-vsn: sys/kern/uipc_syscalls.c 4.26

usr/src/sys/kern/kern_proc.c
usr/src/sys/kern/kern_prot.c
usr/src/sys/kern/kern_resource.c
usr/src/sys/kern/kern_sig.c
usr/src/sys/kern/kern_synch.c
usr/src/sys/kern/kern_time.c
usr/src/sys/kern/sys_generic.c
usr/src/sys/kern/uipc_syscalls.c

index e81a4c9..6b3b8e9 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_proc.c     4.36    82/09/04        */
+/*     kern_proc.c     4.37    82/09/06        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 gethostid()
 {
 
 gethostid()
 {
 
+       u.u_r.r_val1 = hostid;
 }
 
 sethostid()
 {
 }
 
 sethostid()
 {
+       struct a {
+               int     hostid;
+       } *uap = (struct a *)u.u_ap;
 
 
+       if (suser())
+               hostid = uap->hostid;
+}
+
+gethostname()
+{
+       register struct a {
+               char    *hostname;
+               int     len;
+       } *uap = (struct a *)u.u_ap;
+       register u_int len;
+
+       len = uap->len;
+       if (len > hostnamelen)
+               len = hostnamelen;
+       if (copyout((caddr_t)hostname, (caddr_t)uap->hostname, len))
+               u.u_error = EFAULT;
+}
+
+sethostname()
+{
+       register struct a {
+               char    *hostname;
+               u_int   len;
+       } *uap = (struct a *)u.u_ap;
+
+       if (!suser())
+               return;
+       if (uap->len > sizeof (hostname) - 1) {
+               u.u_error = EINVAL;
+               return;
+       }
+       hostnamelen = uap->len;
+       if (copyin((caddr_t)uap->hostname, hostname, uap->len))
+               u.u_error = EFAULT;
+       hostname[hostnamelen] = 0;
 }
 
 /*
 }
 
 /*
@@ -604,7 +644,7 @@ done:
        swtch();
 }
 
        swtch();
 }
 
-wait()
+owait()
 {
        struct rusage ru, *rup;
 
 {
        struct rusage ru, *rup;
 
@@ -833,3 +873,172 @@ pfind(pid)
                        return (p);
        return ((struct proc *)0);
 }
                        return (p);
        return ((struct proc *)0);
 }
+
+/*
+ * Create a new process-- the internal version of
+ * sys fork.
+ * It returns 1 in the new process, 0 in the old.
+ */
+newproc(isvfork)
+       int isvfork;
+{
+       register struct proc *p;
+       register struct proc *rpp, *rip;
+       register int n;
+       register struct file *fp;
+
+       p = NULL;
+       /*
+        * First, just locate a slot for a process
+        * and copy the useful info from this process into it.
+        * The panic "cannot happen" because fork has already
+        * checked for the existence of a slot.
+        */
+retry:
+       mpid++;
+       if (mpid >= 30000) {
+               mpid = 0;
+               goto retry;
+       }
+       for (rpp = proc; rpp < procNPROC; rpp++) {
+               if (rpp->p_stat == NULL && p==NULL)
+                       p = rpp;
+               if (rpp->p_pid==mpid || rpp->p_pgrp==mpid)
+                       goto retry;
+       }
+       if ((rpp = p) == NULL)
+               panic("no procs");
+
+       /*
+        * Make a proc table entry for the new process.
+        */
+       rip = u.u_procp;
+#ifdef QUOTA
+       (rpp->p_quota = rip->p_quota)->q_cnt++;
+#endif
+       rpp->p_stat = SIDL;
+       timerclear(&rpp->p_realtimer.it_value);
+       rpp->p_flag = SLOAD | (rip->p_flag & (SPAGI|SNUSIG));
+       if (isvfork) {
+               rpp->p_flag |= SVFORK;
+               rpp->p_ndx = rip->p_ndx;
+       } else
+               rpp->p_ndx = rpp - proc;
+       rpp->p_uid = rip->p_uid;
+       rpp->p_pgrp = rip->p_pgrp;
+       rpp->p_nice = rip->p_nice;
+       rpp->p_textp = isvfork ? 0 : rip->p_textp;
+       rpp->p_pid = mpid;
+       rpp->p_ppid = rip->p_pid;
+       rpp->p_pptr = rip;
+       rpp->p_osptr = rip->p_cptr;
+       if (rip->p_cptr)
+               rip->p_cptr->p_ysptr = rpp;
+       rpp->p_ysptr = NULL;
+       rpp->p_cptr = NULL;
+       rip->p_cptr = rpp;
+       rpp->p_time = 0;
+       rpp->p_cpu = 0;
+       rpp->p_siga0 = rip->p_siga0;
+       rpp->p_siga1 = rip->p_siga1;
+       /* take along any pending signals, like stops? */
+       if (isvfork) {
+               rpp->p_tsize = rpp->p_dsize = rpp->p_ssize = 0;
+               rpp->p_szpt = clrnd(ctopt(UPAGES));
+               forkstat.cntvfork++;
+               forkstat.sizvfork += rip->p_dsize + rip->p_ssize;
+       } else {
+               rpp->p_tsize = rip->p_tsize;
+               rpp->p_dsize = rip->p_dsize;
+               rpp->p_ssize = rip->p_ssize;
+               rpp->p_szpt = rip->p_szpt;
+               forkstat.cntfork++;
+               forkstat.sizfork += rip->p_dsize + rip->p_ssize;
+       }
+       rpp->p_rssize = 0;
+       rpp->p_maxrss = rip->p_maxrss;
+       rpp->p_wchan = 0;
+       rpp->p_slptime = 0;
+       rpp->p_pctcpu = 0;
+       rpp->p_cpticks = 0;
+       n = PIDHASH(rpp->p_pid);
+       p->p_idhash = pidhash[n];
+       pidhash[n] = rpp - proc;
+       multprog++;
+
+       /*
+        * Increase reference counts on shared objects.
+        */
+       for (n = 0; n < NOFILE; n++) {
+               fp = u.u_ofile[n];
+               if (fp == NULL)
+                       continue;
+               fp->f_count++;
+               if (u.u_pofile[n]&RDLOCK)
+                       fp->f_inode->i_rdlockc++;
+               if (u.u_pofile[n]&WRLOCK)
+                       fp->f_inode->i_wrlockc++;
+       }
+       u.u_cdir->i_count++;
+       if (u.u_rdir)
+               u.u_rdir->i_count++;
+
+       /*
+        * Partially simulate the environment
+        * of the new process so that when it is actually
+        * created (by copying) it will look right.
+        * This begins the section where we must prevent the parent
+        * from being swapped.
+        */
+       rip->p_flag |= SKEEP;
+       if (procdup(rpp, isvfork))
+               return (1);
+
+       /*
+        * Make child runnable and add to run queue.
+        */
+       (void) spl6();
+       rpp->p_stat = SRUN;
+       setrq(rpp);
+       (void) spl0();
+
+       /*
+        * Cause child to take a non-local goto as soon as it runs.
+        * On older systems this was done with SSWAP bit in proc
+        * table; on VAX we use u.u_pcb.pcb_sswap so don't need
+        * to do rpp->p_flag |= SSWAP.  Actually do nothing here.
+        */
+       /* rpp->p_flag |= SSWAP; */
+
+       /*
+        * Now can be swapped.
+        */
+       rip->p_flag &= ~SKEEP;
+
+       /*
+        * If vfork make chain from parent process to child
+        * (where virtal memory is temporarily).  Wait for
+        * child to finish, steal virtual memory back,
+        * and wakeup child to let it die.
+        */
+       if (isvfork) {
+               u.u_procp->p_xlink = rpp;
+               u.u_procp->p_flag |= SNOVM;
+               while (rpp->p_flag & SVFORK)
+                       sleep((caddr_t)rpp, PZERO - 1);
+               if ((rpp->p_flag & SLOAD) == 0)
+                       panic("newproc vfork");
+               uaccess(rpp, Vfmap, &vfutl);
+               u.u_procp->p_xlink = 0;
+               vpassvm(rpp, u.u_procp, &vfutl, &u, Vfmap);
+               u.u_procp->p_flag &= ~SNOVM;
+               rpp->p_ndx = rpp - proc;
+               rpp->p_flag |= SVFDONE;
+               wakeup((caddr_t)rpp);
+       }
+
+       /*
+        * 0 return means parent.
+        */
+       return (0);
+}
index 715ede3..312e2bb 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_prot.c     5.5     82/08/24        */
+/*     kern_prot.c     5.6     82/09/06        */
 
 /*
  * System calls related to processes and protection
 
 /*
  * System calls related to processes and protection
@@ -11,7 +11,6 @@
 #include "../h/reg.h"
 #include "../h/inode.h"
 #include "../h/proc.h"
 #include "../h/reg.h"
 #include "../h/inode.h"
 #include "../h/proc.h"
-#include "../h/clock.h"
 #include "../h/mtpr.h"
 #include "../h/timeb.h"
 #include "../h/times.h"
 #include "../h/mtpr.h"
 #include "../h/timeb.h"
 #include "../h/times.h"
@@ -154,7 +153,8 @@ setgroups()
        } *uap = (struct a *)u.u_ap;
        register int *gp;
 
        } *uap = (struct a *)u.u_ap;
        register int *gp;
 
-       if (suser())
+printf("gidsetsize %d, gidset %x\n", uap->gidsetsize, uap->gidset);
+       if (!suser())
                return;
        if (uap->gidsetsize > sizeof (u.u_groups) / sizeof (u.u_groups[0])) {
                u.u_error = EINVAL;
                return;
        if (uap->gidsetsize > sizeof (u.u_groups) / sizeof (u.u_groups[0])) {
                u.u_error = EINVAL;
@@ -165,6 +165,7 @@ setgroups()
                u.u_error = EFAULT;
                return;
        }
                u.u_error = EFAULT;
                return;
        }
+printf("copied in %d %d ... \n", u.u_groups[0], u.u_groups[1]);
        for (gp = &u.u_groups[uap->gidsetsize]; gp < &u.u_groups[NGROUPS]; gp++)
                *gp = -1;
 }
        for (gp = &u.u_groups[uap->gidsetsize]; gp < &u.u_groups[NGROUPS]; gp++)
                *gp = -1;
 }
index b488947..7caa1e5 100644 (file)
@@ -1,8 +1,7 @@
-/*     kern_resource.c 4.12    82/09/04        */
+/*     kern_resource.c 4.13    82/09/06        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
-#include "../h/acct.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/inode.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/inode.h"
@@ -106,7 +105,7 @@ donice(p, n)
                u.u_error = 0;
 }
 
                u.u_error = 0;
 }
 
-setlimit()
+setrlimit()
 {
        register struct a {
                u_int   which;
 {
        register struct a {
                u_int   which;
@@ -144,7 +143,7 @@ setlimit()
                u.u_procp->p_maxrss = alim.rlim_cur/NBPG;
 }
 
                u.u_procp->p_maxrss = alim.rlim_cur/NBPG;
 }
 
-getlimit()
+getrlimit()
 {
        register struct a {
                u_int   which;
 {
        register struct a {
                u_int   which;
@@ -205,137 +204,31 @@ ruadd(ru, ru2)
                *ip++ += *ip2++;
 }
 
                *ip++ += *ip2++;
 }
 
-struct inode *acctp;
-struct inode *savacctp;
-
-long   acctlow = 2;            /* stop accounting when < 2% data space left */
-long   accthigh = 4;           /* resume when space risen to > 4% */
-
-/*
- * Perform process accounting functions.
- */
-sysacct()
+#ifndef NOCOMPAT
+onice()
 {
 {
-       register struct inode *ip;
        register struct a {
        register struct a {
-               char    *fname;
+               int     niceness;
        } *uap;
 
        uap = (struct a *)u.u_ap;
        } *uap;
 
        uap = (struct a *)u.u_ap;
-       if (suser()) {
-               if (savacctp) {
-                       acctp = savacctp;
-                       savacctp = NULL;
-               }
-               if (uap->fname==NULL) {
-                       if (ip = acctp) {
-                               irele(ip);
-                               acctp = NULL;
-                       }
-                       return;
-               }
-               ip = namei(uchar, 0, 1);
-               if(ip == NULL)
-                       return;
-               if((ip->i_mode & IFMT) != IFREG) {
-                       u.u_error = EACCES;
-                       iput(ip);
-                       return;
-               }
-               if (acctp && (acctp->i_number != ip->i_number ||
-                   acctp->i_dev != ip->i_dev))
-                       irele(acctp);
-               acctp = ip;
-               iunlock(ip);
-       }
+       donice(u.u_procp, uap->niceness);
 }
 }
+#endif
 
 
-struct acct acctbuf;
-/*
- * On exit, write a record on the accounting file.
- */
-acct()
+otimes()
 {
 {
-       register i;
-       register struct inode *ip;
-       off_t siz;
-       register struct acct *ap = &acctbuf;
-
-       if (savacctp && savacctp->i_fs->fs_cstotal.cs_nbfree >
-           accthigh * savacctp->i_fs->fs_dsize / 100) {
-               acctp = savacctp;
-               savacctp = NULL;
-               printf("Accounting resumed\n");
-       }
-       if ((ip=acctp)==NULL)
-               return;
-       if (acctp->i_fs->fs_cstotal.cs_nbfree <
-           acctlow * acctp->i_fs->fs_dsize / 100) {
-               savacctp = acctp;
-               acctp = NULL;
-               printf("Accounting suspended\n");
-               return;
-       }
-       ilock(ip);
-       for (i=0; i<sizeof(ap->ac_comm); i++)
-               ap->ac_comm[i] = u.u_comm[i];
-       ap->ac_utime = compress((long)u.u_ru.ru_utime.tv_sec);
-       ap->ac_stime = compress((long)u.u_ru.ru_stime.tv_sec);
-       ap->ac_etime = compress((long)(time - u.u_start));
-       ap->ac_btime = u.u_start;
-       ap->ac_uid = u.u_ruid;
-       ap->ac_gid = u.u_rgid;
-       ap->ac_mem = 0;
-       if (i = u.u_ru.ru_utime.tv_sec + u.u_ru.ru_stime.tv_sec)
-               ap->ac_mem =
-                   (u.u_ru.ru_ixrss + u.u_ru.ru_idrss + u.u_ru.ru_isrss) / i;
-       ap->ac_io = compress((long)(u.u_ru.ru_inblock + u.u_ru.ru_oublock));
-       if (u.u_ttyp)
-               ap->ac_tty = u.u_ttyd;
-       else
-               ap->ac_tty = NODEV;
-       ap->ac_flag = u.u_acflag;
-       siz = ip->i_size;
-       u.u_error =
-           rdwri(UIO_WRITE, ip, (caddr_t)ap, sizeof (acctbuf), siz,
-               1, (int *)0);
-       if (u.u_error)
-               ip->i_size = siz;
-       iunlock(ip);
+
+       /* XXX */
 }
 
 }
 
-/*
- * Produce a pseudo-floating point representation
- * with 3 bits base-8 exponent, 13 bits fraction.
- */
-compress(t)
-register long t;
+ovtimes()
 {
 {
-       register exp = 0, round = 0;
 
 
-       while (t >= 8192) {
-               exp++;
-               round = t&04;
-               t >>= 3;
-       }
-       if (round) {
-               t++;
-               if (t >= 8192) {
-                       t >>= 3;
-                       exp++;
-               }
-       }
-       return((exp<<13) + t);
+       /* XXX */
 }
 
 }
 
-#ifndef NOCOMPAT
-onice()
+ovlimit()
 {
 {
-       register struct a {
-               int     niceness;
-       } *uap;
 
 
-       uap = (struct a *)u.u_ap;
-       donice(u.u_procp, uap->niceness);
 }
 }
-#endif
index 4cf8e02..40927ad 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_sig.c      5.5     82/09/04        */
+/*     kern_sig.c      5.6     82/09/06        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -709,11 +709,11 @@ core()
        u.u_error =rdwri(UIO_WRITE, ip,
            (caddr_t)&u, ctob(UPAGES),
            0, 1, (int *)0);
        u.u_error =rdwri(UIO_WRITE, ip,
            (caddr_t)&u, ctob(UPAGES),
            0, 1, (int *)0);
-       if (u.u_error)
+       if (u.u_error == 0)
        rdwri(UIO_WRITE, ip,
            (caddr_t)ctob(u.u_tsize), ctob(u.u_dsize),
            ctob(UPAGES), 0, (int *)0);
        rdwri(UIO_WRITE, ip,
            (caddr_t)ctob(u.u_tsize), ctob(u.u_dsize),
            ctob(UPAGES), 0, (int *)0);
-       if (u.u_error)
+       if (u.u_error == 0)
        rdwri(UIO_WRITE, ip,
            (caddr_t)(USRSTACK-ctob(u.u_ssize)), ctob(u.u_ssize),
            ctob(UPAGES)+ctob(u.u_dsize), 0, (int *)0);
        rdwri(UIO_WRITE, ip,
            (caddr_t)(USRSTACK-ctob(u.u_ssize)), ctob(u.u_ssize),
            ctob(UPAGES)+ctob(u.u_dsize), 0, (int *)0);
@@ -733,10 +733,10 @@ oalarm()
        register struct proc *p = u.u_procp;
        int s = spl7();
 
        register struct proc *p = u.u_procp;
        int s = spl7();
 
-       p->p_realtimer.itimer_reload = 0;
-       u.u_r.r_val1 = p->p_realtimer.itimer_value.tv_sec;
-       p->p_realtimer.itimer_value.tv_sec = uap->deltat;
-       p->p_realtimer.itimer_value.tv_usec = 0;
+       timerclear(&p->p_realtimer.it_interval);
+       u.u_r.r_val1 = p->p_realtimer.it_value.tv_sec;
+       p->p_realtimer.it_value.tv_sec = uap->deltat;
+       p->p_realtimer.it_value.tv_usec = 0;
        splx(s);
 }
 
        splx(s);
 }
 
index dc6befe..b713619 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_synch.c    4.19    82/09/04        */
+/*     kern_synch.c    4.20    82/09/06        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/pte.h"
 #include "../h/inline.h"
 #include "../h/mtpr.h"
 #include "../h/pte.h"
 #include "../h/inline.h"
 #include "../h/mtpr.h"
+#ifdef MUSH
 #include "../h/quota.h"
 #include "../h/quota.h"
+#include "../h/share.h"
+#endif
+#include "../h/kernel.h"
+#include "../h/buf.h"
+
+/*
+ * Force switch among equal priority processes every 100ms.
+ */
+roundrobin()
+{
+
+       runrun++;
+       aston();
+       timeout(roundrobin, 0, hz / 10);
+}
+
+/*
+ * The digital decay cpu usage priority assignment is scaled to run in
+ * time as expanded by the 1 minute load average.  Each second we
+ * multiply the the previous cpu usage estimate by
+ *             nrscale*avenrun[0]
+ * The following relates the load average to the period over which
+ * cpu usage is 90% forgotten:
+ *     loadav 1         5 seconds
+ *     loadav 5        24 seconds
+ *     loadav 10       47 seconds
+ *     loadav 20       93 seconds
+ * This is a great improvement on the previous algorithm which
+ * decayed the priorities by a constant, and decayed away all knowledge
+ * of previous activity in about 20 seconds.  Under heavy load,
+ * the previous algorithm degenerated to round-robin with poor response
+ * time when there was a high load average.
+ */
+#undef ave
+#define        ave(a,b) ((int)(((int)(a*b))/(b+1)))
+int    nrscale = 2;
+double avenrun[];
+
+/*
+ * Constant for decay filter for cpu usage field
+ * in process table (used by ps au).
+ */
+double ccpu = 0.95122942450071400909;          /* exp(-1/20) */
+
+#ifdef MELB
+/*
+ * Automatic niceness rate & max constants
+ */
+#define        MAXNICE (8 + NZERO)     /* maximum auto nice value */
+#define        NFACT   (40 * hz)       /* nice++ every 40 secs cpu+sys time */
+#endif
+
+/*
+ * Recompute process priorities, once a second
+ */
+schedcpu()
+{
+       register struct proc *p;
+       register int s, a;
+
+       s = spl6(); time.tv_sec += lbolt / hz; lbolt %= hz; splx(s);
+       wakeup((caddr_t)&lbolt);
+
+       for (p = proc; p < procNPROC; p++) if (p->p_stat && p->p_stat!=SZOMB) {
+#ifdef MUSH
+               /*
+                * Charge process for memory in use
+                */
+               if (p->p_quota->q_uid)
+                       p->p_quota->q_cost +=
+                           shconsts.sc_click * p->p_rssize;
+#endif
+               if (p->p_time != 127)
+                       p->p_time++;
+               if (timerisset(&p->p_seltimer) &&
+                    --p->p_seltimer.tv_sec <= 0) {
+                       timerclear(&p->p_seltimer);
+                       s = spl6();
+                       switch (p->p_stat) {
+
+                       case SSLEEP:
+                               setrun(p);
+                               break;
+
+                       case SSTOP:
+                               unsleep(p);
+                               break;
+                       }
+                       splx(s);
+               }
+               if (timerisset(&p->p_realtimer.it_value) &&
+                   itimerdecr(&p->p_realtimer, 1000000) == 0)
+                       psignal(p, SIGALRM);
+               if (p->p_stat==SSLEEP || p->p_stat==SSTOP)
+                       if (p->p_slptime != 127)
+                               p->p_slptime++;
+               if (p->p_flag&SLOAD)
+                       p->p_pctcpu = ccpu * p->p_pctcpu +
+                           (1.0 - ccpu) * (p->p_cpticks/(float)hz);
+               p->p_cpticks = 0;
+#ifdef MUSH
+               a = ave((p->p_cpu & 0377), avenrun[0]*nrscale) +
+                    p->p_nice - NZERO + p->p_quota->q_nice;
+#else
+               a = ave((p->p_cpu & 0377), avenrun[0]*nrscale) +
+                    p->p_nice - NZERO;
+#endif
+               if (a < 0)
+                       a = 0;
+               if (a > 255)
+                       a = 255;
+               p->p_cpu = a;
+               (void) setpri(p);
+               s = spl6();     /* prevent state changes */
+               if (p->p_pri >= PUSER) {
+                       if ((p != u.u_procp || noproc) &&
+                           p->p_stat == SRUN &&
+                           (p->p_flag & SLOAD) &&
+                           p->p_pri != p->p_usrpri) {
+                               remrq(p);
+                               p->p_pri = p->p_usrpri;
+                               setrq(p);
+                       } else
+                               p->p_pri = p->p_usrpri;
+               }
+               splx(s);
+       }
+       vmmeter();
+       if (runin!=0) {
+               runin = 0;
+               wakeup((caddr_t)&runin);
+       }
+       if (bclnlist != NULL)
+               wakeup((caddr_t)&proc[2]);
+       timeout(schedcpu, 0, hz);
+}
 
 #define SQSIZE 0100    /* Must be power of 2 */
 #define HASH(x)        (( (int) x >> 5) & (SQSIZE-1))
 
 #define SQSIZE 0100    /* Must be power of 2 */
 #define HASH(x)        (( (int) x >> 5) & (SQSIZE-1))
@@ -95,7 +232,7 @@ tsleep(chan, pri, tvp)
        int s, rval;
 
        s = spl7();
        int s, rval;
 
        s = spl7();
-       if (timercmp(tvp, &p->p_realtimer.itimer_value, >)) {
+       if (timercmp(tvp, &p->p_realtimer.it_value, >)) {
                /* alarm will occur first! */
                sleep(chan, pri);
                rval = TS_OK;           /* almost NOTREACHED modulo fuzz */
                /* alarm will occur first! */
                sleep(chan, pri);
                rval = TS_OK;           /* almost NOTREACHED modulo fuzz */
@@ -261,172 +398,3 @@ setpri(pp)
        pp->p_usrpri = p;
        return (p);
 }
        pp->p_usrpri = p;
        return (p);
 }
-
-/*
- * Create a new process-- the internal version of
- * sys fork.
- * It returns 1 in the new process, 0 in the old.
- */
-newproc(isvfork)
-       int isvfork;
-{
-       register struct proc *p;
-       register struct proc *rpp, *rip;
-       register int n;
-       register struct file *fp;
-
-       p = NULL;
-       /*
-        * First, just locate a slot for a process
-        * and copy the useful info from this process into it.
-        * The panic "cannot happen" because fork has already
-        * checked for the existence of a slot.
-        */
-retry:
-       mpid++;
-       if (mpid >= 30000) {
-               mpid = 0;
-               goto retry;
-       }
-       for (rpp = proc; rpp < procNPROC; rpp++) {
-               if (rpp->p_stat == NULL && p==NULL)
-                       p = rpp;
-               if (rpp->p_pid==mpid || rpp->p_pgrp==mpid)
-                       goto retry;
-       }
-       if ((rpp = p) == NULL)
-               panic("no procs");
-
-       /*
-        * Make a proc table entry for the new process.
-        */
-       rip = u.u_procp;
-#ifdef QUOTA
-       (rpp->p_quota = rip->p_quota)->q_cnt++;
-#endif
-       rpp->p_stat = SIDL;
-       timerclear(&rpp->p_realtimer.itimer_value);
-       rpp->p_flag = SLOAD | (rip->p_flag & (SPAGI|SNUSIG));
-       if (isvfork) {
-               rpp->p_flag |= SVFORK;
-               rpp->p_ndx = rip->p_ndx;
-       } else
-               rpp->p_ndx = rpp - proc;
-       rpp->p_uid = rip->p_uid;
-       rpp->p_pgrp = rip->p_pgrp;
-       rpp->p_nice = rip->p_nice;
-       rpp->p_textp = isvfork ? 0 : rip->p_textp;
-       rpp->p_pid = mpid;
-       rpp->p_ppid = rip->p_pid;
-       rpp->p_pptr = rip;
-       rpp->p_osptr = rip->p_cptr;
-       if (rip->p_cptr)
-               rip->p_cptr->p_ysptr = rpp;
-       rpp->p_ysptr = NULL;
-       rpp->p_cptr = NULL;
-       rip->p_cptr = rpp;
-       rpp->p_time = 0;
-       rpp->p_cpu = 0;
-       rpp->p_siga0 = rip->p_siga0;
-       rpp->p_siga1 = rip->p_siga1;
-       /* take along any pending signals, like stops? */
-       if (isvfork) {
-               rpp->p_tsize = rpp->p_dsize = rpp->p_ssize = 0;
-               rpp->p_szpt = clrnd(ctopt(UPAGES));
-               forkstat.cntvfork++;
-               forkstat.sizvfork += rip->p_dsize + rip->p_ssize;
-       } else {
-               rpp->p_tsize = rip->p_tsize;
-               rpp->p_dsize = rip->p_dsize;
-               rpp->p_ssize = rip->p_ssize;
-               rpp->p_szpt = rip->p_szpt;
-               forkstat.cntfork++;
-               forkstat.sizfork += rip->p_dsize + rip->p_ssize;
-       }
-       rpp->p_rssize = 0;
-       rpp->p_maxrss = rip->p_maxrss;
-       rpp->p_wchan = 0;
-       rpp->p_slptime = 0;
-       rpp->p_pctcpu = 0;
-       rpp->p_cpticks = 0;
-       n = PIDHASH(rpp->p_pid);
-       p->p_idhash = pidhash[n];
-       pidhash[n] = rpp - proc;
-       multprog++;
-
-       /*
-        * Increase reference counts on shared objects.
-        */
-       for (n = 0; n < NOFILE; n++) {
-               fp = u.u_ofile[n];
-               if (fp == NULL)
-                       continue;
-               fp->f_count++;
-               if (u.u_pofile[n]&RDLOCK)
-                       fp->f_inode->i_rdlockc++;
-               if (u.u_pofile[n]&WRLOCK)
-                       fp->f_inode->i_wrlockc++;
-       }
-       u.u_cdir->i_count++;
-       if (u.u_rdir)
-               u.u_rdir->i_count++;
-
-       /*
-        * Partially simulate the environment
-        * of the new process so that when it is actually
-        * created (by copying) it will look right.
-        * This begins the section where we must prevent the parent
-        * from being swapped.
-        */
-       rip->p_flag |= SKEEP;
-       if (procdup(rpp, isvfork))
-               return (1);
-
-       /*
-        * Make child runnable and add to run queue.
-        */
-       (void) spl6();
-       rpp->p_stat = SRUN;
-       setrq(rpp);
-       (void) spl0();
-
-       /*
-        * Cause child to take a non-local goto as soon as it runs.
-        * On older systems this was done with SSWAP bit in proc
-        * table; on VAX we use u.u_pcb.pcb_sswap so don't need
-        * to do rpp->p_flag |= SSWAP.  Actually do nothing here.
-        */
-       /* rpp->p_flag |= SSWAP; */
-
-       /*
-        * Now can be swapped.
-        */
-       rip->p_flag &= ~SKEEP;
-
-       /*
-        * If vfork make chain from parent process to child
-        * (where virtal memory is temporarily).  Wait for
-        * child to finish, steal virtual memory back,
-        * and wakeup child to let it die.
-        */
-       if (isvfork) {
-               u.u_procp->p_xlink = rpp;
-               u.u_procp->p_flag |= SNOVM;
-               while (rpp->p_flag & SVFORK)
-                       sleep((caddr_t)rpp, PZERO - 1);
-               if ((rpp->p_flag & SLOAD) == 0)
-                       panic("newproc vfork");
-               uaccess(rpp, Vfmap, &vfutl);
-               u.u_procp->p_xlink = 0;
-               vpassvm(rpp, u.u_procp, &vfutl, &u, Vfmap);
-               u.u_procp->p_flag &= ~SNOVM;
-               rpp->p_ndx = rpp - proc;
-               rpp->p_flag |= SVFDONE;
-               wakeup((caddr_t)rpp);
-       }
-
-       /*
-        * 0 return means parent.
-        */
-       return (0);
-}
index 4dc95e4..6629761 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_time.c     5.3     82/09/04        */
+/*     kern_time.c     5.4     82/09/06        */
 
 #include "../h/param.h"
 #include "../h/dir.h"          /* XXX */
 
 #include "../h/param.h"
 #include "../h/dir.h"          /* XXX */
@@ -8,6 +8,10 @@
 #include "../h/inode.h"
 #include "../h/proc.h"
 
 #include "../h/inode.h"
 #include "../h/proc.h"
 
+/* 
+ * Time of day and interval timer support.
+ */
+
 gettimeofday()
 {
        register struct a {
 gettimeofday()
 {
        register struct a {
@@ -15,14 +19,16 @@ gettimeofday()
                struct  timezone *tzp;
        } *uap = (struct a *)u.u_ap;
        struct timeval atv;
                struct  timezone *tzp;
        } *uap = (struct a *)u.u_ap;
        struct timeval atv;
+       int s;
 
 
-       microtime(&atv);
+       s = spl7(); atv = time; splx(s);
        if (copyout((caddr_t)&atv, (caddr_t)uap->tp, sizeof (atv))) {
                u.u_error = EFAULT;
                return;
        }
        if (uap->tzp == 0)
                return;
        if (copyout((caddr_t)&atv, (caddr_t)uap->tp, sizeof (atv))) {
                u.u_error = EFAULT;
                return;
        }
        if (uap->tzp == 0)
                return;
+       /* SHOULD HAVE PER-PROCESS TIMEZONE */
        if (copyout((caddr_t)&tz, uap->tzp, sizeof (tz))) {
                u.u_error = EFAULT;
                return;
        if (copyout((caddr_t)&tz, uap->tzp, sizeof (tz))) {
                u.u_error = EFAULT;
                return;
@@ -32,8 +38,8 @@ gettimeofday()
 settimeofday()
 {
        register struct a {
 settimeofday()
 {
        register struct a {
-               struct timeval *tv;
-               struct timezone *tzp;
+               struct  timeval *tv;
+               struct  timezone *tzp;
        } *uap = (struct a *)u.u_ap;
        struct timeval atv;
        struct timezone atz;
        } *uap = (struct a *)u.u_ap;
        struct timeval atv;
        struct timezone atz;
@@ -42,31 +48,34 @@ settimeofday()
                u.u_error = EFAULT;
                return;
        }
                u.u_error = EFAULT;
                return;
        }
-       if (suser()) {
-               struct timeval tdelta;
-
-               tdelta = atv;
-
-               timevalsub(&tdelta, &time);
-               timevaladd(&boottime, &tdelta);
-               time = atv;
-               clockset();
-       }
-       if (uap->tzp) {
+       setthetime(&atv);
+       if (uap->tzp && suser()) {
                if (copyin((caddr_t)uap->tzp, (caddr_t)&atz, sizeof (atz))) {
                        u.u_error = EFAULT;
                        return;
                }
                if (copyin((caddr_t)uap->tzp, (caddr_t)&atz, sizeof (atz))) {
                        u.u_error = EFAULT;
                        return;
                }
-               /* XXX */
        }
 }
 
        }
 }
 
+setthetime(tv)
+       struct timeval *tv;
+{
+       register int delta;
+       int s;
+
+       if (!suser())
+               return;
+       boottime.tv_sec += tv->tv_sec - time.tv_sec;
+       s = spl7(); time = *tv; splx(s);
+       clockset();
+}
+
 timevaladd(t1, t2)
        struct timeval *t1, *t2;
 {
 
        t1->tv_sec += t2->tv_sec;
 timevaladd(t1, t2)
        struct timeval *t1, *t2;
 {
 
        t1->tv_sec += t2->tv_sec;
-       t1->tv_usec += t2->tv_sec;
+       t1->tv_usec += t2->tv_usec;
        timevalfix(t1);
 }
 
        timevalfix(t1);
 }
 
@@ -75,7 +84,7 @@ timevalsub(t1, t2)
 {
 
        t1->tv_sec -= t2->tv_sec;
 {
 
        t1->tv_sec -= t2->tv_sec;
-       t1->tv_usec -= t2->tv_sec;
+       t1->tv_usec -= t2->tv_usec;
        timevalfix(t1);
 }
 
        timevalfix(t1);
 }
 
@@ -111,11 +120,8 @@ getitimer()
        else
                itp = &u.u_timer[uap->which];
        s = spl7();
        else
                itp = &u.u_timer[uap->which];
        s = spl7();
-       if (copyout((caddr_t)itp, uap->itv, sizeof (struct itimerval))) {
+       if (copyout((caddr_t)itp, uap->itv, sizeof (struct itimerval)))
                u.u_error = EFAULT;
                u.u_error = EFAULT;
-               goto bad;
-       }
-bad:
        splx(s);
 }
 
        splx(s);
 }
 
@@ -123,39 +129,45 @@ setitimer()
 {
        register struct a {
                u_int   which;
 {
        register struct a {
                u_int   which;
-               struct  itimerval *itv;
+               struct  itimerval *itv, *oitv;
        } *uap = (struct a *)u.u_ap;
        struct itimerval aitv;
        int s;
 
        } *uap = (struct a *)u.u_ap;
        struct itimerval aitv;
        int s;
 
-       s = spl7();
        if (uap->which > 2) {
                u.u_error = EINVAL;
        if (uap->which > 2) {
                u.u_error = EINVAL;
-               goto bad;
+               return;
        }
        if (copyin((caddr_t)uap->itv, (caddr_t)&aitv,
            sizeof (struct itimerval))) {
                u.u_error = EFAULT;
        }
        if (copyin((caddr_t)uap->itv, (caddr_t)&aitv,
            sizeof (struct itimerval))) {
                u.u_error = EFAULT;
-               goto bad;
+               return;
+       }
+       if (uap->oitv) {
+               uap->itv = uap->oitv;
+               getitimer();
        }
        }
-       u.u_timer[uap->which] = aitv;
+       if (itimerfix(&aitv.it_value) || itimerfix(&aitv.it_interval)) {
+               u.u_error = EINVAL;
+               return;
+       }
+       s = spl7();
        if (uap->which == ITIMER_REAL)
                u.u_procp->p_realtimer = aitv;
        if (uap->which == ITIMER_REAL)
                u.u_procp->p_realtimer = aitv;
-bad:
+       else
+               u.u_timer[uap->which] = aitv;
        splx(s);
        splx(s);
-       return;
 }
 
 }
 
-getandsetitimer()
+itimerfix(tv)
+       struct timeval *tv;
 {
 {
-       int s = spl7();
 
 
-       getitimer();
-       if (u.u_error == 0) {
-               u.u_ap[1] = u.u_ap[2];
-               setitimer();
-       }
-       splx(s);
+       if (tv->tv_sec < 0 || tv->tv_usec < 0)
+               return (EINVAL);
+       if (tv->tv_sec == 0 && tv->tv_usec < tick)
+               tv->tv_usec = tick;
+       return (0);
 }
 
 itimerdecr(itp, usec)
 }
 
 itimerdecr(itp, usec)
@@ -163,20 +175,28 @@ itimerdecr(itp, usec)
        int usec;
 {
 
        int usec;
 {
 
-       while (itp->itimer_value.tv_usec < usec) {
-               if (itp->itimer_value.tv_sec == 0)
+       if (itp->it_value.tv_usec < usec) {
+               if (itp->it_value.tv_sec == 0) {
+                       usec -= itp->it_value.tv_usec;
                        goto expire;
                        goto expire;
-               itp->itimer_value.tv_usec += 1000000;
-               itp->itimer_value.tv_sec--;
+               }
+               itp->it_value.tv_usec += 1000000;
+               itp->it_value.tv_sec--;
        }
        }
-       itp->itimer_value.tv_usec -= usec;
-       if (timerisset(&itp->itimer_value))
+       itp->it_value.tv_usec -= usec;
+       usec = 0;
+       if (timerisset(&itp->it_value))
                return (1);
 expire:
                return (1);
 expire:
-       if (itp->itimer_reload == 0)
-               itp->itimer_value.tv_usec = 0;
-       else
-               itp->itimer_value = itp->itimer_interval;
+       if (timerisset(&itp->it_interval)) {
+               itp->it_value = itp->it_interval;
+               itp->it_value.tv_usec -= usec;
+               if (itp->it_value.tv_usec < 0) {
+                       itp->it_value.tv_usec += 1000000;
+                       itp->it_value.tv_sec--;
+               }
+       } else
+               itp->it_value.tv_usec = 0;
        return (0);
 }
 
        return (0);
 }
 
@@ -187,6 +207,18 @@ otime()
        u.u_r.r_time = time.tv_sec;
 }
 
        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);
+}
+
 #include "../h/timeb.h"
 
 oftime()
 #include "../h/timeb.h"
 
 oftime()
@@ -206,3 +238,4 @@ oftime()
        if (copyout((caddr_t)&t, (caddr_t)uap->tp, sizeof(t)) < 0)
                u.u_error = EFAULT;
 }
        if (copyout((caddr_t)&t, (caddr_t)uap->tp, sizeof(t)) < 0)
                u.u_error = EFAULT;
 }
+#endif
index 1cfaaca..c0dec1c 100644 (file)
@@ -1,4 +1,4 @@
-/*     sys_generic.c   5.12    82/09/04        */
+/*     sys_generic.c   5.13    82/09/06        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -569,3 +569,13 @@ nullioctl(tp, cmd, data, flags)
 #endif
        return (cmd);
 }
 #endif
        return (cmd);
 }
+
+ostty()
+{
+
+}
+
+ogtty()
+{
+
+}
index c46af7f..a8b64f0 100644 (file)
@@ -1,4 +1,4 @@
-/*     uipc_syscalls.c 4.25    82/09/04        */
+/*     uipc_syscalls.c 4.26    82/09/06        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -47,11 +47,6 @@ socketpair()
 
 }
 
 
 }
 
-spipe()
-{
-
-}
-
 sendto()
 {
 
 sendto()
 {
 
@@ -98,10 +93,7 @@ shutdown()
  */
 
 static struct sockproto localproto = { PF_UNIX, 0 };
  */
 
 static struct sockproto localproto = { PF_UNIX, 0 };
-/*
- * Pipe system call interface.
- */
-opipe()
+pipe()
 {
        register struct file *rf, *wf;
        struct socket *rso, *wso;
 {
        register struct file *rf, *wf;
        struct socket *rso, *wso;