From patchwork Wed May 16 08:00:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 10402967 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6D4DF601D2 for ; Wed, 16 May 2018 08:11:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FEBE287CC for ; Wed, 16 May 2018 08:11:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54748287F5; Wed, 16 May 2018 08:11:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC159287CC for ; Wed, 16 May 2018 08:11:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752689AbeEPILq (ORCPT ); Wed, 16 May 2018 04:11:46 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:22082 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752101AbeEPILo (ORCPT ); Wed, 16 May 2018 04:11:44 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="39989779" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 May 2018 16:11:42 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id E911E4B3EF17; Wed, 16 May 2018 16:11:36 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.185) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.399.0; Wed, 16 May 2018 16:11:36 +0800 From: Xiao Yang To: CC: , Xiao Yang Subject: [PATCH] generic/486: print correct errno Date: Wed, 16 May 2018 16:00:04 +0800 Message-ID: <1526457604-10060-1-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.185] X-yoursite-MailScanner-ID: E911E4B3EF17.ACBCB X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On glibc v2.12 or v2.17, running generic/486 with XFS got wrong EINVAL instead of ENODATA: ---------------------------------------------------------------- QA output created by 486 No data available error=22 at line 63 ---------------------------------------------------------------- We want to save the correct errno and print it after calling perror(). It seems that only calling perror() didn't change the errno, but calling perror() and redirecting the output of perror() to a file set errno to EINVAL. For example, running the special test.c to reproduce the issue: ------------------------------------------------------------ #include #include #include int main(void) { close(-1); printf("errno %d before\n", errno); perror(""); printf("errno %d after\n", errno); } ------------------------------------------------------------ # gcc -o test test.c # ./test # ./test 2>log fdopen() called by perror() in glibc seems to set errno to EINVAL in some cases(e.g. the access mode of stderr is O_WRONLY). I am not sure whether this is a perror bug in glibc or not. Signed-off-by: Xiao Yang --- src/attr_replace_test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/attr_replace_test.c b/src/attr_replace_test.c index 23adc07..e9a08cc 100644 --- a/src/attr_replace_test.c +++ b/src/attr_replace_test.c @@ -10,8 +10,9 @@ #include #include -#define die() do { perror(""); \ -fprintf(stderr, "error=%d at line %d\n", errno, __LINE__); \ +#define die() do { int real_errno = errno; \ +perror(""); \ +fprintf(stderr, "error=%d at line %d\n", real_errno, __LINE__); \ exit(1); } while (0) #define fail(...) do { \