kern_resource.c (94861) | kern_resource.c (96886) |
---|---|
1/*- 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. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94 | 1/*- 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. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94 |
39 * $FreeBSD: head/sys/kern/kern_resource.c 94861 2002-04-16 17:11:34Z jhb $ | 39 * $FreeBSD: head/sys/kern/kern_resource.c 96886 2002-05-19 00:14:50Z jhb $ |
40 */ 41 42#include "opt_compat.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/sysproto.h> 47#include <sys/file.h> --- 48 unchanged lines hidden (view full) --- 96 switch (uap->which) { 97 case PRIO_PROCESS: 98 if (uap->who == 0) 99 low = td->td_ksegrp->kg_nice; 100 else { 101 p = pfind(uap->who); 102 if (p == NULL) 103 break; | 40 */ 41 42#include "opt_compat.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/sysproto.h> 47#include <sys/file.h> --- 48 unchanged lines hidden (view full) --- 96 switch (uap->which) { 97 case PRIO_PROCESS: 98 if (uap->who == 0) 99 low = td->td_ksegrp->kg_nice; 100 else { 101 p = pfind(uap->who); 102 if (p == NULL) 103 break; |
104 if (p_cansee(td->td_proc, p) == 0) | 104 if (p_cansee(td, p) == 0) |
105 low = p->p_ksegrp.kg_nice /* XXXKSE */ ; 106 PROC_UNLOCK(p); 107 } 108 break; 109 110 case PRIO_PGRP: { 111 register struct pgrp *pg; 112 --- 6 unchanged lines hidden (view full) --- 119 if (pg == NULL) { 120 sx_sunlock(&proctree_lock); 121 break; 122 } 123 } 124 sx_sunlock(&proctree_lock); 125 LIST_FOREACH(p, &pg->pg_members, p_pglist) { 126 PROC_LOCK(p); | 105 low = p->p_ksegrp.kg_nice /* XXXKSE */ ; 106 PROC_UNLOCK(p); 107 } 108 break; 109 110 case PRIO_PGRP: { 111 register struct pgrp *pg; 112 --- 6 unchanged lines hidden (view full) --- 119 if (pg == NULL) { 120 sx_sunlock(&proctree_lock); 121 break; 122 } 123 } 124 sx_sunlock(&proctree_lock); 125 LIST_FOREACH(p, &pg->pg_members, p_pglist) { 126 PROC_LOCK(p); |
127 if (!p_cansee(td->td_proc, p) && p->p_ksegrp.kg_nice /* XXXKSE */ < low) | 127 if (!p_cansee(td, p) && p->p_ksegrp.kg_nice /* XXXKSE */ < low) |
128 low = p->p_ksegrp.kg_nice /* XXXKSE */ ; 129 PROC_UNLOCK(p); 130 } 131 PGRP_UNLOCK(pg); 132 break; 133 } 134 135 case PRIO_USER: 136 if (uap->who == 0) 137 uap->who = td->td_ucred->cr_uid; 138 sx_slock(&allproc_lock); 139 LIST_FOREACH(p, &allproc, p_list) { 140 PROC_LOCK(p); | 128 low = p->p_ksegrp.kg_nice /* XXXKSE */ ; 129 PROC_UNLOCK(p); 130 } 131 PGRP_UNLOCK(pg); 132 break; 133 } 134 135 case PRIO_USER: 136 if (uap->who == 0) 137 uap->who = td->td_ucred->cr_uid; 138 sx_slock(&allproc_lock); 139 LIST_FOREACH(p, &allproc, p_list) { 140 PROC_LOCK(p); |
141 if (!p_cansee(td->td_proc, p) && | 141 if (!p_cansee(td, p) && |
142 p->p_ucred->cr_uid == uap->who && 143 p->p_ksegrp.kg_nice /* XXXKSE */ < low) 144 low = p->p_ksegrp.kg_nice /* XXXKSE */ ; 145 PROC_UNLOCK(p); 146 } 147 sx_sunlock(&allproc_lock); 148 break; 149 --- 35 unchanged lines hidden (view full) --- 185 if (uap->who == 0) { 186 PROC_LOCK(curp); 187 error = donice(td, curp, uap->prio); 188 PROC_UNLOCK(curp); 189 } else { 190 p = pfind(uap->who); 191 if (p == 0) 192 break; | 142 p->p_ucred->cr_uid == uap->who && 143 p->p_ksegrp.kg_nice /* XXXKSE */ < low) 144 low = p->p_ksegrp.kg_nice /* XXXKSE */ ; 145 PROC_UNLOCK(p); 146 } 147 sx_sunlock(&allproc_lock); 148 break; 149 --- 35 unchanged lines hidden (view full) --- 185 if (uap->who == 0) { 186 PROC_LOCK(curp); 187 error = donice(td, curp, uap->prio); 188 PROC_UNLOCK(curp); 189 } else { 190 p = pfind(uap->who); 191 if (p == 0) 192 break; |
193 if (p_cansee(td->td_proc, p) == 0) | 193 if (p_cansee(td, p) == 0) |
194 error = donice(td, p, uap->prio); 195 PROC_UNLOCK(p); 196 } 197 found++; 198 break; 199 200 case PRIO_PGRP: { 201 register struct pgrp *pg; --- 7 unchanged lines hidden (view full) --- 209 if (pg == NULL) { 210 sx_sunlock(&proctree_lock); 211 break; 212 } 213 } 214 sx_sunlock(&proctree_lock); 215 LIST_FOREACH(p, &pg->pg_members, p_pglist) { 216 PROC_LOCK(p); | 194 error = donice(td, p, uap->prio); 195 PROC_UNLOCK(p); 196 } 197 found++; 198 break; 199 200 case PRIO_PGRP: { 201 register struct pgrp *pg; --- 7 unchanged lines hidden (view full) --- 209 if (pg == NULL) { 210 sx_sunlock(&proctree_lock); 211 break; 212 } 213 } 214 sx_sunlock(&proctree_lock); 215 LIST_FOREACH(p, &pg->pg_members, p_pglist) { 216 PROC_LOCK(p); |
217 if (!p_cansee(td->td_proc, p)) { | 217 if (!p_cansee(td, p)) { |
218 error = donice(td, p, uap->prio); 219 found++; 220 } 221 PROC_UNLOCK(p); 222 } 223 PGRP_UNLOCK(pg); 224 break; 225 } 226 227 case PRIO_USER: 228 if (uap->who == 0) 229 uap->who = td->td_ucred->cr_uid; 230 sx_slock(&allproc_lock); 231 FOREACH_PROC_IN_SYSTEM(p) { 232 PROC_LOCK(p); 233 if (p->p_ucred->cr_uid == uap->who && | 218 error = donice(td, p, uap->prio); 219 found++; 220 } 221 PROC_UNLOCK(p); 222 } 223 PGRP_UNLOCK(pg); 224 break; 225 } 226 227 case PRIO_USER: 228 if (uap->who == 0) 229 uap->who = td->td_ucred->cr_uid; 230 sx_slock(&allproc_lock); 231 FOREACH_PROC_IN_SYSTEM(p) { 232 PROC_LOCK(p); 233 if (p->p_ucred->cr_uid == uap->who && |
234 !p_cansee(td->td_proc, p)) { | 234 !p_cansee(td, p)) { |
235 error = donice(td, p, uap->prio); 236 found++; 237 } 238 PROC_UNLOCK(p); 239 } 240 sx_sunlock(&allproc_lock); 241 break; 242 --- 11 unchanged lines hidden (view full) --- 254donice(td, chgp, n) 255 struct thread *td; 256 register struct proc *chgp; 257 register int n; 258{ 259 int error; 260 261 PROC_LOCK_ASSERT(chgp, MA_OWNED); | 235 error = donice(td, p, uap->prio); 236 found++; 237 } 238 PROC_UNLOCK(p); 239 } 240 sx_sunlock(&allproc_lock); 241 break; 242 --- 11 unchanged lines hidden (view full) --- 254donice(td, chgp, n) 255 struct thread *td; 256 register struct proc *chgp; 257 register int n; 258{ 259 int error; 260 261 PROC_LOCK_ASSERT(chgp, MA_OWNED); |
262 if ((error = p_cansched(td->td_proc, chgp))) | 262 if ((error = p_cansched(td, chgp))) |
263 return (error); 264 if (n > PRIO_MAX) 265 n = PRIO_MAX; 266 if (n < PRIO_MIN) 267 n = PRIO_MIN; 268 if (n < chgp->p_ksegrp.kg_nice /* XXXKSE */ && suser(td)) 269 return (EACCES); 270 chgp->p_ksegrp.kg_nice /* XXXKSE */ = n; --- 38 unchanged lines hidden (view full) --- 309 } else { 310 p = pfind(uap->pid); 311 if (p == NULL) 312 return (ESRCH); 313 } 314 315 switch (uap->function) { 316 case RTP_LOOKUP: | 263 return (error); 264 if (n > PRIO_MAX) 265 n = PRIO_MAX; 266 if (n < PRIO_MIN) 267 n = PRIO_MIN; 268 if (n < chgp->p_ksegrp.kg_nice /* XXXKSE */ && suser(td)) 269 return (EACCES); 270 chgp->p_ksegrp.kg_nice /* XXXKSE */ = n; --- 38 unchanged lines hidden (view full) --- 309 } else { 310 p = pfind(uap->pid); 311 if (p == NULL) 312 return (ESRCH); 313 } 314 315 switch (uap->function) { 316 case RTP_LOOKUP: |
317 if ((error = p_cansee(td->td_proc, p))) | 317 if ((error = p_cansee(td, p))) |
318 break; 319 mtx_lock_spin(&sched_lock); 320 pri_to_rtp(&p->p_ksegrp /* XXXKSE */ , &rtp); 321 mtx_unlock_spin(&sched_lock); 322 PROC_UNLOCK(p); 323 return (copyout(&rtp, uap->rtp, sizeof(struct rtprio))); 324 case RTP_SET: | 318 break; 319 mtx_lock_spin(&sched_lock); 320 pri_to_rtp(&p->p_ksegrp /* XXXKSE */ , &rtp); 321 mtx_unlock_spin(&sched_lock); 322 PROC_UNLOCK(p); 323 return (copyout(&rtp, uap->rtp, sizeof(struct rtprio))); 324 case RTP_SET: |
325 if ((error = p_cansched(td->td_proc, p)) || (error = cierror)) | 325 if ((error = p_cansched(td, p)) || (error = cierror)) |
326 break; 327 /* disallow setting rtprio in most cases if not superuser */ 328 if (suser(td) != 0) { 329 /* can't set someone else's */ 330 if (uap->pid) { 331 error = EPERM; 332 break; 333 } --- 687 unchanged lines hidden --- | 326 break; 327 /* disallow setting rtprio in most cases if not superuser */ 328 if (suser(td) != 0) { 329 /* can't set someone else's */ 330 if (uap->pid) { 331 error = EPERM; 332 break; 333 } --- 687 unchanged lines hidden --- |