public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Linux Kernel Patch; setpriority
@ 2002-03-27 20:59 Stephen Baker
  2002-03-27 21:19 ` David Wagner
  2002-03-27 22:32 ` Chris Wright
  0 siblings, 2 replies; 7+ messages in thread
From: Stephen Baker @ 2002-03-27 20:59 UTC (permalink / raw)
  To: linux-kernel

All,

This patch will allow a process or thread to changes it's priority 
dynamically based on it's capabilities.  In our case we wanted to use 
threads with Linux.  To have true priorities we need root to use 
SCHED_FIFO or SCHED_RR; in many case root access is not allowed but we 
still wanted priorities.  So we started using setpriority to change a 
threads priority.  Now we used nice values from 19 to 0 which did not 
require root access.  In some cases a thread need to raise it's nice 
level and this would fail.  I also saw a note man renice(8) that said 
this bug exists.
So the following patch address this problem.  It allows any process or 
thread to raise or lower it's nice value for it's current capability. 
For example a CAP_SYS_NICE process can use 19 to -20 for it's value and 
a normal user can use 19 to 0.  By capping normal user to zero then we 
don't have any problems with conflicts with higher priority programs in 
the system since zero is the default value.

SB


--- linux-2.4.9-31/kernel/sys.c    Wed Mar 27 13:11:10 2002
+++ linux/kernel/sys.c    Wed Mar 27 13:09:36 2002
@@ -194,6 +194,12 @@
    return 0;
}

+/*
+ * Allow the process to adjust it's priority higher or lower.
+ * If the process has CAP_SYS_NICE set then we can use
+ * -20 to 19.  Otherwise we use 0 to 19 as our valid priority
+ * range.
+ */
asmlinkage long sys_setpriority(int which, int who, int niceval)
{
    struct task_struct *p;
@@ -220,7 +226,8 @@
        }
        if (error == -ESRCH)
            error = 0;
-        if (niceval < p->nice && !capable(CAP_SYS_NICE))
+        if ((niceval < 0) &&
+            (niceval < p->nice && !capable(CAP_SYS_NICE)))
            error = -EACCES;
        else
            p->nice = niceval;



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-03-29  0:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-03-27 20:59 Linux Kernel Patch; setpriority Stephen Baker
2002-03-27 21:19 ` David Wagner
2002-03-29  0:24   ` Mike Fedyk
2002-03-27 22:32 ` Chris Wright
2002-03-28 21:19   ` Bill Davidsen
2002-03-28 22:20     ` Stephen Baker
2002-03-29  0:39       ` Bill Davidsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox