From patchwork Thu Sep 18 21:16:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 390980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B551814016B for ; Fri, 19 Sep 2014 07:14:32 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=g9WtpSTs4+t9aqCqqct/mF9QpDpMc nz8Lenyvly0qHMUw6JhdkZCF0AZT5O89EwUD2JqMxPPeGOPhNyAqq+CXDwUvkHjd +HkLcYBMr2zIa/1MwFJuPpBVYzfRDcRayir2bsteEUylP+7Q3r604pDhDWncjVhh QW3iZQZ32E81vM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=zvXwvks8xKbOAGUIe/JZLz+qyE0=; b=ena 2eK+2juP3gtOS4Xwv3dTamnYbGxqQ6mVb5BrAsRXBukH2dMabtePKsgsZd1y/0Rw 967SGeM35Z94UaSYCc4zJOf4gj3j7LpBgD3VWMuqsBIw6jSMg/68+fm912hLejsP jC7Ib4UWBU/LQ0eI0AINb1pB9/tVQ4/5GFZEbtZw= Received: (qmail 27486 invoked by alias); 18 Sep 2014 21:14:26 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 27472 invoked by uid 89); 18 Sep 2014 21:14:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_20, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: arati.lostca.se Date: Thu, 18 Sep 2014 23:16:00 +0200 From: Arjun Shankar To: libc-alpha@sourceware.org Subject: [PATCH] Write errors to stdout and not stderr in nptl/tst-setuid3.c Message-ID: <20140918231600.642a0c3a@zion> Mime-Version: 1.0 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-18 Arjun Shankar * nptl/tst-setuid3.c: Write errors to stdout. --- nptl/tst-setuid3.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/nptl/tst-setuid3.c b/nptl/tst-setuid3.c index f78f485..6077aa1 100644 --- a/nptl/tst-setuid3.c +++ b/nptl/tst-setuid3.c @@ -15,11 +15,12 @@ License along with the GNU C Library; if not, see . */ -#include #include #include #include #include +#include +#include /* The test must run under a non-privileged user ID. */ static const uid_t test_uid = 1; @@ -27,15 +28,26 @@ 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 ": %s\n", __VA_ARGS__, strerror (errno)); \ + _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 +58,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 +73,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; }