* [musl] putchar not returning EOF even though ferror is set
@ 2025-05-05 13:48 Sertonix
2025-05-05 13:56 ` Rich Felker
2025-05-06 15:27 ` Markus Wichmann
0 siblings, 2 replies; 3+ messages in thread
From: Sertonix @ 2025-05-05 13:48 UTC (permalink / raw)
To: musl
After a function using a FILE stream errors following calls of putchar
(and probably other functions) don't return EOF. This can cause some
busybox applets (like yes(1)) to never stop (when SIGPIPE is ignored in
the environment).
The commit message of e3cd6c5c265c (major stdio overhaul, using
readv/writev, plus other changes) looks like this might have been
intentional.
Does musl consider this something which needs to be changed in busybox
or would it be possible to change musl here?
(If I read the glibc code correctly it checks ferror in some cases?)
Ref https://gitlab.alpinelinux.org/alpine/aports/-/issues/17129
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [musl] putchar not returning EOF even though ferror is set
2025-05-05 13:48 [musl] putchar not returning EOF even though ferror is set Sertonix
@ 2025-05-05 13:56 ` Rich Felker
2025-05-06 15:27 ` Markus Wichmann
1 sibling, 0 replies; 3+ messages in thread
From: Rich Felker @ 2025-05-05 13:56 UTC (permalink / raw)
To: Sertonix; +Cc: musl
On Mon, May 05, 2025 at 01:48:42PM +0000, Sertonix wrote:
>
> After a function using a FILE stream errors following calls of putchar
> (and probably other functions) don't return EOF. This can cause some
> busybox applets (like yes(1)) to never stop (when SIGPIPE is ignored in
> the environment).
>
> The commit message of e3cd6c5c265c (major stdio overhaul, using
> readv/writev, plus other changes) looks like this might have been
> intentional.
>
> Does musl consider this something which needs to be changed in busybox
> or would it be possible to change musl here?
>
> (If I read the glibc code correctly it checks ferror in some cases?)
>
> Ref https://gitlab.alpinelinux.org/alpine/aports/-/issues/17129
There is no specification anywhere in C or POSIX (the latter wouldn't
really matter since POSIX is aligned with C and can't make
requirements contradictory to it, but checking can be informative
anyway) that the error indicator being set for a stream causes further
writes to fail. glibc doing that appears to just be something they...
made up?
This is in contrast to the EOF status for read operations, which is
required to be "sticky" and cause future read attempts to return EOF.
Applications that want to stop when an error has been encountered
should check the return value of the writing function or check
ferror().
Rich
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [musl] putchar not returning EOF even though ferror is set
2025-05-05 13:48 [musl] putchar not returning EOF even though ferror is set Sertonix
2025-05-05 13:56 ` Rich Felker
@ 2025-05-06 15:27 ` Markus Wichmann
1 sibling, 0 replies; 3+ messages in thread
From: Markus Wichmann @ 2025-05-06 15:27 UTC (permalink / raw)
To: musl; +Cc: Sertonix
Am Mon, May 05, 2025 at 01:48:42PM +0000 schrieb Sertonix:
>
> After a function using a FILE stream errors following calls of putchar
> (and probably other functions) don't return EOF. This can cause some
> busybox applets (like yes(1)) to never stop (when SIGPIPE is ignored in
> the environment).
>
> The commit message of e3cd6c5c265c (major stdio overhaul, using
> readv/writev, plus other changes) looks like this might have been
> intentional.
>
> Does musl consider this something which needs to be changed in busybox
> or would it be possible to change musl here?
>
> (If I read the glibc code correctly it checks ferror in some cases?)
>
> Ref https://gitlab.alpinelinux.org/alpine/aports/-/issues/17129
If it is any consolation: As long as the block size is coprime to one
more than the string length, at some point the application should stop
(because that means that at some point the putchar('\n') will be called
when the buffer is full). But of course, the main case is that the
string is just "y", so the full output is 2 bytes, and that isn't
coprime to 1024.
The glibc behavior here is not conforming. No C standard I could find
specifies it or allows it explicitly. They all say that fputc() writes
the character given to the file, not that it may or may not do so
depending on the whims of the implementor. busybox should change its yes
applett to either test the return values of all the stdio function
called, or else test ferror() as an additional loop exit condition. Or
possibly even in place of the current one (which is that putchar('\n')
returns EOF).
Ciao,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-06 15:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-05 13:48 [musl] putchar not returning EOF even though ferror is set Sertonix
2025-05-05 13:56 ` Rich Felker
2025-05-06 15:27 ` Markus Wichmann
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).