compilable 4.2 calls, not tested
authorBill Joy <root@ucbvax.Berkeley.EDU>
Sun, 5 Sep 1982 00:11:33 +0000 (16:11 -0800)
committerBill Joy <root@ucbvax.Berkeley.EDU>
Sun, 5 Sep 1982 00:11:33 +0000 (16:11 -0800)
SCCS-vsn: sys/kern/kern_resource.c 4.12

usr/src/sys/kern/kern_resource.c

index 8642e85..b488947 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_resource.c 4.11    82/08/22        */
+/*     kern_resource.c 4.12    82/09/04        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/seg.h"
 #include "../h/fs.h"
 #include "../h/uio.h"
 #include "../h/seg.h"
 #include "../h/fs.h"
 #include "../h/uio.h"
+#include "../h/vm.h"
+
+getpriority()
+{
+       register struct a {
+               int     which;
+               int     who;
+       } *uap = (struct a *)u.u_ap;
+       register struct proc *p;
+
+       u.u_r.r_val1 = NZERO+20;
+       u.u_error = ESRCH;
+       switch (uap->which) {
+
+       case PRIO_PROCESS:
+               if (uap->who == 0)
+                       p = u.u_procp;
+               else
+                       p = pfind(uap->who);
+               if (p == 0)
+                       return;
+               u.u_r.r_val1 = u.u_procp->p_nice;
+               break;
+
+       case PRIO_PGRP:
+               if (uap->who == 0)
+                       uap->who = u.u_procp->p_pgrp;
+               for (p = proc; p < procNPROC; p++)
+                       if (p->p_pgrp == uap->who &&
+                           p->p_nice < u.u_r.r_val1) {
+                               u.u_r.r_val1 = p->p_nice;
+                               u.u_error = 0;
+                       }
+               break;
+
+       default:
+               u.u_error = EINVAL;
+               break;
+       }
+       u.u_r.r_val1 -= NZERO;
+}
+
+setpriority()
+{
+       register struct a {
+               int     which;
+               int     who;
+               int     prio;
+       } *uap = (struct a *)u.u_ap;
+       register struct proc *p;
+
+       u.u_error = ESRCH;
+       switch (uap->which) {
+
+       case PRIO_PROCESS:
+               p = pfind(uap->who);
+               if (p == 0)
+                       return;
+               donice(p, uap->prio);
+               break;
+
+       case PRIO_PGRP:
+               for (p = proc; p < procNPROC; p++)
+                       if (p->p_pgrp == uap->who)
+                               donice(p, uap->prio);
+               break;
+
+       default:
+               u.u_error = EINVAL;
+               break;
+       }
+}
+
+donice(p, n)
+       register struct proc *p;
+       register int n;
+{
+
+       if (u.u_uid && u.u_ruid &&
+           u.u_uid != p->p_uid && u.u_ruid != p->p_uid) {
+               u.u_error = EPERM;
+               return;
+       }
+       n += p->p_nice;
+       if (n >= 2*NZERO)
+               n = 2*NZERO - 1;
+       if (n < 0)
+               n = 0;
+       if (n < p->p_nice && !suser())
+               return;
+       p->p_nice = n;
+       (void) setpri(p);
+       if (u.u_error == ESRCH)
+               u.u_error = 0;
+}
+
+setlimit()
+{
+       register struct a {
+               u_int   which;
+               struct  rlimit *lim;
+       } *uap = (struct a *)u.u_ap;
+       struct rlimit alim;
+       register struct rlimit *alimp;
+
+       if (uap->which >= RLIM_NLIMITS) {
+               u.u_error = EINVAL;
+               return;
+       }
+       alimp = &u.u_rlimit[uap->which];
+       if (copyin((caddr_t)uap->lim, (caddr_t)&alim, sizeof (struct rlimit))) {
+               u.u_error = EFAULT;
+               return;
+       }
+       if (alim.rlim_cur > alimp->rlim_max || alim.rlim_max > alimp->rlim_max)
+               if (!suser())
+                       return;
+       switch (uap->which) {
+
+       case RLIMIT_DATA:
+               if (alim.rlim_cur > ctob(MAXDSIZ))
+                       alim.rlim_cur = ctob(MAXDSIZ);
+               break;
+
+       case RLIMIT_STACK:
+               if (alim.rlim_cur > ctob(MAXSSIZ))
+                       alim.rlim_cur = ctob(MAXSSIZ);
+               break;
+       }
+       *alimp = alim;
+       if (uap->which == RLIMIT_RSS)
+               u.u_procp->p_maxrss = alim.rlim_cur/NBPG;
+}
+
+getlimit()
+{
+       register struct a {
+               u_int   which;
+               struct  rlimit *rlp;
+       } *uap = (struct a *)u.u_ap;
+
+       if (uap->which >= RLIM_NLIMITS) {
+               u.u_error = EINVAL;
+               return;
+       }
+       if (copyout((caddr_t)&u.u_rlimit[uap->which], uap->rlp,
+           sizeof (struct rlimit))) {
+               u.u_error = EFAULT;
+               return;
+       }
+}
+
+getrusage()
+{
+       register struct a {
+               int     who;
+               struct  rusage *rusage;
+       } *uap = (struct a *)u.u_ap;
+       register struct rusage *rup;
+
+       switch (uap->who) {
+
+       case RUSAGE_SELF:
+               rup = &u.u_ru;
+               break;
+
+       case RUSAGE_CHILDREN:
+               rup = &u.u_cru;
+               break;
+
+       default:
+               u.u_error = EINVAL;
+               return;
+       }
+       if (copyout((caddr_t)rup, uap->rusage, sizeof (struct rusage))) {
+               u.u_error = EFAULT;
+               return;
+       }
+}
+
+ruadd(ru, ru2)
+       register struct rusage *ru, *ru2;
+{
+       register int *ip, *ip2;
+       register int i;
+
+       timevaladd(&ru->ru_utime, &ru2->ru_utime);
+       timevaladd(&ru->ru_stime, &ru2->ru_stime);
+       if (ru->ru_maxrss < ru2->ru_maxrss)
+               ru->ru_maxrss = ru2->ru_maxrss;
+       ip = &ru->ru_first; ip2 = &ru2->ru_first;
+       for (i = &ru->ru_last - &ru->ru_first; i > 0; i--)
+               *ip++ += *ip2++;
+}
 
 struct inode *acctp;
 struct inode *savacctp;
 
 struct inode *acctp;
 struct inode *savacctp;
@@ -85,16 +279,17 @@ acct()
        ilock(ip);
        for (i=0; i<sizeof(ap->ac_comm); i++)
                ap->ac_comm[i] = u.u_comm[i];
        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_vm.vm_utime);
-       ap->ac_stime = compress((long)u.u_vm.vm_stime);
+       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;
        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_vm.vm_utime + u.u_vm.vm_stime)
-               ap->ac_mem = (u.u_vm.vm_ixrss + u.u_vm.vm_idsrss) / i;
-       ap->ac_io = compress((long)(u.u_vm.vm_inblk + u.u_vm.vm_oublk));
+       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
        if (u.u_ttyp)
                ap->ac_tty = u.u_ttyd;
        else
@@ -133,39 +328,14 @@ register long t;
        return((exp<<13) + t);
 }
 
        return((exp<<13) + t);
 }
 
-vtimes()
+#ifndef NOCOMPAT
+onice()
 {
        register struct a {
 {
        register struct a {
-               struct  vtimes *par_vm;
-               struct  vtimes *ch_vm;
-       } *uap = (struct a *)u.u_ap;
-
-       if (uap->par_vm == 0)
-               goto onlych;
-       if (copyout((caddr_t)&u.u_vm, (caddr_t)uap->par_vm,
-           sizeof(struct vtimes)) < 0)
-               u.u_error = EFAULT;
-onlych:
-       if (uap->ch_vm == 0)
-               return;
-       if (copyout((caddr_t)&u.u_cvm, (caddr_t)uap->ch_vm,
-           sizeof(struct vtimes)) < 0)
-               u.u_error = EFAULT;
-}
-
-vmsadd(vp, wp)
-       register struct vtimes *vp, *wp;
-{
+               int     niceness;
+       } *uap;
 
 
-       vp->vm_utime += wp->vm_utime;
-       vp->vm_stime += wp->vm_stime;
-       vp->vm_nswap += wp->vm_nswap;
-       vp->vm_idsrss += wp->vm_idsrss;
-       vp->vm_ixrss += wp->vm_ixrss;
-       if (vp->vm_maxrss < wp->vm_maxrss)
-               vp->vm_maxrss = wp->vm_maxrss;
-       vp->vm_majflt += wp->vm_majflt;
-       vp->vm_minflt += wp->vm_minflt;
-       vp->vm_inblk += wp->vm_inblk;
-       vp->vm_oublk += wp->vm_oublk;
+       uap = (struct a *)u.u_ap;
+       donice(u.u_procp, uap->niceness);
 }
 }
+#endif