summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/nice.c
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2017-02-09 21:19:24 +0000
committerngie <ngie@FreeBSD.org>2017-02-09 21:19:24 +0000
commitd881b8eb8843bab6213c03d985c02dbbff945c39 (patch)
tree4ddaae7df858c39d4efe649e53a1d9ba02673ff0 /lib/libc/gen/nice.c
parentc286d65a4db083caf43ec32fa9241865aa1293d2 (diff)
downloadFreeBSD-src-d881b8eb8843bab6213c03d985c02dbbff945c39.zip
FreeBSD-src-d881b8eb8843bab6213c03d985c02dbbff945c39.tar.gz
MFC r279154,r279397:
r279154 (by jilles): nice(): Correct return value and [EPERM] error. PR: 189821 Obtained from: NetBSD Relnotes: yes r279397 (by jilles): 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 Relnotes: yes
Diffstat (limited to 'lib/libc/gen/nice.c')
-rw-r--r--lib/libc/gen/nice.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/libc/gen/nice.c b/lib/libc/gen/nice.c
index e8375e8..ba9524b 100644
--- a/lib/libc/gen/nice.c
+++ b/lib/libc/gen/nice.c
@@ -43,14 +43,20 @@ __FBSDID("$FreeBSD$");
* Backwards compatible nice.
*/
int
-nice(incr)
- int incr;
+nice(int incr)
{
- int prio;
+ int saverrno, prio;
+ saverrno = errno;
errno = 0;
prio = getpriority(PRIO_PROCESS, 0);
- if (prio == -1 && errno)
+ if (prio == -1 && errno != 0)
return (-1);
- return (setpriority(PRIO_PROCESS, 0, prio + incr));
+ if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) {
+ if (errno == EACCES)
+ errno = EPERM;
+ return (-1);
+ }
+ errno = saverrno;
+ return (0);
}
OpenPOWER on IntegriCloud