From nobody Thu Feb 1 21:31:18 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TQsXk4fKtz58hfX; Thu, 1 Feb 2024 21:31:18 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TQsXk3rvLz4bwp; Thu, 1 Feb 2024 21:31:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706823078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rYlyO8HvQqvfg/ubEgdpMBEP74KabcS6vRMh6CWBflk=; b=coJN3yP86MZoZH/riMma96cco0gxg54TC1XiqYJOUiTBkgUhPFV1vi4ZSadrhM6gGy5YuT OA5OpswFlh1zD+zFpogMiRYKfFcd77PGNiL9Xi6/U7wvPPrHJbXTIxTlpy56iUbYq9nJjk JknwavBGpz3zx+tzNzLxg1wYooxNrUS+WL7nHuiEMLO6wjCjQVQxqo8hurjNz3qz8nKDB5 tMydxmh8dgu54undTFxcFlT0xyvn/VqDeDI0uMd7EjCGDE7ji/1/J/ET3RbzmFq3qQIAXv rI7N3PyZWm6nD5U/z29yhYsRUmvoZJWZ2yO/0lNoejxzRyiYQg/j1RLaAC86fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706823078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rYlyO8HvQqvfg/ubEgdpMBEP74KabcS6vRMh6CWBflk=; b=cynpPy65y2o+FsfdcQUOjhz+tDyAB7P/MQ501pvdMU+V3X3fw71gam5hrnohkcRv2fFP8J aygraqzUJb/WanIqAOROIThJdcw79c804mX/9nQltRYURRgYbowdQvMYexpyE6NJOUQat1 WZamcZ+59WXbioqwErbFmnTzGDOK25PWv1kp2P7CpknkcIJ+cwQE+ZDDP6fkjIowV2Zz+X j3mjnyFGTgk2wcLkfQ2o1Bveo6ZRFcB7zWzd8pID7BuHihvp/EcOYl4qMUeRm4fSC/XkDJ sV2Gr2B4u8UkeP8zAFTNyFVlR6n33mAZrpnE+NlDdm9wIX951+y3UiBV2P0rdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706823078; a=rsa-sha256; cv=none; b=jVq7DjA7VlfAtcY0e3oWU6FNWhLxJbC5DF93VZgkthh0GWSqm+IjTVbvPEbSkiaMRNW9L2 ujrRcdte/WtYAbjnkmSyt8sd6XPG8souiB0yI2kKAA3N+M4niM9XjAFo7kOzYg3vkqlCZq SzwJ2eyRcWaGD7Q81pkg/Fb045GfSfkpPag6cHlYkeezSxgFd6ZGjdSCzjs1kfxtu8nA6k tZUChEp8/vrLDOwGwt+eJvKEf1a6y2me1yxc7BAruG2F07s/9T0W/awdKeW6HXQIVT68f1 01z7SG7xdlIRRPZ+9MrsEcWrgg2BOflbTLQfnlnrTqZ4ION2lpiCkeaZgue8Nw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TQsXk1HfXz1Gw2; Thu, 1 Feb 2024 21:31:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 411LVIj9080866; Thu, 1 Feb 2024 21:31:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 411LVIDX080863; Thu, 1 Feb 2024 21:31:18 GMT (envelope-from git) Date: Thu, 1 Feb 2024 21:31:18 GMT Message-Id: <202402012131.411LVIDX080863@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: f49953dd49f2 - stable/14 - setusercontext(): Move priority setting in new setclasspriority() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f49953dd49f28169a5f3b86a414936c095c19ea9 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=f49953dd49f28169a5f3b86a414936c095c19ea9 commit f49953dd49f28169a5f3b86a414936c095c19ea9 Author: Olivier Certner AuthorDate: 2023-05-29 17:09:36 +0000 Commit: Olivier Certner CommitDate: 2024-02-01 21:29:48 +0000 setusercontext(): Move priority setting in new setclasspriority() In preparation for setting priorities from '~/.login_conf' and to ease reading of setusercontext(). No functional change. Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40350 (cherry picked from commit 7b94ec550ef6e7b75d608e125e9b78478197d4e7) Approved by: markj (mentor) --- lib/libutil/login_class.c | 97 +++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 45 deletions(-) diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c index 9c3285736f3b..9d8dc652d678 100644 --- a/lib/libutil/login_class.c +++ b/lib/libutil/login_class.c @@ -456,6 +456,56 @@ setlogincontext(login_cap_t *lc, const struct passwd *pwd, unsigned long flags) } +/* + * Private function to set process priority. + */ +static void +setclasspriority(login_cap_t * const lc, struct passwd const * const pwd) +{ + const rlim_t def_val = LOGIN_DEFPRI, err_val = INT64_MIN; + rlim_t p = login_getcapnum(lc, "priority", def_val, err_val); + int rc; + + if (p == err_val) { + /* Invariant: 'lc' != NULL. */ + syslog(LOG_WARNING, + "%s%s%sLogin class '%s': " + "Invalid priority specification: '%s'", + pwd ? "Login '" : "", + pwd ? pwd->pw_name : "", + pwd ? "': " : "", + lc->lc_class, + login_getcapstr(lc, "priority", "", "")); + /* Reset the priority, as if the capability was not present. */ + p = def_val; + } + + if (p > PRIO_MAX) { + struct rtprio rtp; + + rtp.type = RTP_PRIO_IDLE; + p += RTP_PRIO_MIN - (PRIO_MAX + 1); + rtp.prio = p > RTP_PRIO_MAX ? RTP_PRIO_MAX : p; + rc = rtprio(RTP_SET, 0, &rtp); + } else if (p < PRIO_MIN) { + struct rtprio rtp; + + rtp.type = RTP_PRIO_REALTIME; + p += RTP_PRIO_MAX - (PRIO_MIN - 1); + rtp.prio = p < RTP_PRIO_MIN ? RTP_PRIO_MIN : p; + rc = rtprio(RTP_SET, 0, &rtp); + } else + rc = setpriority(PRIO_PROCESS, 0, (int)p); + + if (rc != 0) + syslog(LOG_WARNING, + "%s%s%sLogin class '%s': " + "Setting priority failed: %m", + pwd ? "Login '" : "", + pwd ? pwd->pw_name : "", + pwd ? "': " : "", + lc ? lc->lc_class : ""); +} /* * setusercontext() @@ -490,51 +540,8 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN | LOGIN_SETMAC); /* Set the process priority */ - if (flags & LOGIN_SETPRIORITY) { - const rlim_t def_val = LOGIN_DEFPRI, err_val = INT64_MIN; - rlim_t p = login_getcapnum(lc, "priority", def_val, err_val); - int rc; - - if (p == err_val) { - /* Invariant: 'lc' != NULL. */ - syslog(LOG_WARNING, - "%s%s%sLogin class '%s': " - "Invalid priority specification: '%s'", - pwd ? "Login '" : "", - pwd ? pwd->pw_name : "", - pwd ? "': " : "", - lc->lc_class, - login_getcapstr(lc, "priority", "", "")); - /* Reset the priority, as if the capability was not present. */ - p = def_val; - } - - if (p > PRIO_MAX) { - struct rtprio rtp; - - rtp.type = RTP_PRIO_IDLE; - p += RTP_PRIO_MIN - (PRIO_MAX + 1); - rtp.prio = p > RTP_PRIO_MAX ? RTP_PRIO_MAX : p; - rc = rtprio(RTP_SET, 0, &rtp); - } else if (p < PRIO_MIN) { - struct rtprio rtp; - - rtp.type = RTP_PRIO_REALTIME; - p += RTP_PRIO_MAX - (PRIO_MIN - 1); - rtp.prio = p < RTP_PRIO_MIN ? RTP_PRIO_MIN : p; - rc = rtprio(RTP_SET, 0, &rtp); - } else - rc = setpriority(PRIO_PROCESS, 0, (int)p); - - if (rc != 0) - syslog(LOG_WARNING, - "%s%s%sLogin class '%s': " - "Setting priority failed: %m", - pwd ? "Login '" : "", - pwd ? pwd->pw_name : "", - pwd ? "': " : "", - lc ? lc->lc_class : ""); - } + if (flags & LOGIN_SETPRIORITY) + setclasspriority(lc, pwd); /* Setup the user's group permissions */ if (flags & LOGIN_SETGROUP) {