[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

at jobs are always run with nice 0



at(1) jobs are always run with nice 0, because setusercontext(3)
overwrites the priority value set by nice(3).  I wonder how the
priority can be lowered while running with the effective uid of
a user != root.  I thought this is not possible.

Switched to setpriority(2) while I'm there.

-hgw

diff -u -r1.11 atrun.c
--- atrun.c	2001/04/19 22:57:27	1.11
+++ atrun.c	2001/05/05 22:13:08
@@ -30,6 +30,8 @@
 #include <sys/fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 #include <sys/wait.h>
 #include <sys/param.h>
 #include <ctype.h>
@@ -242,7 +244,7 @@
 		perr2("Cannot chdir to ", _PATH_ATSPOOL);
 
 	/*
-	 * Create a file to hold the output of the job we are  about to
+	 * Create a file to hold the output of the job we are about to
 	 * run. Write the mail header.
 	 */
 
@@ -297,16 +299,21 @@
 		if (chdir(_PATH_ATJOBS) < 0)
 			perr2("Cannot chdir to ", _PATH_ATJOBS);
 
-		queue = *filename;
-
-		if (queue > 'b')
-		    nice(queue - 'b');
-
 		if (setusercontext(0, pentry, pentry->pw_uid, LOGIN_SETALL) < 0)
 			perr("Cannot set user context");
 
 		if (chdir(pentry->pw_dir) < 0)
 			chdir("/");
+
+		/* First letter indicates requested job priority */
+		queue = filename[0];
+		if (islower(queue) && (queue > 'b'))
+			if (setpriority(PRIO_PROCESS, 0, queue - 'b') != 0)
+				perr("Can't set process priority");
+
+		if (isupper(queue) && (queue > 'B'))
+			if (setpriority(PRIO_PROCESS, 0, queue - 'B') != 0)
+				perr("Can't set process priority");
 
 		if (execle(_PATH_BSHELL, "sh", NULL, nenvp) != 0)
 			perr("Exec failed for /bin/sh");