public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] Write errors to stdout and not stderr in nptl/tst-setuid3.c
@ 2014-09-19 10:05 Arjun Shankar
  2014-09-23 14:37 ` Florian Weimer
  0 siblings, 1 reply; 4+ messages in thread
From: Arjun Shankar @ 2014-09-19 10:05 UTC (permalink / raw)
  To: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 621 bytes --]

nptl/tst-setuid3.c was using the `err' and `errx' functions to write
error messages. This wrote to stderr instead of the preferred stdout.

This patch should fix that.

ChangeLog:

2014-09-19  Arjun Shankar  <arjun.is@lostca.se>

	* nptl/tst-setuid3.c: Write errors to stdout.
---
 nptl/tst-setuid3.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

Changes in v2:
 - incorporate Florian's review comment: use %m to write errno string;
   Note: Seems there are many tests that write to stderr. I will look
   at them during the coming week(s) when I find a good chunk of time.

[-- Attachment #2: 0001-nptl-tst-setuid3.c-Write-to-stdout-not-stderr.patch --]
[-- Type: text/x-patch, Size: 3454 bytes --]

diff --git a/nptl/tst-setuid3.c b/nptl/tst-setuid3.c
index f78f485..a48d742 100644
--- a/nptl/tst-setuid3.c
+++ b/nptl/tst-setuid3.c
@@ -15,7 +15,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <err.h>
+#include <stdio.h>
 #include <errno.h>
 #include <pthread.h>
 #include <stdbool.h>
@@ -27,15 +27,21 @@ static const uid_t test_uid = 1;
 static pthread_barrier_t barrier1;
 static pthread_barrier_t barrier2;
 
+#define FAIL(fmt, ...) \
+  do { printf ("FAIL: " fmt "\n", __VA_ARGS__); _exit (1); } while (0)
+
+#define FAIL_ERR(fmt, ...) \
+  do { printf ("FAIL: " fmt ": %m\n", __VA_ARGS__); _exit (1); } while (0)
+
 static void *
 thread_func (void *ctx __attribute__ ((unused)))
 {
   int ret = pthread_barrier_wait (&barrier1);
   if (ret != PTHREAD_BARRIER_SERIAL_THREAD && ret != 0)
-    errx (1, "pthread_barrier_wait (barrier1) (on thread): %d", ret);
+    FAIL ("pthread_barrier_wait (barrier1) (on thread): %d", ret);
   ret = pthread_barrier_wait (&barrier2);
   if (ret != PTHREAD_BARRIER_SERIAL_THREAD && ret != 0)
-    errx (1, "pthread_barrier_wait (barrier2) (on thread): %d", ret);
+    FAIL ("pthread_barrier_wait (barrier2) (on thread): %d", ret);
   return NULL;
 }
 
@@ -46,13 +52,13 @@ setuid_failure (int phase)
   switch (ret)
     {
     case 0:
-      errx (1, "setuid succeeded unexpectedly in phase %d", phase);
+      FAIL ("setuid succeeded unexpectedly in phase %d", phase);
     case -1:
       if (errno != EPERM)
-	err (1, "setuid phase %d", phase);
+	FAIL_ERR ("setuid phase %d", phase);
       break;
     default:
-      errx (1, "invalid setuid return value in phase %d: %d", phase, ret);
+      FAIL ("invalid setuid return value in phase %d: %d", phase, ret);
     }
 }
 
