diff mbox

Fix BZ #18086 (nice resets errno to 0)

Message ID CAPC3xaoD55Kc9x=JuPnCKqQncSeAXv2+X=Qrd7u7nXFG2usRTQ@mail.gmail.com
State New
Headers show

Commit Message

Paul Pluzhnikov Aug. 9, 2015, 11:28 p.m. UTC
Greetings,

Attached patch fixes BZ #18086 -- nice resets errno to 0 on success.
Tested on Linux/x86_64, no new failures.

Thanks,


2015-08-09  Paul Pluzhnikov  <ppluzhnikov@google.com>

        [BZ #18086]
        * sysdeps/posix/nice.c (nice): Restore old errno.
        * posix/tst-nice.c (do_test): Add test for BZ #18086.

Comments

Mike Frysinger Aug. 10, 2015, 2:19 a.m. UTC | #1
On 09 Aug 2015 16:28, Paul Pluzhnikov wrote:
> +      printf ("FAIL: errno = %d != EBADF\n", errno);

i often find error messages like this hard to parse.  explicit is better:
	printf ("FAIL: errno = %i, but wanted EBADF (%i)\n", errno, EBADF);

> @@ -47,5 +45,7 @@ nice (int incr)
>  	errno = EPERM;

not really related, but shouldn't this use __set_errno ?
-mike
diff mbox

Patch

diff --git a/posix/tst-nice.c b/posix/tst-nice.c
index ac78d60..3b9eb55 100644
--- a/posix/tst-nice.c
+++ b/posix/tst-nice.c
@@ -56,8 +56,17 @@  do_test (void)
       return 1;
     }
 
-  printf ("PASS: nice(%d) from %d return: %d\n", incr, old, ret);
+  /* BZ #18086. Make sure we don't reset errno.  */
+  errno = EBADF;
+  nice (0);
+  if (errno != EBADF)
+    {
+      printf ("FAIL: errno = %d != EBADF\n", errno);
+      return 1;
+    }
+
 
+  printf ("PASS: nice(%d) from %d return: %d\n", incr, old, ret);
   return 0;
 }
 
diff --git a/sysdeps/posix/nice.c b/sysdeps/posix/nice.c
index 42bb99b..4d05c70 100644
--- a/sysdeps/posix/nice.c
+++ b/sysdeps/posix/nice.c
@@ -36,8 +36,6 @@  nice (int incr)
     {
       if (errno != 0)
 	return -1;
-      else
-	__set_errno (save);
     }
 
   result = __setpriority (PRIO_PROCESS, 0, prio + incr);
@@ -47,5 +45,7 @@  nice (int incr)
 	errno = EPERM;
       return -1;
     }
+
+  __set_errno (save);
   return __getpriority (PRIO_PROCESS, 0);
 }