correct no-such-process error
[unix-history] / usr / src / sys / kern / kern_resource.c
index 82c5a85..1f71393 100644 (file)
@@ -1,15 +1,22 @@
-/*     kern_resource.c 4.15    82/10/17        */
+/*
+ * 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_resource.c     6.9 (Berkeley) %G%
+ */
 
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/inode.h"
-#include "../h/proc.h"
-#include "../h/seg.h"
-#include "../h/fs.h"
-#include "../h/uio.h"
-#include "../h/vm.h"
+#include "param.h"
+#include "systm.h"
+#include "dir.h"
+#include "user.h"
+#include "inode.h"
+#include "proc.h"
+#include "seg.h"
+#include "fs.h"
+#include "uio.h"
+#include "vm.h"
+#include "kernel.h"
 
 /*
  * Resource controls and accounting.
 
 /*
  * Resource controls and accounting.
@@ -22,9 +29,8 @@ getpriority()
                int     who;
        } *uap = (struct a *)u.u_ap;
        register struct proc *p;
                int     who;
        } *uap = (struct a *)u.u_ap;
        register struct proc *p;
+       int low = PRIO_MAX + 1;
 
 
-       u.u_r.r_val1 = NZERO+20;
-       u.u_error = ESRCH;
        switch (uap->which) {
 
        case PRIO_PROCESS:
        switch (uap->which) {
 
        case PRIO_PROCESS:
@@ -33,44 +39,39 @@ getpriority()
                else
                        p = pfind(uap->who);
                if (p == 0)
                else
                        p = pfind(uap->who);
                if (p == 0)
-                       return;
-               u.u_r.r_val1 = u.u_procp->p_nice;
-               u.u_error = 0;
+                       break;
+               low = p->p_nice;
                break;
 
        case PRIO_PGRP:
                if (uap->who == 0)
                        uap->who = u.u_procp->p_pgrp;
                break;
 
        case PRIO_PGRP:
                if (uap->who == 0)
                        uap->who = u.u_procp->p_pgrp;
-               for (p = proc; p < procNPROC; p++) {
-                       if (p->p_stat == NULL)
-                               continue;
+               for (p = allproc; p != NULL; p = p->p_nxt) {
                        if (p->p_pgrp == uap->who &&
                        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;
-                       }
+                           p->p_nice < low)
+                               low = p->p_nice;
                }
                break;
 
        case PRIO_USER:
                if (uap->who == 0)
                        uap->who = u.u_uid;
                }
                break;
 
        case PRIO_USER:
                if (uap->who == 0)
                        uap->who = u.u_uid;
-               for (p = proc; p < procNPROC; p++) {
-                       if (p->p_stat == NULL)
-                               continue;
+               for (p = allproc; p != NULL; p = p->p_nxt) {
                        if (p->p_uid == uap->who &&
                        if (p->p_uid == uap->who &&
-                           p->p_nice < u.u_r.r_val1) {
-                               u.u_r.r_val1 = p->p_nice;
-                               u.u_error = 0;
-                       }
+                           p->p_nice < low)
+                               low = p->p_nice;
                }
                break;
 
        default:
                u.u_error = EINVAL;
                }
                break;
 
        default:
                u.u_error = EINVAL;
-               break;
+               return;
        }
        }
-       u.u_r.r_val1 -= NZERO;
+       if (low == PRIO_MAX + 1) {
+               u.u_error = ESRCH;
+               return;
+       }
+       u.u_r.r_val1 = low;
 }
 
 setpriority()
 }
 
 setpriority()
@@ -81,8 +82,8 @@ setpriority()
                int     prio;
        } *uap = (struct a *)u.u_ap;
        register struct proc *p;
                int     prio;
        } *uap = (struct a *)u.u_ap;
        register struct proc *p;
+       int found = 0;
 
 
-       u.u_error = ESRCH;
        switch (uap->which) {
 
        case PRIO_PROCESS:
        switch (uap->which) {
 
        case PRIO_PROCESS:
@@ -91,30 +92,37 @@ setpriority()
                else
                        p = pfind(uap->who);
                if (p == 0)
                else
                        p = pfind(uap->who);
                if (p == 0)
-                       return;
+                       break;
                donice(p, uap->prio);
                donice(p, uap->prio);
+               found++;
                break;
 
        case PRIO_PGRP:
                if (uap->who == 0)
                        uap->who = u.u_procp->p_pgrp;
                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)
+               for (p = allproc; p != NULL; p = p->p_nxt)
+                       if (p->p_pgrp == uap->who) {
                                donice(p, uap->prio);
                                donice(p, uap->prio);
+                               found++;
+                       }
                break;
 
        case PRIO_USER:
                if (uap->who == 0)
                        uap->who = u.u_uid;
                break;
 
        case PRIO_USER:
                if (uap->who == 0)
                        uap->who = u.u_uid;
-               for (p = proc; p < procNPROC; p++)
-                       if (p->p_uid == uap->who)
+               for (p = allproc; p != NULL; p = p->p_nxt)
+                       if (p->p_uid == uap->who) {
                                donice(p, uap->prio);
                                donice(p, uap->prio);
+                               found++;
+                       }
                break;
 
        default:
                u.u_error = EINVAL;
                break;
 
        default:
                u.u_error = EINVAL;
-               break;
+               return;
        }
        }
+       if (found == 0)
+               u.u_error = ESRCH;
 }
 
 donice(p, n)
 }
 
 donice(p, n)
@@ -124,22 +132,19 @@ donice(p, n)
 
        if (u.u_uid && u.u_ruid &&
            u.u_uid != p->p_uid && u.u_ruid != p->p_uid) {
 
        if (u.u_uid && u.u_ruid &&
            u.u_uid != p->p_uid && u.u_ruid != p->p_uid) {
-               u.u_error = EACCES;
+               u.u_error = EPERM;
                return;
        }
                return;
        }
-       n += NZERO;
-       if (n >= 2*NZERO)
-               n = 2*NZERO - 1;
-       if (n < 0)
-               n = 0;
+       if (n > PRIO_MAX)
+               n = PRIO_MAX;
+       if (n < PRIO_MIN)
+               n = PRIO_MIN;
        if (n < p->p_nice && !suser()) {
                u.u_error = EACCES;
                return;
        }
        p->p_nice = n;
        (void) setpri(p);
        if (n < p->p_nice && !suser()) {
                u.u_error = EACCES;
                return;
        }
        p->p_nice = n;
        (void) setpri(p);
-       if (u.u_error == ESRCH)
-               u.u_error = 0;
 }
 
 setrlimit()
 }
 
 setrlimit()
@@ -150,29 +155,34 @@ setrlimit()
        } *uap = (struct a *)u.u_ap;
        struct rlimit alim;
        register struct rlimit *alimp;
        } *uap = (struct a *)u.u_ap;
        struct rlimit alim;
        register struct rlimit *alimp;
+       extern unsigned maxdmap;
 
        if (uap->which >= RLIM_NLIMITS) {
                u.u_error = EINVAL;
                return;
        }
        alimp = &u.u_rlimit[uap->which];
 
        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;
+       u.u_error = copyin((caddr_t)uap->lim, (caddr_t)&alim,
+               sizeof (struct rlimit));
+       if (u.u_error)
                return;
                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 > 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);
+               if (alim.rlim_cur > maxdmap)
+                       alim.rlim_cur = maxdmap;
+               if (alim.rlim_max > maxdmap)
+                       alim.rlim_max = maxdmap;
                break;
 
        case RLIMIT_STACK:
                break;
 
        case RLIMIT_STACK:
-               if (alim.rlim_cur > ctob(MAXSSIZ))
-                       alim.rlim_cur = ctob(MAXSSIZ);
+               if (alim.rlim_cur > maxdmap)
+                       alim.rlim_cur = maxdmap;
+               if (alim.rlim_max > maxdmap)
+                       alim.rlim_max = maxdmap;
                break;
        }
        *alimp = alim;
                break;
        }
        *alimp = alim;
@@ -191,11 +201,8 @@ getrlimit()
                u.u_error = EINVAL;
                return;
        }
                u.u_error = EINVAL;
                return;
        }
-       if (copyout((caddr_t)&u.u_rlimit[uap->which], uap->rlp,
-           sizeof (struct rlimit))) {
-               u.u_error = EFAULT;
-               return;
-       }
+       u.u_error = copyout((caddr_t)&u.u_rlimit[uap->which], (caddr_t)uap->rlp,
+           sizeof (struct rlimit));
 }
 
 getrusage()
 }
 
 getrusage()
@@ -220,16 +227,14 @@ getrusage()
                u.u_error = EINVAL;
                return;
        }
                u.u_error = EINVAL;
                return;
        }
-       if (copyout((caddr_t)rup, uap->rusage, sizeof (struct rusage))) {
-               u.u_error = EFAULT;
-               return;
-       }
+       u.u_error = copyout((caddr_t)rup, (caddr_t)uap->rusage,
+           sizeof (struct rusage));
 }
 
 ruadd(ru, ru2)
        register struct rusage *ru, *ru2;
 {
 }
 
 ruadd(ru, ru2)
        register struct rusage *ru, *ru2;
 {
-       register u_int *ip, *ip2;
+       register long *ip, *ip2;
        register int i;
 
        timevaladd(&ru->ru_utime, &ru2->ru_utime);
        register int i;
 
        timevaladd(&ru->ru_utime, &ru2->ru_utime);
@@ -240,89 +245,3 @@ ruadd(ru, ru2)
        for (i = &ru->ru_last - &ru->ru_first; i > 0; i--)
                *ip++ += *ip2++;
 }
        for (i = &ru->ru_last - &ru->ru_first; i > 0; i--)
                *ip++ += *ip2++;
 }
-
-#ifndef NOCOMPAT
-onice()
-{
-       register struct a {
-               int     niceness;
-       } *uap = (struct a *)u.u_ap;
-       register struct proc *p = u.u_procp;
-
-       donice(p, (p->p_nice-NZERO)+uap->niceness);
-}
-
-#include "../h/times.h"
-
-otimes()
-{
-       register struct a {
-               struct  tms *tmsb;
-       } *uap = (struct a *)u.u_ap;
-       struct tms atms;
-
-       atms.tms_utime = scale60(&u.u_ru.ru_utime);
-       atms.tms_stime = scale60(&u.u_ru.ru_stime);
-       atms.tms_cutime = scale60(&u.u_cru.ru_utime);
-       atms.tms_cstime = scale60(&u.u_cru.ru_stime);
-       if (copyout((caddr_t)&atms, uap->tmsb, sizeof (atms))) {
-               u.u_error = EFAULT;
-               return;
-       }
-}
-
-scale60(tvp)
-       register struct timeval *tvp;
-{
-
-       return (tvp->tv_sec * 60 + tvp->tv_usec / 16667);
-}
-
-#include <vtimes.h>
-
-ovtimes()
-{
-       register struct a {
-               struct  vtimes *par;
-               struct  vtimes *chi;
-       } *uap = (struct a *)u.u_ap;
-       struct vtimes avt;
-
-       if (uap->par) {
-               getvtimes(&u.u_ru, &avt);
-               if (copyout((caddr_t)&avt, (caddr_t)uap->par, sizeof (avt))) {
-                       u.u_error = EFAULT;
-                       return;
-               }
-       }
-       if (uap->chi) {
-               getvtimes(&u.u_cru, &avt);
-               if (copyout((caddr_t)&avt, (caddr_t)uap->chi, sizeof (avt))) {
-                       u.u_error = EFAULT;
-                       return;
-               }
-       }
-}
-
-getvtimes(aru, avt)
-       register struct rusage *aru;
-       register struct vtimes *avt;
-{
-
-       avt->vm_utime = scale60(&aru->ru_utime);
-       avt->vm_stime = scale60(&aru->ru_stime);
-       avt->vm_idsrss = ((aru->ru_idrss+aru->ru_isrss) / hz) * 60;
-       avt->vm_ixrss = aru->ru_ixrss / hz * 60;
-       avt->vm_maxrss = aru->ru_maxrss;
-       avt->vm_majflt = aru->ru_majflt;
-       avt->vm_minflt = aru->ru_minflt;
-       avt->vm_nswap = aru->ru_nswap;
-       avt->vm_inblk = aru->ru_inblock;
-       avt->vm_oublk = aru->ru_oublock;
-}
-
-ovlimit()
-{
-
-       u.u_error = EACCES;
-}