diff mbox

Fix BZ #18086 (nice resets errno to 0)

Message ID CALoOobMuFTR9PZbr-C0AMuZPtxDrcqAk9NcmqqX_hNcX-NS5gQ@mail.gmail.com
State New
Headers show

Commit Message

Paul Pluzhnikov Aug. 10, 2015, 3:02 a.m. UTC
On Sun, Aug 9, 2015 at 7:19 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> 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 ?

That would be logical.

Revised patch attached.

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, 3:10 a.m. UTC | #1
lgtm ... i'll push in a while if no one else pipes up
-mike
diff mbox

Patch

diff --git a/posix/tst-nice.c b/posix/tst-nice.c
index ac78d60..814891d 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 = %i, but wanted EBADF (%i)\n", errno, EBADF);
+      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..8f6daaf 100644
--- a/sysdeps/posix/nice.c
+++ b/sysdeps/posix/nice.c
@@ -36,16 +36,16 @@  nice (int incr)
     {
       if (errno != 0)
 	return -1;
-      else
-	__set_errno (save);
     }
 
   result = __setpriority (PRIO_PROCESS, 0, prio + incr);
   if (result == -1)
     {
       if (errno == EACCES)
-	errno = EPERM;
+	__set_errno (EPERM);
       return -1;
     }
+
+  __set_errno (save);
   return __getpriority (PRIO_PROCESS, 0);
 }