Bug 29459 - fwrite does not return EPIPE when underlying write fails with EPIPE.
Summary: fwrite does not return EPIPE when underlying write fails with EPIPE.
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: stdio (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-08 17:32 UTC by Carlos O'Donell
Modified: 2022-08-08 19:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
test-fwrite.c (595 bytes, text/x-csrc)
2022-08-08 17:33 UTC, Carlos O'Donell
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos O'Donell 2022-08-08 17:32:57 UTC
This was reported downstream for CentOS 9 Stream here:
https://bugzilla.redhat.com/show_bug.cgi?id=2112672

The issue is an upstream issue that needs review.

The test case is attached from the downstream issue.

An strace shows the issue clearly:

1659979752.806415 write(1, "hello\n", 6) = 6
1659979752.806467 write(2, "1. fwrite wrote 6 bytes and ferror is 0\n", 40) = 40
1659979752.806517 write(1, "hello\n", 6) = -1 EPIPE (Broken pipe)
1659979752.806548 --- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=202616, si_uid=1000} ---
1659979752.806563 write(2, "2. fwrite wrote 6 bytes and ferror is 1\n", 40) = 40

The underlying write fails with EPIPE, but fwrite doesn't itself fail.
Comment 1 Carlos O'Donell 2022-08-08 17:33:45 UTC
Created attachment 14264 [details]
test-fwrite.c
Comment 2 Carlos O'Donell 2022-08-08 17:35:22 UTC
POSIX says it shall fail with EPIPE:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fputc.html#
"An attempt is made to write to a pipe or FIFO that is not open for reading by any process. A SIGPIPE signal shall also be sent to the thread."
Comment 3 Andreas Schwab 2022-08-08 17:50:45 UTC
How exactly is the test program called?
Comment 4 Carlos O'Donell 2022-08-08 19:19:11 UTC
(In reply to Andreas Schwab from comment #3)
> How exactly is the test program called?

./fwrite -l hello 5000 | head -n1

Such that head terminates and closes the pipe after reading one line.