From patchwork Fri Jan 12 07:38:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 859544 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-89126-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="j+/IhLZ0"; dkim-atps=neutral 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 3zHvl05TjFz9t2f for ; Fri, 12 Jan 2018 18:39:08 +1100 (AEDT) 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:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= OyxjnKpkgFZomKUcoZXKzt/KiZQZaIgWV4oUMwWWvusyDd7Q6mJ4K8rUUn+rcAzc /RVWYhbN+EwQpX61xk9wt+M6pPU/zZxT6b4HV0cx/SK2gsfQD5xrzJI3BrpA28Sf vhKC0N44KoZum2RUBaBTX13Rid5jMZfyXwK2ejHxyhM= 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:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=tt5LSw DYIzG3ytb0rn32K4EfioI=; b=j+/IhLZ0arUqCtTO93EXx5tcisFq2hUxOEFKH7 WJn7I+3sDzBKu7yw+aukTZLVihbVkkgV/ZUEQIhSDGZsQMdXK7B6KvR9ZJsNgFq5 34deqXyn62TFNXSwnBnqNaRtC5s7Rk/Nml4PEDZqOSEJm4lo38yYE8q0TjCLXy0B Zv0Zs= Received: (qmail 123729 invoked by alias); 12 Jan 2018 07:39:02 -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 123682 invoked by uid 89); 12 Jan 2018 07:39:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Date: Fri, 12 Jan 2018 08:38:57 +0100 To: libc-alpha@sourceware.org Subject: [PATCH] support: Preserve errno in write_message, TEST_VERIFY and other checks User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20180112073857.83A1141A7FDF7@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) These facilities could clobber errno, which makes it difficult to write certain checks because a specific order has to be used. 2018-01-12 Florian Weimer * support/write_message.c (write_message): Preserve errno. * support/check.c (print_failure): Likewise. * support/support_test_verify_impl.c (support_test_verify_impl): Likewise. * support/support_test_compare_failure.c (support_test_compare_failure): Likewise. diff --git a/support/check.c b/support/check.c index 688ed569ac..78f2b3cde1 100644 --- a/support/check.c +++ b/support/check.c @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -26,9 +27,11 @@ static void print_failure (const char *file, int line, const char *format, va_list ap) { + int saved_errno = errno; printf ("error: %s:%d: ", file, line); vprintf (format, ap); puts (""); + errno = saved_errno; } int diff --git a/support/support_test_compare_failure.c b/support/support_test_compare_failure.c index e5596fd121..8eb51c439d 100644 --- a/support/support_test_compare_failure.c +++ b/support/support_test_compare_failure.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #include @@ -44,6 +45,7 @@ support_test_compare_failure (const char *file, int line, int right_positive, int right_size) { + int saved_errno = errno; support_record_failure (); if (left_size != right_size) printf ("%s:%d: numeric comparison failure (widths %d and %d)\n", @@ -52,4 +54,5 @@ support_test_compare_failure (const char *file, int line, printf ("%s:%d: numeric comparison failure\n", file, line); report (" left", left_expr, left_value, left_positive, left_size); report ("right", right_expr, right_value, right_positive, right_size); + errno = saved_errno; } diff --git a/support/support_test_verify_impl.c b/support/support_test_verify_impl.c index 80311a8265..5ff5555a6a 100644 --- a/support/support_test_verify_impl.c +++ b/support/support_test_verify_impl.c @@ -18,14 +18,17 @@ #include +#include #include #include void support_test_verify_impl (const char *file, int line, const char *expr) { + int saved_errno = errno; support_record_failure (); printf ("error: %s:%d: not true: %s\n", file, line, expr); + errno = saved_errno; } void diff --git a/support/write_message.c b/support/write_message.c index 9d0f267a2f..a3e2f90535 100644 --- a/support/write_message.c +++ b/support/write_message.c @@ -18,12 +18,15 @@ #include +#include #include #include void write_message (const char *message) { + int saved_errno = errno; ssize_t unused __attribute__ ((unused)); unused = write (STDOUT_FILENO, message, strlen (message)); + errno = saved_errno; }