From doogie@forbidden-donut.anet-stl.com  Thu May 14 17:31:50 1998
Received: from forbidden-donut.anet-stl.com (vmailer@forbidden-donut.anet-stl.com [209.83.128.17])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id RAA20204
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 14 May 1998 17:31:49 -0700 (PDT)
          (envelope-from doogie@forbidden-donut.anet-stl.com)
Received: by forbidden-donut.anet-stl.com (VMailer, from userid 1001)
	id 1C21F043DA; Thu, 14 May 1998 19:31:23 -0500 (CDT)
Message-Id: <19980515003122.1C21F043DA@forbidden-donut.anet-stl.com>
Date: Thu, 14 May 1998 19:31:22 -0500 (CDT)
From: doogie@forbidden-donut.anet-stl.com
Reply-To: doogie@forbidden-donut.anet-stl.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: There is no way to set real/idletime priority in login.conf
X-Send-Pr-Version: 3.2

>Number:         6636
>Category:       bin
>Synopsis:       There is no way to set real/idletime priority in login.conf
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    steve
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 14 17:30:00 PDT 1998
>Closed-Date:    Thu Jun 4 15:24:59 PDT 1998
>Last-Modified:  Thu Jun  4 15:25:36 PDT 1998
>Originator:     Jason Young
>Release:        FreeBSD 2.2.6-STABLE i386
>Organization:
ANET St. Louis
>Environment:

FreeBSD 3.0-CURRENT, as of 05-10-98
FreeBSD 2.2.6-STABLE, as of 05-10-98

>Description:

There is no way to set idle or realtime processing priorities for an
entire user class via the login.conf file. This capability is highly
desirable.

For example, you might wish to set all normal shell users to an idletime
processing class, to keep them from being able to interfere with system
processes. You might also set root logins at the console to a realtime
value, so that you can get into a machine that's running something out of
control. This is only what I can think of off the top of my head. 

>How-To-Repeat:

N/A.

>Fix:

This patch adapts the 'priority' attribute to understand values ranging
from 52 to -52, to allow setting of priority in a manner identical to that
displayed by top(1). 21-52 are idletime priorities, -21 to -52 are
realtime, and 20 to -20 are normal nice values.

*** login_class.c.old	Sat May 10 13:55:38 1997
--- login_class.c	Sun May 10 07:08:07 1998
***************
*** 36,45 ****
--- 36,46 ----
  #include <fcntl.h>
  #include <pwd.h>
  #include <syslog.h>
  #include <login_cap.h>
  #include <paths.h>
+ #include <sys/rtprio.h>
  
  
  #undef	UNKNOWN
  #define	UNKNOWN	"su"
  
***************
*** 313,322 ****
--- 314,324 ----
  setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned int flags)
  {
      quad_t	p;
      mode_t	mymask;
      login_cap_t *llc = NULL;
+     struct rtprio rtp;
  
      if (lc == NULL) {
  	if (pwd != NULL && (lc = login_getpwclass(pwd)) != NULL)
  	    llc = lc; /* free this when we're done */
      }
***************
*** 328,343 ****
      if (pwd == NULL)
  	flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN);
  
      /* Set the process priority */
      if (flags & LOGIN_SETPRIORITY) {
! 	p = login_getcapnum(lc, "priority", LOGIN_DEFPRI, LOGIN_DEFPRI);
  
! 	p = (p < PRIO_MIN || p > PRIO_MAX) ? LOGIN_DEFPRI : p;
! 	if (setpriority(PRIO_PROCESS, 0, (int)p) != 0)
! 	    syslog(LOG_WARNING, "setpriority '%s' (%s): %m",
  		   pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS);
      }
  
      /* Setup the user's group permissions */
      if (flags & LOGIN_SETGROUP) {
  	if (setgid(pwd->pw_gid) != 0) {
--- 330,360 ----
      if (pwd == NULL)
  	flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN);
  
      /* Set the process priority */
      if (flags & LOGIN_SETPRIORITY) {
!         p = login_getcapnum(lc, "priority", LOGIN_DEFPRI, LOGIN_DEFPRI);
  
!         if(p > PRIO_MAX) {
! 	    rtp.type = RTP_PRIO_IDLE;
! 	    rtp.prio = p - PRIO_MAX - 1;
! 	    p = (rtp.prio > RTP_PRIO_MAX) ? 31 : p;
! 	    if(rtprio(RTP_SET, 0, &rtp))
! 	       syslog(LOG_WARNING, "rtprio '%s' (%s): %m",
  		   pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS);
+ 	} else if(p < PRIO_MIN) {
+ 	    rtp.type = RTP_PRIO_REALTIME;
+ 	    rtp.prio = abs(p - PRIO_MIN + RTP_PRIO_MAX);
+ 	    p = (rtp.prio > RTP_PRIO_MAX) ? 1 : p;
+ 	    if(rtprio(RTP_SET, 0, &rtp))
+ 		syslog(LOG_WARNING, "rtprio '%s' (%s): %m",
+ 		   pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS);
+ 	} else {
+ 	    if (setpriority(PRIO_PROCESS, 0, (int)p) != 0)
+ 	        syslog(LOG_WARNING, "setpriority '%s' (%s): %m",
+ 		   pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS);
+ 	}
      }
  
      /* Setup the user's group permissions */
      if (flags & LOGIN_SETGROUP) {
  	if (setgid(pwd->pw_gid) != 0) {
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->suspended 
State-Changed-By: phk 
State-Changed-When: Tue May 19 03:06:24 PDT 1998 
State-Changed-Why:  
awaiting committer 
Responsible-Changed-From-To: freebsd-bugs->steve 
Responsible-Changed-By: steve 
Responsible-Changed-When: Sun May 24 20:58:09 PDT 1998 
Responsible-Changed-Why:  
Patch committed to -current, thanks!  I will merge into 
-stable soon. 
State-Changed-From-To: suspended->closed 
State-Changed-By: steve 
State-Changed-When: Thu Jun 4 15:24:59 PDT 1998 
State-Changed-Why:  
Patch committed to both -stable and -current.  Thanks! 
>Unformatted:
