From owner-svn-src-head@freebsd.org Sun Jan 12 13:38:52 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 34B4B22F6C5; Sun, 12 Jan 2020 13:38:52 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47wd980RVZz4P0G; Sun, 12 Jan 2020 13:38:52 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0A4DB1C6AB; Sun, 12 Jan 2020 13:38:52 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00CDcpaX021055; Sun, 12 Jan 2020 13:38:51 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00CDcpwG021053; Sun, 12 Jan 2020 13:38:51 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <202001121338.00CDcpwG021053@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Sun, 12 Jan 2020 13:38:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356658 - in head/sys: compat/linux kern sys X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: in head/sys: compat/linux kern sys X-SVN-Commit-Revision: 356658 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Jan 2020 13:38:52 -0000 Author: trasz Date: Sun Jan 12 13:38:51 2020 New Revision: 356658 URL: https://svnweb.freebsd.org/changeset/base/356658 Log: Add kern_setpriority(), use it in Linuxulator. Reviewed by: kib MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D22841 Modified: head/sys/compat/linux/linux_misc.c head/sys/kern/kern_resource.c head/sys/sys/syscallsubr.h Modified: head/sys/compat/linux/linux_misc.c ============================================================================== --- head/sys/compat/linux/linux_misc.c Sun Jan 12 06:13:52 2020 (r356657) +++ head/sys/compat/linux/linux_misc.c Sun Jan 12 13:38:51 2020 (r356658) @@ -1207,12 +1207,8 @@ linux_getitimer(struct thread *td, struct linux_getiti 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) */ Modified: head/sys/kern/kern_resource.c ============================================================================== --- head/sys/kern/kern_resource.c Sun Jan 12 06:13:52 2020 (r356657) +++ head/sys/kern/kern_resource.c Sun Jan 12 13:38:51 2020 (r356658) @@ -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_ 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_ 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_ 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); Modified: head/sys/sys/syscallsubr.h ============================================================================== --- head/sys/sys/syscallsubr.h Sun Jan 12 06:13:52 2020 (r356657) +++ head/sys/sys/syscallsubr.h Sun Jan 12 13:38:51 2020 (r356658) @@ -251,6 +251,7 @@ int kern_sendit(struct thread *td, int s, struct msghd 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);