svn commit: r279397 - in head: contrib/netbsd-tests/lib/libc/gen lib/libc/gen
Jilles Tjoelker
jilles at FreeBSD.org
Sat Feb 28 18:22:12 UTC 2015
Author: jilles
Date: Sat Feb 28 18:22:10 2015
New Revision: 279397
URL: https://svnweb.freebsd.org/changeset/base/279397
Log:
nice(): Put back old return value, keeping [EPERM] error.
Commit r279154 changed the API and ABI significantly, and {NZERO} is still
wrong.
Also, preserve errno on success instead of setting it to 0.
PR: 189821
Reported by: bde
Relnotes: yes
Modified:
head/contrib/netbsd-tests/lib/libc/gen/t_nice.c
head/lib/libc/gen/nice.3
head/lib/libc/gen/nice.c
Modified: head/contrib/netbsd-tests/lib/libc/gen/t_nice.c
==============================================================================
--- head/contrib/netbsd-tests/lib/libc/gen/t_nice.c Sat Feb 28 17:44:31 2015 (r279396)
+++ head/contrib/netbsd-tests/lib/libc/gen/t_nice.c Sat Feb 28 18:22:10 2015 (r279397)
@@ -93,7 +93,11 @@ ATF_TC_HEAD(nice_priority, tc)
ATF_TC_BODY(nice_priority, tc)
{
+#ifdef __FreeBSD__
+ int i, pri, pri2, nic;
+#else
int i, pri, nic;
+#endif
pid_t pid;
int sta;
@@ -106,8 +110,10 @@ ATF_TC_BODY(nice_priority, tc)
pri = getpriority(PRIO_PROCESS, 0);
ATF_REQUIRE(errno == 0);
+#ifdef __NetBSD__
if (nic != pri)
atf_tc_fail("nice(3) and getpriority(2) conflict");
+#endif
/*
* Also verify that the nice(3) values
@@ -119,10 +125,18 @@ ATF_TC_BODY(nice_priority, tc)
if (pid == 0) {
errno = 0;
+#ifdef __FreeBSD__
pri = getpriority(PRIO_PROCESS, 0);
+#else
+ pri2 = getpriority(PRIO_PROCESS, 0);
+#endif
ATF_REQUIRE(errno == 0);
+#ifdef __FreeBSD__
+ if (pri != pri2)
+#else
if (nic != pri)
+#endif
_exit(EXIT_FAILURE);
_exit(EXIT_SUCCESS);
@@ -161,7 +175,11 @@ ATF_TC_HEAD(nice_thread, tc)
ATF_TC_BODY(nice_thread, tc)
{
pthread_t tid[5];
+#ifdef __FreeBSD__
+ int pri, rv, val;
+#else
int rv, val;
+#endif
size_t i;
/*
@@ -173,7 +191,12 @@ ATF_TC_BODY(nice_thread, tc)
val = nice(i);
ATF_REQUIRE(val != -1);
+#ifdef __FreeBSD__
+ pri = getpriority(PRIO_PROCESS, 0);
+ rv = pthread_create(&tid[i], NULL, threadfunc, &pri);
+#else
rv = pthread_create(&tid[i], NULL, threadfunc, &val);
+#endif
ATF_REQUIRE(rv == 0);
rv = pthread_join(tid[i], NULL);
Modified: head/lib/libc/gen/nice.3
==============================================================================
--- head/lib/libc/gen/nice.3 Sat Feb 28 17:44:31 2015 (r279396)
+++ head/lib/libc/gen/nice.3 Sat Feb 28 18:22:10 2015 (r279397)
@@ -28,7 +28,7 @@
.\" @(#)nice.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd February 22, 2015
+.Dd February 28, 2015
.Dt NICE 3
.Os
.Sh NAME
@@ -48,9 +48,9 @@ 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 .
+function adds
+.Fa incr
+to the scheduling priority of the process.
The priority is a value in the range -20 to 20.
The default priority is 0; lower priorities cause more favorable scheduling.
Only the super-user may lower priorities.
@@ -60,8 +60,9 @@ Children inherit the priority of their p
.Sh RETURN VALUES
Upon successful completion,
.Fn nice
-returns the new nice value minus
-.Dv NZERO .
+returns 0, and
+.Va errno
+is unchanged.
Otherwise, \-1 is returned, the process' nice value is not changed, and
.Va errno
is set to indicate the error.
@@ -84,7 +85,11 @@ argument is negative and the caller does
The
.Fn nice
function conforms to
-.St -xpg4.2 .
+.St -p1003.1-2008
+except for the return value.
+This implementation returns 0 upon successful completion but
+the standard requires returning the new nice value,
+which could be \-1.
.Sh HISTORY
A
.Fn nice
Modified: head/lib/libc/gen/nice.c
==============================================================================
--- head/lib/libc/gen/nice.c Sat Feb 28 17:44:31 2015 (r279396)
+++ head/lib/libc/gen/nice.c Sat Feb 28 18:22:10 2015 (r279397)
@@ -45,16 +45,18 @@ __FBSDID("$FreeBSD$");
int
nice(int incr)
{
- int prio;
+ int saverrno, prio;
+ saverrno = errno;
errno = 0;
prio = getpriority(PRIO_PROCESS, 0);
- if (prio == -1 && errno)
- return -1;
+ if (prio == -1 && errno != 0)
+ return (-1);
if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) {
if (errno == EACCES)
errno = EPERM;
- return -1;
+ return (-1);
}
- return getpriority(PRIO_PROCESS, 0);
+ errno = saverrno;
+ return (0);
}
More information about the svn-src-all
mailing list