@@ -61,41 +67,41 @@ do_test (void)
 {
   if (getuid () == 0)
     if (setuid (test_uid) != 0)
-      err (1, "setuid (%u)", (unsigned) test_uid);
+      FAIL_ERR ("setuid (%u)", (unsigned) test_uid);
   if (setuid (getuid ()))
-    err (1, "setuid (getuid ())");
+    FAIL_ERR ("setuid (%s)", "getuid ()");
   setuid_failure (1);
 
   int ret = pthread_barrier_init (&barrier1, NULL, 2);
   if (ret != 0)
-    errx (1, "pthread_barrier_init (barrier1): %d", ret);
+    FAIL ("pthread_barrier_init (barrier1): %d", ret);
   ret = pthread_barrier_init (&barrier2, NULL, 2);
   if (ret != 0)
-    errx (1, "pthread_barrier_init (barrier2): %d", ret);
+    FAIL ("pthread_barrier_init (barrier2): %d", ret);
 
   pthread_t thread;
   ret = pthread_create (&thread, NULL, thread_func, NULL);
   if (ret != 0)
-    errx (1, "pthread_create: %d", ret);
+    FAIL ("pthread_create: %d", ret);
 
   /* Ensure that the thread is running properly.  */
   ret = pthread_barrier_wait (&barrier1);
   if (ret != 0)
-    errx (1, "pthread_barrier_wait (barrier1): %d", ret);
+    FAIL ("pthread_barrier_wait (barrier1): %d", ret);
 
   setuid_failure (2);
 
   /* Check success case. */
   if (setuid (getuid ()) != 0)
-    err (1, "setuid (getuid ())");
+    FAIL_ERR ("setuid (%s)", "getuid ()");
 
   /* Shutdown.  */
   ret = pthread_barrier_wait (&barrier2);
   if (ret != PTHREAD_BARRIER_SERIAL_THREAD && ret != 0)
-    errx (1, "pthread_barrier_wait (barrier2): %d", ret);
+    FAIL ("pthread_barrier_wait (barrier2): %d", ret);
 
   if (ret != PTHREAD_BARRIER_SERIAL_THREAD && ret != 0)
-    errx (1, "pthread_join: %d", ret);
+    FAIL ("pthread_join: %d", ret);
 
   return 0;
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Write errors to stdout and not stderr in nptl/tst-setuid3.c
  2014-09-19 10:05 [PATCH v2] Write errors to stdout and not stderr in nptl/tst-setuid3.c Arjun Shankar
@ 2014-09-23 14:37 ` Florian Weimer
  2014-10-01 14:47   ` [ping][PATCH " Arjun Shankar
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2014-09-23 14:37 UTC (permalink / raw)
  To: Arjun Shankar, libc-alpha

On 09/19/2014 12:07 PM, Arjun Shankar wrote:
> nptl/tst-setuid3.c was using the `err' and `errx' functions to write
> error messages. This wrote to stderr instead of the preferred stdout.
>
> This patch should fix that.
>
> ChangeLog:
>
> 2014-09-19  Arjun Shankar  <arjun.is@lostca.se>
>
> 	* nptl/tst-setuid3.c: Write errors to stdout.

Looks good to me, thanks.

-- 
Florian Weimer / Red Hat Product Security

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ping][PATCH v2] Write errors to stdout and not stderr in nptl/tst-setuid3.c
  2014-09-23 14:37 ` Florian Weimer
@ 2014-10-01 14:47   ` Arjun Shankar
  2014-10-06  8:41     ` Siddhesh Poyarekar
  0 siblings, 1 reply; 4+ messages in thread
From: Arjun Shankar @ 2014-10-01 14:47 UTC (permalink / raw)
  To: libc-alpha; +Cc: Florian Weimer

Ping! Florian has already looked at this patch.

On Tue, 23 Sep 2014 16:37:35 +0200
Florian Weimer <fweimer@redhat.com> wrote:

> On 09/19/2014 12:07 PM, Arjun Shankar wrote:
> > nptl/tst-setuid3.c was using the `err' and `errx' functions to write
> > error messages. This wrote to stderr instead of the preferred stdout.
> >
> > This patch should fix that.
> >
> > ChangeLog:
> >
> > 2014-09-19  Arjun Shankar  <arjun.is@lostca.se>
> >
> > 	* nptl/tst-setuid3.c: Write errors to stdout.
> 
> Looks good to me, thanks.
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ping][PATCH v2] Write errors to stdout and not stderr in nptl/tst-setuid3.c
  2014-10-01 14:47   ` [ping][PATCH " Arjun Shankar
@ 2014-10-06  8:41     ` Siddhesh Poyarekar
  0 siblings, 0 replies; 4+ messages in thread
From: Siddhesh Poyarekar @ 2014-10-06  8:41 UTC (permalink / raw)
  To: Arjun Shankar; +Cc: libc-alpha, Florian Weimer

[-- Attachment #1: Type: text/plain, Size: 192 bytes --]

On Wed, Oct 01, 2014 at 04:49:15PM +0200, Arjun Shankar wrote:
> Ping! Florian has already looked at this patch.
> 


I thought Florian would have committed it.  I have now.

Siddhesh

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-10-06  8:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-19 10:05 [PATCH v2] Write errors to stdout and not stderr in nptl/tst-setuid3.c Arjun Shankar
2014-09-23 14:37 ` Florian Weimer
2014-10-01 14:47   ` [ping][PATCH " Arjun Shankar
2014-10-06  8:41     ` Siddhesh Poyarekar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).