summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Tomasz Napierala <trasz@FreeBSD.org>2020-01-12 13:38:51 +0000
committerEdward Tomasz Napierala <trasz@FreeBSD.org>2020-01-12 13:38:51 +0000
commit7a0ef283e66c39f35ac023588cb80803dd71f25b (patch)
treed2de1adeb38229cf002798b9eec655397893ecff
parentd14a599d6977710b9896c0b6fe7772bd802541b5 (diff)
Notes
-rw-r--r--sys/compat/linux/linux_misc.c6
-rw-r--r--sys/kern/kern_resource.c31
-rw-r--r--sys/sys/syscallsubr.h1
3 files changed, 21 insertions, 17 deletions
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index 206f9dd53cf62..761f954f95041 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -1207,12 +1207,8 @@ linux_getitimer(struct thread *td, struct linux_getitimer_args *uap)
int
linux_nice(struct thread *td, struct linux_nice_args *args)
{
- struct setpriority_args bsd_args;
- bsd_args.which = PRIO_PROCESS;
- bsd_args.who = 0; /* current process */
- bsd_args.prio = args->inc;
- return (sys_setpriority(td, &bsd_args));
+ return (kern_setpriority(td, PRIO_PROCESS, 0, args->inc));
}
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index 99efe979aa201..aa3b91537469e 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -175,24 +175,31 @@ struct setpriority_args {
int
sys_setpriority(struct thread *td, struct setpriority_args *uap)
{
+
+ return (kern_setpriority(td, uap->which, uap->who, uap->prio));
+}
+
+int
+kern_setpriority(struct thread *td, int which, int who, int prio)
+{
struct proc *curp, *p;
struct pgrp *pg;
int found = 0, error = 0;
curp = td->td_proc;
- switch (uap->which) {
+ switch (which) {
case PRIO_PROCESS:
- if (uap->who == 0) {
+ if (who == 0) {
PROC_LOCK(curp);
- error = donice(td, curp, uap->prio);
+ error = donice(td, curp, prio);
PROC_UNLOCK(curp);
} else {
- p = pfind(uap->who);
+ p = pfind(who);
if (p == NULL)
break;
error = p_cansee(td, p);
if (error == 0)
- error = donice(td, p, uap->prio);
+ error = donice(td, p, prio);
PROC_UNLOCK(p);
}
found++;
@@ -200,11 +207,11 @@ sys_setpriority(struct thread *td, struct setpriority_args *uap)
case PRIO_PGRP:
sx_slock(&proctree_lock);
- if (uap->who == 0) {
+ if (who == 0) {
pg = curp->p_pgrp;
PGRP_LOCK(pg);
} else {
- pg = pgfind(uap->who);
+ pg = pgfind(who);
if (pg == NULL) {
sx_sunlock(&proctree_lock);
break;
@@ -215,7 +222,7 @@ sys_setpriority(struct thread *td, struct setpriority_args *uap)
PROC_LOCK(p);
if (p->p_state == PRS_NORMAL &&
p_cansee(td, p) == 0) {
- error = donice(td, p, uap->prio);
+ error = donice(td, p, prio);
found++;
}
PROC_UNLOCK(p);
@@ -224,15 +231,15 @@ sys_setpriority(struct thread *td, struct setpriority_args *uap)
break;
case PRIO_USER:
- if (uap->who == 0)
- uap->who = td->td_ucred->cr_uid;
+ if (who == 0)
+ who = td->td_ucred->cr_uid;
sx_slock(&allproc_lock);
FOREACH_PROC_IN_SYSTEM(p) {
PROC_LOCK(p);
if (p->p_state == PRS_NORMAL &&
- p->p_ucred->cr_uid == uap->who &&
+ p->p_ucred->cr_uid == who &&
p_cansee(td, p) == 0) {
- error = donice(td, p, uap->prio);
+ error = donice(td, p, prio);
found++;
}
PROC_UNLOCK(p);
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 6c7bfd9c1b912..f16bc1de290b1 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -251,6 +251,7 @@ int kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags,
int kern_setgroups(struct thread *td, u_int ngrp, gid_t *groups);
int kern_setitimer(struct thread *, u_int, struct itimerval *,
struct itimerval *);
+int kern_setpriority(struct thread *td, int which, int who, int prio);
int kern_setrlimit(struct thread *, u_int, struct rlimit *);
int kern_setsockopt(struct thread *td, int s, int level, int name,
const void *optval, enum uio_seg valseg, socklen_t valsize);