[newlib-cygwin/main] Cygwin: nice: align return value and errno with POSIX and Linux

Corinna Vinschen corinna@sourceware.org
Fri Nov 29 09:57:34 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=6adfb1fc28dd22f3f63fbedd40f73337e97e17f8

commit 6adfb1fc28dd22f3f63fbedd40f73337e97e17f8
Author:     Christian Franke <christian.franke@t-online.de>
AuthorDate: Wed Nov 27 18:54:37 2024 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Thu Nov 28 21:58:50 2024 +0100

    Cygwin: nice: align return value and errno with POSIX and Linux
    
    Return new nice value instead of 0 on success.
    Set errno to EPERM instead of EACCES on failure.
    
    Signed-off-by: Christian Franke <christian.franke@t-online.de>

Diff:
---
 winsup/cygwin/release/3.6.0 |  4 ++++
 winsup/cygwin/syscalls.cc   | 11 ++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/release/3.6.0 b/winsup/cygwin/release/3.6.0
index ef7e4018fbd2..1b2f00ad8fd6 100644
--- a/winsup/cygwin/release/3.6.0
+++ b/winsup/cygwin/release/3.6.0
@@ -48,3 +48,7 @@ What changed:
   or EPERM if Windows would silently set a lower priority
   (HIGH_PRIORITY_CLASS instead of REALTIME_PRIORITY_CLASS) due to
   missing administrator privileges.
+
+- nice(2) now returns the new nice value instead of 0 on success
+  and sets errno to EPERM instead of EACCES on failure.  This confirms
+  to POSIX and Linux (glibc >= 2.2.4) behavior.
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 72537bc5ad52..60350b6904b2 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -3959,7 +3959,16 @@ out:
 extern "C" int
 nice (int incr)
 {
-  return setpriority (PRIO_PROCESS, myself->pid, myself->nice + incr);
+  if (setpriority (PRIO_PROCESS, myself->pid, myself->nice + incr))
+    {
+      /* POSIX: EPERM instead of EACCES. */
+      set_errno (EPERM);
+      return -1;
+    }
+
+  /* POSIX: return the new nice value.  Linux glibc >= 2.2.4 provides
+     conformance with POSIX (FreeBSD returns 0). */
+  return myself->nice;
 }
 
 static void


More information about the Cygwin-cvs mailing list