浏览代码

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.
Alexey Kodanev 3 年之前
父节点
当前提交
3aba2150d0
共有 1 个文件被更改,包括 8 次插入1 次删除
  1. 8 1
      src/unistd/nice.c

+ 8 - 1
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;
+	}
 }