public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug stdio/28026] New: flushing or closing fdopen'ed socket with mode "r+" sometimes fails with ESPIPE
@ 2021-06-29 20:22 jscott at posteo dot net
  2021-06-29 20:49 ` [Bug stdio/28026] " schwab@linux-m68k.org
  2021-06-29 21:33 ` jscott at posteo dot net
  0 siblings, 2 replies; 3+ messages in thread
From: jscott at posteo dot net @ 2021-06-29 20:22 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28026

            Bug ID: 28026
           Summary: flushing or closing fdopen'ed socket with mode "r+"
                    sometimes fails with ESPIPE
           Product: glibc
           Version: 2.31
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: jscott at posteo dot net
  Target Milestone: ---

Created attachment 13517
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13517&action=edit
an example program demonstrating the issue

Hello,

I've discovered that when using fdopen to get a bidirectional stream from a
socket, if one writes to the buffer while there is still data to be read and
later tries to fflush or fclose it, the function will fail with ESPIPE. It
seems like fflush doesn't consider that one may not be able to seek on the file
descriptor.

Other implementations I've tried, including Musl libc and Cygwin, don't
demonstrate this behavior. I've been careful to not mix unbuffered I/O with the
stream I/O functions, and I've attached a small program that demonstrates the
issue on my Debian GNU/Linux Bullseye system.

This issue was previously noted on Stack Overflow nine years ago:
https://stackoverflow.com/q/10255663

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug stdio/28026] flushing or closing fdopen'ed socket with mode "r+" sometimes fails with ESPIPE
  2021-06-29 20:22 [Bug stdio/28026] New: flushing or closing fdopen'ed socket with mode "r+" sometimes fails with ESPIPE jscott at posteo dot net
@ 2021-06-29 20:49 ` schwab@linux-m68k.org
  2021-06-29 21:33 ` jscott at posteo dot net
  1 sibling, 0 replies; 3+ messages in thread
From: schwab@linux-m68k.org @ 2021-06-29 20:49 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28026

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
You cannot mix fread/fwrite operations without intervening fflush/fseek.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug stdio/28026] flushing or closing fdopen'ed socket with mode "r+" sometimes fails with ESPIPE
  2021-06-29 20:22 [Bug stdio/28026] New: flushing or closing fdopen'ed socket with mode "r+" sometimes fails with ESPIPE jscott at posteo dot net
  2021-06-29 20:49 ` [Bug stdio/28026] " schwab@linux-m68k.org
@ 2021-06-29 21:33 ` jscott at posteo dot net
  1 sibling, 0 replies; 3+ messages in thread
From: jscott at posteo dot net @ 2021-06-29 21:33 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28026

John Scott <jscott at posteo dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |NOTABUG

--- Comment #2 from John Scott <jscott at posteo dot net> ---
(In reply to Andreas Schwab from comment #1)
> You cannot mix fread/fwrite operations without intervening fflush/fseek.

Thanks for your prompt reply, I see that was my mistake. fseek, fgetpos, and
fsetpos all fail on the stream, so it seems that one can't follow up reading
with writing like this at all.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-29 21:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 20:22 [Bug stdio/28026] New: flushing or closing fdopen'ed socket with mode "r+" sometimes fails with ESPIPE jscott at posteo dot net
2021-06-29 20:49 ` [Bug stdio/28026] " schwab@linux-m68k.org
2021-06-29 21:33 ` jscott at posteo dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).