2 * Copyright (c) 1982, 1986, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include "opt_compat.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/sysproto.h>
46 #include <sys/kernel.h>
48 #include <sys/malloc.h>
49 #include <sys/mutex.h>
51 #include <sys/resourcevar.h>
52 #include <sys/sched.h>
54 #include <sys/syscallsubr.h>
55 #include <sys/sysent.h>
59 #include <vm/vm_param.h>
61 #include <vm/vm_map.h>
64 static MALLOC_DEFINE(M_PLIMIT, "plimit", "plimit structures");
65 static MALLOC_DEFINE(M_UIDINFO, "uidinfo", "uidinfo structures");
66 #define UIHASH(uid) (&uihashtbl[(uid) & uihash])
67 static struct mtx uihashtbl_mtx;
68 static LIST_HEAD(uihashhead, uidinfo) *uihashtbl;
69 static u_long uihash; /* size of hash table - 1 */
71 static void calcru1(struct proc *p, struct rusage_ext *ruxp,
72 struct timeval *up, struct timeval *sp);
73 static int donice(struct thread *td, struct proc *chgp, int n);
74 static struct uidinfo *uilookup(uid_t uid);
77 * Resource controls and accounting.
80 #ifndef _SYS_SYSPROTO_H_
81 struct getpriority_args {
92 register struct getpriority_args *uap;
100 switch (uap->which) {
104 low = td->td_proc->p_nice;
109 if (p_cansee(td, p) == 0)
116 sx_slock(&proctree_lock);
118 pg = td->td_proc->p_pgrp;
121 pg = pgfind(uap->who);
123 sx_sunlock(&proctree_lock);
127 sx_sunlock(&proctree_lock);
128 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
130 if (!p_cansee(td, p)) {
141 uap->who = td->td_ucred->cr_uid;
142 sx_slock(&allproc_lock);
143 LIST_FOREACH(p, &allproc, p_list) {
145 if (!p_cansee(td, p) &&
146 p->p_ucred->cr_uid == uap->who) {
152 sx_sunlock(&allproc_lock);
159 if (low == PRIO_MAX + 1 && error == 0)
161 td->td_retval[0] = low;
165 #ifndef _SYS_SYSPROTO_H_
166 struct setpriority_args {
178 struct setpriority_args *uap;
180 struct proc *curp, *p;
182 int found = 0, error = 0;
185 switch (uap->which) {
189 error = donice(td, curp, uap->prio);
195 if (p_cansee(td, p) == 0)
196 error = donice(td, p, uap->prio);
203 sx_slock(&proctree_lock);
208 pg = pgfind(uap->who);
210 sx_sunlock(&proctree_lock);
214 sx_sunlock(&proctree_lock);
215 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
217 if (!p_cansee(td, p)) {
218 error = donice(td, p, uap->prio);
228 uap->who = td->td_ucred->cr_uid;
229 sx_slock(&allproc_lock);
230 FOREACH_PROC_IN_SYSTEM(p) {
232 if (p->p_ucred->cr_uid == uap->who &&
234 error = donice(td, p, uap->prio);
239 sx_sunlock(&allproc_lock);
246 if (found == 0 && error == 0)
252 * Set "nice" for a (whole) process.
255 donice(struct thread *td, struct proc *p, int n)
259 PROC_LOCK_ASSERT(p, MA_OWNED);
260 if ((error = p_cansched(td, p)))
266 if (n < p->p_nice && suser(td) != 0)
268 mtx_lock_spin(&sched_lock);
270 mtx_unlock_spin(&sched_lock);
275 * Set realtime priority.
279 #ifndef _SYS_SYSPROTO_H_
289 struct thread *td; /* curthread */
290 register struct rtprio_args *uap;
298 /* Perform copyin before acquiring locks if needed. */
299 if (uap->function == RTP_SET)
300 cierror = copyin(uap->rtp, &rtp, sizeof(struct rtprio));
314 switch (uap->function) {
316 if ((error = p_cansee(td, p)))
318 mtx_lock_spin(&sched_lock);
320 * Return OUR priority if no pid specified,
321 * or if one is, report the highest priority
322 * in the process. There isn't much more you can do as
323 * there is only room to return a single priority.
324 * XXXKSE: maybe need a new interface to report
325 * priorities of multiple system scope threads.
326 * Note: specifying our own pid is not the same
327 * as leaving it zero.
330 pri_to_rtp(td->td_ksegrp, &rtp);
334 rtp.type = RTP_PRIO_IDLE;
335 rtp.prio = RTP_PRIO_MAX;
336 FOREACH_KSEGRP_IN_PROC(p, kg) {
337 pri_to_rtp(kg, &rtp2);
338 if (rtp2.type < rtp.type ||
339 (rtp2.type == rtp.type &&
340 rtp2.prio < rtp.prio)) {
341 rtp.type = rtp2.type;
342 rtp.prio = rtp2.prio;
346 mtx_unlock_spin(&sched_lock);
348 return (copyout(&rtp, uap->rtp, sizeof(struct rtprio)));
350 if ((error = p_cansched(td, p)) || (error = cierror))
353 /* Disallow setting rtprio in most cases if not superuser. */
354 if (suser(td) != 0) {
355 /* can't set someone else's */
360 /* can't set realtime priority */
362 * Realtime priority has to be restricted for reasons which should be
363 * obvious. However, for idle priority, there is a potential for
364 * system deadlock if an idleprio process gains a lock on a resource
365 * that other processes need (and the idleprio process can't run
366 * due to a CPU-bound normal process). Fix me! XXX
369 if (RTP_PRIO_IS_REALTIME(rtp.type)) {
371 if (rtp.type != RTP_PRIO_NORMAL) {
379 * If we are setting our own priority, set just our
380 * KSEGRP but if we are doing another process,
381 * do all the groups on that process. If we
382 * specify our own pid we do the latter.
384 mtx_lock_spin(&sched_lock);
386 error = rtp_to_pri(&rtp, td->td_ksegrp);
388 FOREACH_KSEGRP_IN_PROC(p, kg) {
389 if ((error = rtp_to_pri(&rtp, kg)) != 0) {
394 mtx_unlock_spin(&sched_lock);
405 rtp_to_pri(struct rtprio *rtp, struct ksegrp *kg)
408 mtx_assert(&sched_lock, MA_OWNED);
409 if (rtp->prio > RTP_PRIO_MAX)
411 switch (RTP_PRIO_BASE(rtp->type)) {
412 case RTP_PRIO_REALTIME:
413 kg->kg_user_pri = PRI_MIN_REALTIME + rtp->prio;
415 case RTP_PRIO_NORMAL:
416 kg->kg_user_pri = PRI_MIN_TIMESHARE + rtp->prio;
419 kg->kg_user_pri = PRI_MIN_IDLE + rtp->prio;
424 sched_class(kg, rtp->type);
425 if (curthread->td_ksegrp == kg) {
426 sched_prio(curthread, kg->kg_user_pri); /* XXX dubious */
432 pri_to_rtp(struct ksegrp *kg, struct rtprio *rtp)
435 mtx_assert(&sched_lock, MA_OWNED);
436 switch (PRI_BASE(kg->kg_pri_class)) {
438 rtp->prio = kg->kg_user_pri - PRI_MIN_REALTIME;
441 rtp->prio = kg->kg_user_pri - PRI_MIN_TIMESHARE;
444 rtp->prio = kg->kg_user_pri - PRI_MIN_IDLE;
449 rtp->type = kg->kg_pri_class;
452 #if defined(COMPAT_43)
453 #ifndef _SYS_SYSPROTO_H_
454 struct osetrlimit_args {
465 register struct osetrlimit_args *uap;
471 if ((error = copyin(uap->rlp, &olim, sizeof(struct orlimit))))
473 lim.rlim_cur = olim.rlim_cur;
474 lim.rlim_max = olim.rlim_max;
475 error = kern_setrlimit(td, uap->which, &lim);
479 #ifndef _SYS_SYSPROTO_H_
480 struct ogetrlimit_args {
491 register struct ogetrlimit_args *uap;
498 if (uap->which >= RLIM_NLIMITS)
502 lim_rlimit(p, uap->which, &rl);
506 * XXX would be more correct to convert only RLIM_INFINITY to the
507 * old RLIM_INFINITY and fail with EOVERFLOW for other larger
508 * values. Most 64->32 and 32->16 conversions, including not
509 * unimportant ones of uids are even more broken than what we
510 * do here (they blindly truncate). We don't do this correctly
511 * here since we have little experience with EOVERFLOW yet.
512 * Elsewhere, getuid() can't fail...
514 olim.rlim_cur = rl.rlim_cur > 0x7fffffff ? 0x7fffffff : rl.rlim_cur;
515 olim.rlim_max = rl.rlim_max > 0x7fffffff ? 0x7fffffff : rl.rlim_max;
516 error = copyout(&olim, uap->rlp, sizeof(olim));
519 #endif /* COMPAT_43 */
521 #ifndef _SYS_SYSPROTO_H_
522 struct __setrlimit_args {
533 register struct __setrlimit_args *uap;
538 if ((error = copyin(uap->rlp, &alim, sizeof(struct rlimit))))
540 error = kern_setrlimit(td, uap->which, &alim);
545 kern_setrlimit(td, which, limp)
550 struct plimit *newlim, *oldlim;
552 register struct rlimit *alimp;
556 if (which >= RLIM_NLIMITS)
560 * Preserve historical bugs by treating negative limits as unsigned.
562 if (limp->rlim_cur < 0)
563 limp->rlim_cur = RLIM_INFINITY;
564 if (limp->rlim_max < 0)
565 limp->rlim_max = RLIM_INFINITY;
569 newlim = lim_alloc();
572 alimp = &oldlim->pl_rlimit[which];
573 if (limp->rlim_cur > alimp->rlim_max ||
574 limp->rlim_max > alimp->rlim_max)
575 if ((error = suser_cred(td->td_ucred, SUSER_ALLOWJAIL))) {
580 if (limp->rlim_cur > limp->rlim_max)
581 limp->rlim_cur = limp->rlim_max;
582 lim_copy(newlim, oldlim);
583 alimp = &newlim->pl_rlimit[which];
588 mtx_lock_spin(&sched_lock);
589 p->p_cpulimit = limp->rlim_cur;
590 mtx_unlock_spin(&sched_lock);
593 if (limp->rlim_cur > maxdsiz)
594 limp->rlim_cur = maxdsiz;
595 if (limp->rlim_max > maxdsiz)
596 limp->rlim_max = maxdsiz;
600 if (limp->rlim_cur > maxssiz)
601 limp->rlim_cur = maxssiz;
602 if (limp->rlim_max > maxssiz)
603 limp->rlim_max = maxssiz;
604 oldssiz = alimp->rlim_cur;
608 if (limp->rlim_cur > maxfilesperproc)
609 limp->rlim_cur = maxfilesperproc;
610 if (limp->rlim_max > maxfilesperproc)
611 limp->rlim_max = maxfilesperproc;
615 if (limp->rlim_cur > maxprocperuid)
616 limp->rlim_cur = maxprocperuid;
617 if (limp->rlim_max > maxprocperuid)
618 limp->rlim_max = maxprocperuid;
619 if (limp->rlim_cur < 1)
621 if (limp->rlim_max < 1)
630 if (which == RLIMIT_STACK) {
632 * Stack is allocated to the max at exec time with only
633 * "rlim_cur" bytes accessible. If stack limit is going
634 * up make more accessible, if going down make inaccessible.
636 if (limp->rlim_cur != oldssiz) {
642 if (limp->rlim_cur > oldssiz) {
643 prot = p->p_sysent->sv_stackprot;
644 size = limp->rlim_cur - oldssiz;
645 addr = p->p_sysent->sv_usrstack -
649 size = oldssiz - limp->rlim_cur;
650 addr = p->p_sysent->sv_usrstack - oldssiz;
652 addr = trunc_page(addr);
653 size = round_page(size);
654 (void)vm_map_protect(&p->p_vmspace->vm_map,
655 addr, addr + size, prot, FALSE);
662 #ifndef _SYS_SYSPROTO_H_
663 struct __getrlimit_args {
675 register struct __getrlimit_args *uap;
681 if (uap->which >= RLIM_NLIMITS)
685 lim_rlimit(p, uap->which, &rlim);
687 error = copyout(&rlim, uap->rlp, sizeof(struct rlimit));
692 * Transform the running time and tick information in proc p into user,
693 * system, and interrupt time usage.
702 struct rusage_ext rux;
706 PROC_LOCK_ASSERT(p, MA_OWNED);
707 mtx_assert(&sched_lock, MA_NOTOWNED);
709 mtx_lock_spin(&sched_lock);
711 FOREACH_THREAD_IN_PROC(p, td) {
712 if (TD_IS_RUNNING(td)) {
714 * Adjust for the current time slice. This is
715 * actually fairly important since the error here is
716 * on the order of a time quantum which is much
717 * greater than the precision of binuptime().
719 KASSERT(td->td_oncpu != NOCPU,
720 ("%s: running thread has no CPU", __func__));
725 bintime_add(&rux.rux_runtime, &bt);
726 bintime_sub(&rux.rux_runtime,
727 &pcpu_find(td->td_oncpu)->pc_switchtime);
730 mtx_unlock_spin(&sched_lock);
731 calcru1(p, &rux, up, sp);
732 p->p_rux.rux_uu = rux.rux_uu;
733 p->p_rux.rux_su = rux.rux_su;
734 p->p_rux.rux_iu = rux.rux_iu;
744 PROC_LOCK_ASSERT(p, MA_OWNED);
745 calcru1(p, &p->p_crux, up, sp);
749 calcru1(p, ruxp, up, sp)
751 struct rusage_ext *ruxp;
756 /* {user, system, interrupt, total} {ticks, usec}; previous tu: */
757 u_int64_t ut, uu, st, su, it, iu, tt, tu, ptu;
759 ut = ruxp->rux_uticks;
760 st = ruxp->rux_sticks;
761 it = ruxp->rux_iticks;
767 bintime2timeval(&ruxp->rux_runtime, &tv);
768 tu = (u_int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
769 ptu = ruxp->rux_uu + ruxp->rux_su + ruxp->rux_iu;
772 "calcru: runtime went backwards from %ju usec to %ju usec for pid %d (%s)\n",
773 (uintmax_t)ptu, (uintmax_t)tu, p->p_pid, p->p_comm);
776 if ((int64_t)tu < 0) {
777 printf("calcru: negative runtime of %jd usec for pid %d (%s)\n",
778 (intmax_t)tu, p->p_pid, p->p_comm);
787 /* Enforce monotonicity. */
788 if (uu < ruxp->rux_uu || su < ruxp->rux_su || iu < ruxp->rux_iu) {
789 if (uu < ruxp->rux_uu)
791 else if (uu + ruxp->rux_su + ruxp->rux_iu > tu)
792 uu = tu - ruxp->rux_su - ruxp->rux_iu;
796 su = ((tu - uu) * st) / (st + it);
797 if (su < ruxp->rux_su)
799 else if (uu + su + ruxp->rux_iu > tu)
800 su = tu - uu - ruxp->rux_iu;
802 KASSERT(uu + su + ruxp->rux_iu <= tu,
803 ("calcru: monotonisation botch 1"));
805 KASSERT(iu >= ruxp->rux_iu,
806 ("calcru: monotonisation botch 2"));
812 up->tv_sec = uu / 1000000;
813 up->tv_usec = uu % 1000000;
814 sp->tv_sec = su / 1000000;
815 sp->tv_usec = su % 1000000;
818 #ifndef _SYS_SYSPROTO_H_
819 struct getrusage_args {
821 struct rusage *rusage;
829 register struct thread *td;
830 register struct getrusage_args *uap;
835 error = kern_getrusage(td, uap->who, &ru);
837 error = copyout(&ru, uap->rusage, sizeof(struct rusage));
842 kern_getrusage(td, who, rup)
854 *rup = p->p_stats->p_ru;
855 calcru(p, &rup->ru_utime, &rup->ru_stime);
858 case RUSAGE_CHILDREN:
859 *rup = p->p_stats->p_cru;
860 calccru(p, &rup->ru_utime, &rup->ru_stime);
872 ruadd(ru, rux, ru2, rux2)
874 struct rusage_ext *rux;
876 struct rusage_ext *rux2;
878 register long *ip, *ip2;
881 bintime_add(&rux->rux_runtime, &rux2->rux_runtime);
882 rux->rux_uticks += rux2->rux_uticks;
883 rux->rux_sticks += rux2->rux_sticks;
884 rux->rux_iticks += rux2->rux_iticks;
885 rux->rux_uu += rux2->rux_uu;
886 rux->rux_su += rux2->rux_su;
887 rux->rux_iu += rux2->rux_iu;
888 if (ru->ru_maxrss < ru2->ru_maxrss)
889 ru->ru_maxrss = ru2->ru_maxrss;
891 ip2 = &ru2->ru_first;
892 for (i = &ru->ru_last - &ru->ru_first; i >= 0; i--)
897 * Allocate a new resource limits structure and initialize its
898 * reference count and mutex pointer.
905 limp = malloc(sizeof(struct plimit), M_PLIMIT, M_WAITOK);
907 limp->pl_mtx = mtx_pool_alloc(mtxpool_sleep);
928 KASSERT(limp->pl_refcnt > 0, ("plimit refcnt underflow"));
929 if (--limp->pl_refcnt == 0) {
931 free((void *)limp, M_PLIMIT);
938 * Make a copy of the plimit structure.
939 * We share these structures copy-on-write after fork.
943 struct plimit *dst, *src;
946 KASSERT(dst->pl_refcnt == 1, ("lim_copy to shared limit"));
947 bcopy(src->pl_rlimit, dst->pl_rlimit, sizeof(src->pl_rlimit));
951 * Return the hard limit for a particular system resource. The
952 * which parameter specifies the index into the rlimit array.
955 lim_max(struct proc *p, int which)
959 lim_rlimit(p, which, &rl);
960 return (rl.rlim_max);
964 * Return the current (soft) limit for a particular system resource.
965 * The which parameter which specifies the index into the rlimit array
968 lim_cur(struct proc *p, int which)
972 lim_rlimit(p, which, &rl);
973 return (rl.rlim_cur);
977 * Return a copy of the entire rlimit structure for the system limit
978 * specified by 'which' in the rlimit structure pointed to by 'rlp'.
981 lim_rlimit(struct proc *p, int which, struct rlimit *rlp)
984 PROC_LOCK_ASSERT(p, MA_OWNED);
985 KASSERT(which >= 0 && which < RLIM_NLIMITS,
986 ("request for invalid resource limit"));
987 *rlp = p->p_limit->pl_rlimit[which];
991 * Find the uidinfo structure for a uid. This structure is used to
992 * track the total resource consumption (process count, socket buffer
993 * size, etc.) for the uid and impose limits.
999 uihashtbl = hashinit(maxproc / 16, M_UIDINFO, &uihash);
1000 mtx_init(&uihashtbl_mtx, "uidinfo hash", NULL, MTX_DEF);
1004 * Look up a uidinfo struct for the parameter uid.
1005 * uihashtbl_mtx must be locked.
1007 static struct uidinfo *
1011 struct uihashhead *uipp;
1012 struct uidinfo *uip;
1014 mtx_assert(&uihashtbl_mtx, MA_OWNED);
1016 LIST_FOREACH(uip, uipp, ui_hash)
1017 if (uip->ui_uid == uid)
1024 * Find or allocate a struct uidinfo for a particular uid.
1025 * Increase refcount on uidinfo struct returned.
1026 * uifree() should be called on a struct uidinfo when released.
1032 struct uidinfo *old_uip, *uip;
1034 mtx_lock(&uihashtbl_mtx);
1035 uip = uilookup(uid);
1037 mtx_unlock(&uihashtbl_mtx);
1038 uip = malloc(sizeof(*uip), M_UIDINFO, M_WAITOK | M_ZERO);
1039 mtx_lock(&uihashtbl_mtx);
1041 * There's a chance someone created our uidinfo while we
1042 * were in malloc and not holding the lock, so we have to
1043 * make sure we don't insert a duplicate uidinfo.
1045 if ((old_uip = uilookup(uid)) != NULL) {
1046 /* Someone else beat us to it. */
1047 free(uip, M_UIDINFO);
1050 uip->ui_mtxp = mtx_pool_alloc(mtxpool_sleep);
1052 LIST_INSERT_HEAD(UIHASH(uid), uip, ui_hash);
1056 mtx_unlock(&uihashtbl_mtx);
1061 * Place another refcount on a uidinfo struct.
1065 struct uidinfo *uip;
1070 UIDINFO_UNLOCK(uip);
1074 * Since uidinfo structs have a long lifetime, we use an
1075 * opportunistic refcounting scheme to avoid locking the lookup hash
1078 * If the refcount hits 0, we need to free the structure,
1079 * which means we need to lock the hash.
1081 * After locking the struct and lowering the refcount, if we find
1082 * that we don't need to free, simply unlock and return.
1084 * If refcount lowering results in need to free, bump the count
1085 * back up, loose the lock and aquire the locks in the proper
1086 * order to try again.
1090 struct uidinfo *uip;
1093 /* Prepare for optimal case. */
1096 if (--uip->ui_ref != 0) {
1097 UIDINFO_UNLOCK(uip);
1101 /* Prepare for suboptimal case. */
1103 UIDINFO_UNLOCK(uip);
1104 mtx_lock(&uihashtbl_mtx);
1108 * We must subtract one from the count again because we backed out
1109 * our initial subtraction before dropping the lock.
1110 * Since another thread may have added a reference after we dropped the
1111 * initial lock we have to test for zero again.
1113 if (--uip->ui_ref == 0) {
1114 LIST_REMOVE(uip, ui_hash);
1115 mtx_unlock(&uihashtbl_mtx);
1116 if (uip->ui_sbsize != 0)
1117 printf("freeing uidinfo: uid = %d, sbsize = %jd\n",
1118 uip->ui_uid, (intmax_t)uip->ui_sbsize);
1119 if (uip->ui_proccnt != 0)
1120 printf("freeing uidinfo: uid = %d, proccnt = %ld\n",
1121 uip->ui_uid, uip->ui_proccnt);
1122 UIDINFO_UNLOCK(uip);
1123 FREE(uip, M_UIDINFO);
1127 mtx_unlock(&uihashtbl_mtx);
1128 UIDINFO_UNLOCK(uip);
1132 * Change the count associated with number of processes
1133 * a given user is using. When 'max' is 0, don't enforce a limit
1136 chgproccnt(uip, diff, max)
1137 struct uidinfo *uip;
1143 /* Don't allow them to exceed max, but allow subtraction. */
1144 if (diff > 0 && uip->ui_proccnt + diff > max && max != 0) {
1145 UIDINFO_UNLOCK(uip);
1148 uip->ui_proccnt += diff;
1149 if (uip->ui_proccnt < 0)
1150 printf("negative proccnt for uid = %d\n", uip->ui_uid);
1151 UIDINFO_UNLOCK(uip);
1156 * Change the total socket buffer size a user has used.
1159 chgsbsize(uip, hiwat, to, max)
1160 struct uidinfo *uip;
1168 new = uip->ui_sbsize + to - *hiwat;
1169 /* Don't allow them to exceed max, but allow subtraction. */
1170 if (to > *hiwat && new > max) {
1171 UIDINFO_UNLOCK(uip);
1174 uip->ui_sbsize = new;
1175 UIDINFO_UNLOCK(uip);
1178 printf("negative sbsize for uid = %d\n", uip->ui_uid);