Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157079910
D40350.id122659.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D40350.id122659.diff
View Options
diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c
--- a/lib/libutil/login_class.c
+++ b/lib/libutil/login_class.c
@@ -438,6 +438,61 @@
}
+/*
+ * Private function to set process priority.
+ */
+static void
+setclasspriority(login_cap_t * const lc, struct passwd const * const pwd)
+{
+ /*
+ * Make it unlikely that someone would input our default sentinel
+ * (which indicates no specification).
+ */
+ rlim_t const def_val = INT64_MIN + 1, err_val = INT64_MIN;
+ rlim_t p = login_getcapnum(lc, "priority", def_val, err_val);
+ int rc;
+
+ if (p == def_val)
+ return;
+
+ /* Invariant: 'lc' != NULL from here. */
+
+ if (p == err_val) {
+ 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", "", ""));
+ return;
+ }
+
+ 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_class);
+}
/*
* setusercontext()
@@ -472,53 +527,8 @@
flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN | LOGIN_SETMAC);
/* Set the process priority */
- if (flags & LOGIN_SETPRIORITY) {
- /*
- * Make it unlikely that someone would input our default sentinel
- * (which indicates no specification).
- */
- rlim_t const def_val = INT64_MIN + 1, err_val = INT64_MIN;
- rlim_t p = login_getcapnum(lc, "priority", def_val, err_val);
- int rc;
-
- if (p != def_val) {
- /* Invariant: 'lc' != NULL from here. */
- if (p == err_val) {
- 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", "", ""));
- } else {
- 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_class);
- }
- }
- }
+ if (flags & LOGIN_SETPRIORITY)
+ setclasspriority(lc, pwd);
/* Setup the user's group permissions */
if (flags & LOGIN_SETGROUP) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 19, 8:02 AM (16 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33301330
Default Alt Text
D40350.id122659.diff (3 KB)
Attached To
Mode
D40350: setusercontext(): Move priority setting in new setclasspriority()
Attached
Detach File
Event Timeline
Log In to Comment