summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-06-03 22:32:05 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-06-03 22:32:05 +0000
commitac25eaa91a8c04124f5331584a2057642504ccf2 (patch)
treeba9cc6edd933e35bc0f312f537ee0a357bd016f1 /lib/libc/gen
parent9c07526c7d465ea61369d3c84fe297ea550e768f (diff)
Make nice(3) standards compliant; adapted from patch by Matthias Drochner
While I'm here correct the lies in the manual page.
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/nice.331
-rw-r--r--lib/libc/gen/nice.c9
2 files changed, 30 insertions, 10 deletions
diff --git a/lib/libc/gen/nice.3 b/lib/libc/gen/nice.3
index 8e4a5365a68..41bfa6e979f 100644
--- a/lib/libc/gen/nice.3
+++ b/lib/libc/gen/nice.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: nice.3,v 1.11 2001/05/05 23:12:07 millert Exp $
+.\" $OpenBSD: nice.3,v 1.12 2002/06/03 22:32:04 millert Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -36,7 +36,7 @@
.Os
.Sh NAME
.Nm nice
-.Nd set program scheduling priority
+.Nd change process scheduling priority
.Sh SYNOPSIS
.Fd #include <unistd.h>
.Ft int
@@ -49,18 +49,35 @@ This interface is obsoleted by
.Pp
The
.Fn nice
-function obtains the scheduling priority of the process
-from the system and sets it to the priority value specified in
-.Fa incr .
-The priority is a value in the range \-20 to 20.
+function adds the value specified in
+.Fa incr
+to the scheduling priority of the invoking process.
+.Pp
+.Fa incr
+is an integer such that the resulting scheduling priority
+is within the range \-20 to 20.
The default priority is 0; lower priorities cause more favorable scheduling.
Only the superuser may lower priorities.
.Pp
Children inherit the priority of their parent processes via
.Xr fork 2 .
.Sh RETURN VALUES
+On success,
+.Fn nice
+returns the new priority.
+On error, it returns -1.
+.Pp
+Since
+.Fn nice
+can legitimately return the value -1, it is necessary
+to clear the external variable
+.Va errno
+prior to the
+call, then check it afterward to determine
+if a -1 is an error or a legitimate value.
+.Sh ERRORS
.Fn nice
-returns the same values as
+has the same failure conditions as
.Xr setpriority 2 .
.Sh SEE ALSO
.Xr nice 1 ,
diff --git a/lib/libc/gen/nice.c b/lib/libc/gen/nice.c
index b6a95079fa6..6c312a1da29 100644
--- a/lib/libc/gen/nice.c
+++ b/lib/libc/gen/nice.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: nice.c,v 1.3 1998/05/06 23:11:43 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: nice.c,v 1.4 2002/06/03 22:32:04 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -42,7 +42,7 @@ static char rcsid[] = "$OpenBSD: nice.c,v 1.3 1998/05/06 23:11:43 deraadt Exp $"
#include <unistd.h>
/*
- * Backwards compatible nice.
+ * Backwards compatible nice().
*/
int
nice(incr)
@@ -54,5 +54,8 @@ nice(incr)
prio = getpriority(PRIO_PROCESS, 0);
if (prio == -1 && errno)
return (-1);
- return (setpriority(PRIO_PROCESS, 0, prio + incr));
+ prio += incr;
+ if (setpriority(PRIO_PROCESS, 0, prio) != 0)
+ return (-1);
+ return (prio);
}