* Copyright (c) 1982, 1986, 1991 The Regents of the University of California.
* %sccs.include.redist.c%
* @(#)kern_resource.c 7.13 (Berkeley) %G%
* Resource controls and accounting.
getpriority(curp
, uap
, retval
)
register int low
= PRIO_MAX
+ 1;
register struct pgrp
*pg
;
else if ((pg
= pgfind(uap
->who
)) == NULL
)
for (p
= pg
->pg_mem
; p
!= NULL
; p
= p
->p_pgrpnxt
) {
uap
->who
= curp
->p_ucred
->cr_uid
;
for (p
= allproc
; p
!= NULL
; p
= p
->p_nxt
) {
if (p
->p_ucred
->cr_uid
== uap
->who
&&
setpriority(curp
, uap
, retval
)
int found
= 0, error
= 0;
error
= donice(curp
, p
, uap
->prio
);
register struct pgrp
*pg
;
else if ((pg
= pgfind(uap
->who
)) == NULL
)
for (p
= pg
->pg_mem
; p
!= NULL
; p
= p
->p_pgrpnxt
) {
error
= donice(curp
, p
, uap
->prio
);
uap
->who
= curp
->p_ucred
->cr_uid
;
for (p
= allproc
; p
!= NULL
; p
= p
->p_nxt
)
if (p
->p_ucred
->cr_uid
== uap
->who
) {
error
= donice(curp
, p
, uap
->prio
);
register struct proc
*curp
, *chgp
;
register struct pcred
*pcred
= curp
->p_cred
;
if (pcred
->pc_ucred
->cr_uid
&& pcred
->p_ruid
&&
pcred
->pc_ucred
->cr_uid
!= chgp
->p_ucred
->cr_uid
&&
pcred
->p_ruid
!= chgp
->p_ucred
->cr_uid
)
if (n
< chgp
->p_nice
&& suser(pcred
->pc_ucred
, &curp
->p_acflag
))
setrlimit(p
, uap
, retval
)
register struct rlimit
*alimp
;
if (uap
->which
>= RLIM_NLIMITS
)
alimp
= &p
->p_rlimit
[uap
->which
];
copyin((caddr_t
)uap
->lim
, (caddr_t
)&alim
, sizeof (struct rlimit
)))
if (alim
.rlim_cur
> alimp
->rlim_max
|| alim
.rlim_max
> alimp
->rlim_max
)
if (error
= suser(p
->p_ucred
, &p
->p_acflag
))
if (p
->p_limit
->p_refcnt
> 1 &&
(p
->p_limit
->p_lflags
& PL_SHAREMOD
) == 0) {
p
->p_limit
= limcopy(p
->p_limit
);
if (alim
.rlim_cur
> maxdmap
)
if (alim
.rlim_max
> maxdmap
)
if (alim
.rlim_cur
> maxdmap
)
if (alim
.rlim_max
> maxdmap
)
* Stack is allocated to the max at exec time with only
* "rlim_cur" bytes accessible. If stack limit is going
* up make more accessible, if going down make inaccessible.
if (alim
.rlim_cur
!= alimp
->rlim_cur
) {
if (alim
.rlim_cur
> alimp
->rlim_cur
) {
size
= alim
.rlim_cur
- alimp
->rlim_cur
;
addr
= USRSTACK
- alim
.rlim_cur
;
size
= alimp
->rlim_cur
- alim
.rlim_cur
;
addr
= USRSTACK
- alimp
->rlim_cur
;
(void) vm_map_protect(&p
->p_vmspace
->vm_map
,
addr
, addr
+size
, prot
, FALSE
);
p
->p_rlimit
[uap
->which
] = alim
;
getrlimit(p
, uap
, retval
)
if (uap
->which
>= RLIM_NLIMITS
)
return (copyout((caddr_t
)&p
->p_rlimit
[uap
->which
], (caddr_t
)uap
->rlp
,
sizeof (struct rlimit
)));
getrusage(p
, uap
, retval
)
register struct rusage
*rup
;
rup
->ru_stime
= p
->p_stime
;
rup
->ru_utime
= p
->p_utime
;
rup
= &p
->p_stats
->p_cru
;
return (copyout((caddr_t
)rup
, (caddr_t
)uap
->rusage
,
sizeof (struct rusage
)));
register struct rusage
*ru
, *ru2
;
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
--)
* Make a copy of the plimit structure.
* We share these structures copy-on-write after fork,
* and copy when a limit is changed.
register struct plimit
*copy
;
MALLOC(copy
, struct plimit
*, sizeof(struct plimit
),
bcopy(lim
->pl_rlimit
, copy
->pl_rlimit
,
sizeof(struct rlimit
) * RLIM_NLIMITS
);