about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexey Kodanev <aleksei.kodanev@bell-sw.com>2021-06-29 16:31:30 +0300
committerRich Felker <dalias@aerifal.cx>2022-03-08 17:15:14 -0500
commit3aba2150d0efc80df30d7fc6c22d6041e14d445e (patch)
tree3a419d0ed075b26521d99b34356fa12c7d660fca /src
parent74a28a8af21977ebbc2945beb879f1b9b6ff13ba (diff)
downloadmusl-3aba2150d0efc80df30d7fc6c22d6041e14d445e.tar.gz
musl-3aba2150d0efc80df30d7fc6c22d6041e14d445e.tar.xz
musl-3aba2150d0efc80df30d7fc6c22d6041e14d445e.zip
nice: return EPERM instead of EACCES
To comply with POSIX, change errno from EACCES to EPERM
when the caller did not have the required privilege.
Diffstat (limited to 'src')
-rw-r--r--src/unistd/nice.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/unistd/nice.c b/src/unistd/nice.c
index 6c25c8c3..1c2295ff 100644
--- a/src/unistd/nice.c
+++ b/src/unistd/nice.c
@@ -1,4 +1,5 @@
 #include <unistd.h>
+#include <errno.h>
 #include <sys/resource.h>
 #include <limits.h>
 #include "syscall.h"
@@ -12,5 +13,11 @@ int nice(int inc)
 		prio += getpriority(PRIO_PROCESS, 0);
 	if (prio > NZERO-1) prio = NZERO-1;
 	if (prio < -NZERO) prio = -NZERO;
-	return setpriority(PRIO_PROCESS, 0, prio) ? -1 : prio;
+	if (setpriority(PRIO_PROCESS, 0, prio)) {
+		if (errno == EACCES)
+			errno = EPERM;
+		return -1;
+	} else {
+		return prio;
+	}
 }