All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiao Yang <yangx.jy@cn.fujitsu.com>
To: fstests@vger.kernel.org
Cc: libc-alpha-help@sourceware.org, Xiao Yang <yangx.jy@cn.fujitsu.com>
Subject: [PATCH] generic/486: print correct errno
Date: Wed, 16 May 2018 16:00:04 +0800	[thread overview]
Message-ID: <1526457604-10060-1-git-send-email-yangx.jy@cn.fujitsu.com> (raw)

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 <errno.h>
#include <unistd.h>
#include <stdio.h>

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 <yangx.jy@cn.fujitsu.com>
---
 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 <sys/xattr.h>
 #include <sys/stat.h>
 
-#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 { \
-- 
1.8.3.1




             reply	other threads:[~2018-05-16  8:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-16  8:00 Xiao Yang [this message]
2018-05-16 15:27 ` [PATCH] generic/486: print correct errno Darrick J. Wong
2018-05-17  1:36   ` [PATCH] generic/486: Get rid of the redundant error=%d printing Xiao Yang
2018-05-17  3:16     ` Eryu Guan
2018-05-17  3:25       ` Xiao Yang
2018-05-17  3:32       ` [PATCH v3] " Xiao Yang
2018-05-17 14:55         ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1526457604-10060-1-git-send-email-yangx.jy@cn.fujitsu.com \
    --to=yangx.jy@cn.fujitsu.com \
    --cc=fstests@vger.kernel.org \
    --cc=libc-alpha-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.