Deleted Added
full compact
kern_resource.c (3098) kern_resource.c (3291)
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 * $Id: kern_resource.c,v 1.4 1994/09/01 05:12:40 davidg Exp $
39 * $Id: kern_resource.c,v 1.5 1994/09/25 19:33:42 phk Exp $
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/kernel.h>
45#include <sys/file.h>
46#include <sys/resourcevar.h>
47#include <sys/malloc.h>

--- 142 unchanged lines hidden (view full) ---

190 return (EACCES);
191 chgp->p_nice = n;
192 (void)resetpriority(chgp);
193 return (0);
194}
195
196/* rtprio system call */
197struct rtprio_args {
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/kernel.h>
45#include <sys/file.h>
46#include <sys/resourcevar.h>
47#include <sys/malloc.h>

--- 142 unchanged lines hidden (view full) ---

190 return (EACCES);
191 chgp->p_nice = n;
192 (void)resetpriority(chgp);
193 return (0);
194}
195
196/* rtprio system call */
197struct rtprio_args {
198 int who;
199 pid_t rtprio;
198 int function;
199 pid_t pid;
200 struct rtprio *rtprio;
200};
201
202/*
203 * Set realtime priority
204 */
205
206/* ARGSUSED */
207int
208rtprio(curp, uap, retval)
209 struct proc *curp;
210 register struct rtprio_args *uap;
211 int *retval;
212{
213 register struct proc *p;
201};
202
203/*
204 * Set realtime priority
205 */
206
207/* ARGSUSED */
208int
209rtprio(curp, uap, retval)
210 struct proc *curp;
211 register struct rtprio_args *uap;
212 int *retval;
213{
214 register struct proc *p;
214 register int n = uap->rtprio;
215 register struct pcred *pcred = curp->p_cred;
215 register struct pcred *pcred = curp->p_cred;
216 struct rtprio rtp;
217 int error;
216
218
217 if (uap->who == 0)
219 error = copyin(uap->rtprio, &rtp, sizeof(struct rtprio));
220 if (error)
221 return (error);
222
223 if (uap->pid == 0)
218 p = curp;
219 else
224 p = curp;
225 else
220 p = pfind(uap->who);
226 p = pfind(uap->pid);
221
222 if (p == 0)
223 return (ESRCH);
224
227
228 if (p == 0)
229 return (ESRCH);
230
225 if (n == RTPRIO_NOCHG) {
226 *retval = (int)p->p_rtprio;
227 return(0); }
231 switch (uap->function) {
232 case RTP_LOOKUP:
233 return (copyout(&p->p_rtprio, uap->rtprio, sizeof(struct rtprio)));
234 case RTP_SET:
235 if (pcred->pc_ucred->cr_uid && pcred->p_ruid &&
236 pcred->pc_ucred->cr_uid != p->p_ucred->cr_uid &&
237 pcred->p_ruid != p->p_ucred->cr_uid)
238 return (EPERM);
239 /* disallow setting rtprio in most cases if not superuser */
240 if (suser(pcred->pc_ucred, &curp->p_acflag)) {
241 /* can't set someone else's */
242 if (uap->pid)
243 return (EPERM);
244 /* can't set realtime priority */
245 if (rtp.type == RTP_PRIO_REALTIME)
246 return (EPERM);
247 }
248 switch (rtp.type) {
249 case RTP_PRIO_REALTIME:
250 case RTP_PRIO_NORMAL:
251 case RTP_PRIO_IDLE:
252 if (rtp.prio > RTP_PRIO_MAX)
253 return (EINVAL);
254 p->p_rtprio = rtp;
255 return (0);
256 default:
257 return (EINVAL);
258 }
259
260 default:
261 return (EINVAL);
262 }
263}
228
264
229 if (pcred->pc_ucred->cr_uid && pcred->p_ruid &&
230 pcred->pc_ucred->cr_uid != p->p_ucred->cr_uid &&
231 pcred->p_ruid != p->p_ucred->cr_uid)
232 return (EPERM);
233
234 if (n == RTPRIO_RTOFF) {
235 if(suser(pcred->pc_ucred, &curp->p_acflag)&& !uap->who)
236 return (EPERM);
237 p->p_rtprio = RTPRIO_RTOFF;
238 *retval = RTPRIO_RTOFF;
239 return (0); }
240
241 if (n > RTPRIO_MAX)
242 return (EINVAL);
243 if (n < RTPRIO_MIN)
244 return (EINVAL);
245 if (suser(pcred->pc_ucred, &curp->p_acflag))
246 return (EPERM);
247
248 p->p_rtprio = n;
249
250 *retval = (int)p->p_rtprio;
251 return (0);
252};
253
254#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
255struct setrlimit_args {
256 u_int which;
257 struct orlimit *lim;
258};
259/* ARGSUSED */
260int
261osetrlimit(p, uap, retval)

--- 285 unchanged lines hidden ---
265#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
266struct setrlimit_args {
267 u_int which;
268 struct orlimit *lim;
269};
270/* ARGSUSED */
271int
272osetrlimit(p, uap, retval)

--- 285 unchanged lines hidden ---