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.
This commit is contained in:
Alexey Kodanev 2021-06-29 16:31:30 +03:00 committed by Rich Felker
parent 74a28a8af2
commit 3aba2150d0
1 changed files with 8 additions and 1 deletions

View File

@ -1,4 +1,5 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <limits.h> #include <limits.h>
#include "syscall.h" #include "syscall.h"
@ -12,5 +13,11 @@ int nice(int inc)
prio += getpriority(PRIO_PROCESS, 0); prio += getpriority(PRIO_PROCESS, 0);
if (prio > NZERO-1) prio = NZERO-1; if (prio > NZERO-1) prio = NZERO-1;
if (prio < -NZERO) prio = -NZERO; 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;
}
} }