This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
nice/setpriority fixes
- To: libc-alpha at sources dot redhat dot com
- Subject: nice/setpriority fixes
- From: Bruce <bruce at puremagic dot com>
- Date: Mon, 04 Jun 2001 20:26:36 -0600
The attached patch fixes the bug reported on bug-glibc.
- Bruce
2001-06-04 Bruce Mitchener <bruce@cubik.org>
* manual/resource.texi: Correct setpriority/nice
documentation.
* sysdeps/unix/nice.c: Correct nice() implementation.
Index: manual/resource.texi
===================================================================
RCS file: /cvs/glibc/libc/manual/resource.texi,v
retrieving revision 1.10
diff -u -r1.10 resource.texi
--- resource.texi 2001/05/21 16:19:34 1.10
+++ resource.texi 2001/06/04 18:04:24
@@ -1170,7 +1170,7 @@
Set the nice value of a set of processes to @var{niceval}; @var{class}
and @var{id} specify which ones (see below).
-The return value is the nice value on success, and @code{-1} on
+The return value is @code{0} on success, and @code{-1} on
failure. The following @code{errno} error condition are possible for
this function:
@@ -1225,7 +1225,9 @@
@comment BSD
@deftypefun int nice (int @var{increment})
Increment the nice value of the calling process by @var{increment}.
-The return value is the same as for @code{setpriority}.
+The return value is the new nice value on success, and @code{-1} on
+failure. In the case of failuer, @code{errno} will be set to the
+same values as for @code{setpriority}. .
Here is an equivalent definition of @code{nice}:
@@ -1233,8 +1235,12 @@
int
nice (int increment)
@{
- int old = getpriority (PRIO_PROCESS, 0);
- return setpriority (PRIO_PROCESS, 0, old + increment);
+ int result, old = getpriority (PRIO_PROCESS, 0);
+ result = setpriority (PRIO_PROCESS, 0, old + increment);
+ if (result != -1)
+ return old - increment;
+ else
+ return -1;
@}
@end smallexample
@end deftypefun
Index: sysdeps/unix/nice.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/nice.c,v
retrieving revision 1.3
diff -u -r1.3 nice.c
--- nice.c 1997/06/23 21:53:50 1.3
+++ nice.c 2001/06/04 18:04:34
@@ -28,6 +28,7 @@
{
int save;
int prio;
+ int result;
/* -1 is a valid priority, so we use errno to check for an error. */
save = errno;
@@ -41,5 +42,9 @@
__set_errno (save);
}
- return setpriority (PRIO_PROCESS, 0, prio + incr);
+ result = setpriority (PRIO_PROCESS, 0, prio + incr);
+ if (result != -1)
+ return prio + incr;
+ else
+ return -1;
}