On Tue, Jun 30, 2026 at 01:29:11PM +0000, Sertonix wrote:
> Hi,
>
> reading some skalibs documentation and was wonder why sanitize_read does
> not remap EPIPE to a different errno, avoid any possibility of state
> confusion? Since "everything" can be a fd, I have seen too many unexpected
> errno set by read/write that I would expect EPIPE to be possible as well.
So the way I read the code, the spirit of sanitize_read() is basically
"let's treat a return value of 0 exactly the same way as -1 and EPIPE",
i.e. "let's treat any indication that we cannot read any more, for
any reason, in the same way, so the caller doesn't need to check for
two things". I guess the logic here is that most programs that use
skalibs really don't care whether they are reading from a regular
file, a pipe, a Unix-domain socket, or anything else; all they want
to know is "did we read another chunk, or are we done reading".
So I agree with that part - I agree that, in this case, it is sensible to
treat read() returning 0 in exactly the same way as read() returning -1
with errno set to EPIPE. Now the other part - whether to treat that
situation as an error (what sanitize_read() does now) or as something
that is basically fine (reset errno to 0 and return 0) - is more of
a philosophical/design decision. Apparently the author decided that,
for this suite of programs, it makes more sense to treat end of input
as an error.
Now, changing that - besides needing to convince the author that
the philosophical/design decision needs reevaluating - would mean going
through all of the skalibs code and all of the code of other programs that
use sanitize_read(), and changing all the current checks for
errno == EPIPE to checks for sanitize_read() returning 0 (changing
the semantics of sanitize_read() in this way would also be both
an API breakage and an ABI one). But even before one embarks on such
a quest, the prior question - are the current semantics wrong - should
be answered first :)
And for the record, I agree with you about read() being able to
return many different kinds of error codes on different platforsm and
different file descriptors, and IMHO this is fine - after all, reading
from a regular file is fundamentally different from reading from
a pipe, a FIFO, or a Unix-domain socket, not even to mention reading
from an established TCP connection. Still, the EPIPE return value of
sanitize_read() is a deliberate design choice, and IMHO a good one;
thus, anyone who uses sanitize_read() already has to know about it :)
G'luck,
Peter
--
Peter Pentchev roam_at_ringlet.net roam_at_debian.org peter_at_morpheusly.com
PGP key: https://www.ringlet.net/roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13
Received on Tue Jun 30 2026 - 17:38:40 CEST