From nobody Thu Feb 01 21:26:11 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 4TQsQr2TLnz58hGD; Thu, 1 Feb 2024 21:26:12 +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 4TQsQr0Zd6z4WKR; Thu, 1 Feb 2024 21:26:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706822772; 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=kpCGYSVp264IBY5TqIid0PH1b7TgtlLFpwI4Pf+DMH0=; b=iXoFPryxyYa9ToJOcx7iAYYeBH+xX8eV0aXr49w4zphOUZFGoX9PduNrI/pHXHMQ+zCLz7 bKBHQTf3aMLmHbjB7CnxdmdOclZdM1RMl/j3vNwzpMPHOROtB7r+rHC87V4aQ2K0PE8HP0 wXjhHlUAfVOsRihbzZNgthKsLY/+obyYrr1qGJp2vHdIfowrdms6WXPTkiJHUo6gO+29di BBs1/YgbXCL8CzUpmFj5PXD4HWHPjvJNUmJsp0H9pXj1h5ZandUVFhGsF7JMetFGU0+T8w tSqNUXBrhNjcxW3XcJJvhKVginW2KSyQK71ohthoDTQeEm5PeBP8WBopSW8UcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706822772; 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=kpCGYSVp264IBY5TqIid0PH1b7TgtlLFpwI4Pf+DMH0=; b=RP9+lw2efrscg8T6hp+Aqm0NFpDoLGomzkjCHntNY5ARSp7gEkJVdaSTf48hwDh2YUSasD On8hLKx8FWduKgM4L0hlFM6HIA5HSRPWUHgAWxJHo6WqxD/hKGUDUGCYYDUl7g+9BYNFy6 i2IGdMS2Bn/kw+B2aoco0wsIVAsF7danIJoDB5jHH3GZK36Bveu9mNWdUQjzlm1tijDBAZ mbQHRQoAilKHuAJgVLZgtR6rDrbD/zWDIDkIjkhi650WxoDJk65ONiMSkycw4EqAzeMEWg G92SKi4hej/kBElQaaQHHV1s3WTpNl5nwbfSPhNIFitEACpyp3/m0STFnJRzJQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706822772; a=rsa-sha256; cv=none; b=Fl6rAkocPNdroJCIOuzwLhAok0P7GiyZY6Y7KF8qCRIsAJu0JIYV7Z3+5zdxgtXO39oVQi HUCXb4V0VbmaEnY6+vWVmpTX2zdXb8cWvW328+FyA1QYbP3BkRoBpdiu9cRGakDGnVhfIK PXdzFMVuCvLLa9qujIYuhO8Y+12LMYcgKQ23O8aukMjdQe0xX9FDEuU5K2h3lWcQFyUJl4 eFE79kZ8AnjsrA2J002n0uUCATvdSUSGIcjl9ZylHPWZp63ZGlHbtb1bJEQc24EbE0SPbZ mfLXII2ijGF0PHPIvCaOBXDxJevuSlRDy+MM1zI47R96Jv/6QrGCuIxm7Fk75Q== 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 4TQsQq6mWXz1Hcs; Thu, 1 Feb 2024 21:26:11 +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 411LQBMg070641; Thu, 1 Feb 2024 21:26:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 411LQBb3070638; Thu, 1 Feb 2024 21:26:11 GMT (envelope-from git) Date: Thu, 1 Feb 2024 21:26:11 GMT Message-Id: <202402012126.411LQBb3070638@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: 3fc149c302ab - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 3fc149c302ab7287e063e7fdd0a0d7031947e3fb Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=3fc149c302ab7287e063e7fdd0a0d7031947e3fb commit 3fc149c302ab7287e063e7fdd0a0d7031947e3fb Author: Olivier Certner AuthorDate: 2023-05-29 17:09:36 +0000 Commit: Olivier Certner CommitDate: 2024-02-01 21:23:52 +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) {