Fix a clang 3.5 warning about abs(3) being given an argument of type

quad_t in setusercontext().  While here, sanitize the clamping of the
priority value, and use the correct type for the return value of
login_getcapnum().

Reviewed by:	kib
MFC after:	3 days
This commit is contained in:
dim 2014-10-29 20:18:37 +00:00
parent dde27ca539
commit a4cb0d397c

View File

@ -424,7 +424,7 @@ setlogincontext(login_cap_t *lc, const struct passwd *pwd,
int int
setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned int flags) setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned int flags)
{ {
quad_t p; rlim_t p;
mode_t mymask; mode_t mymask;
login_cap_t *llc = NULL; login_cap_t *llc = NULL;
struct sigaction sa, prevsa; struct sigaction sa, prevsa;
@ -449,16 +449,16 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
if (p > PRIO_MAX) { if (p > PRIO_MAX) {
rtp.type = RTP_PRIO_IDLE; rtp.type = RTP_PRIO_IDLE;
rtp.prio = p - PRIO_MAX - 1; p -= PRIO_MAX + 1;
p = (rtp.prio > RTP_PRIO_MAX) ? 31 : p; rtp.prio = p > RTP_PRIO_MAX ? RTP_PRIO_MAX : p;
if (rtprio(RTP_SET, 0, &rtp)) if (rtprio(RTP_SET, 0, &rtp))
syslog(LOG_WARNING, "rtprio '%s' (%s): %m", syslog(LOG_WARNING, "rtprio '%s' (%s): %m",
pwd ? pwd->pw_name : "-", pwd ? pwd->pw_name : "-",
lc ? lc->lc_class : LOGIN_DEFCLASS); lc ? lc->lc_class : LOGIN_DEFCLASS);
} else if (p < PRIO_MIN) { } else if (p < PRIO_MIN) {
rtp.type = RTP_PRIO_REALTIME; rtp.type = RTP_PRIO_REALTIME;
rtp.prio = abs(p - PRIO_MIN + RTP_PRIO_MAX); p -= PRIO_MIN - RTP_PRIO_MAX;
p = (rtp.prio > RTP_PRIO_MAX) ? 1 : p; rtp.prio = p < RTP_PRIO_MIN ? RTP_PRIO_MIN : p;
if (rtprio(RTP_SET, 0, &rtp)) if (rtprio(RTP_SET, 0, &rtp))
syslog(LOG_WARNING, "rtprio '%s' (%s): %m", syslog(LOG_WARNING, "rtprio '%s' (%s): %m",
pwd ? pwd->pw_name : "-", pwd ? pwd->pw_name : "-",