mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] nice: return EPERM instead of EACCES
@ 2021-06-29 13:31 Alexey Kodanev
  2021-06-29 14:48 ` Rich Felker
  0 siblings, 1 reply; 6+ messages in thread
From: Alexey Kodanev @ 2021-06-29 13:31 UTC (permalink / raw)
  To: musl; +Cc: Alexey Kodanev

To comply with POSIX, change errno from EACCES to EPERM
when the caller did not have the required privilege.
---
 src/unistd/nice.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

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;
+	}
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-08 22:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 13:31 [musl] [PATCH] nice: return EPERM instead of EACCES Alexey Kodanev
2021-06-29 14:48 ` Rich Felker
2021-06-29 15:45   ` Alexey Kodanev
2021-06-29 20:10     ` Rich Felker
2021-08-03  9:18       ` Alexey Kodanev
2022-03-08 22:16         ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).