From: Joseph Myers <josmyers@redhat.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: Document further requirement on mixing streams / file descriptors
Date: Thu, 26 Sep 2024 22:39:30 +0000 (UTC) [thread overview]
Message-ID: <e05a4e05-e460-2aca-b287-c63f3f3362a3@redhat.com> (raw)
In-Reply-To: <87v7yi95v0.fsf@oldenburg.str.redhat.com>
On Thu, 26 Sep 2024, Florian Weimer wrote:
> I do not think this rules accurate. The standard streams are linked
> channels, typically with descriptors for the file description in the
> parent process. They are streams. A freshly started program does not
> know if another program seeked any of the descriptors before. Does this
> mean programs need to add fseek calls for the standard streams? What if
> those streams are not seekable?
This seems like it might be an omission in the POSIX specification.
What I'd expect is: after execve, the standard streams are set up from the
relevant file descriptors. If the previous process seeked on a handle for
that open file description, then it (possibly in the child after fork)
must make the file descriptor active, including seeking on it to get a
defined offset, but then after execve nothing more is needed regarding
seeking on the stream (assuming that other processes aren't using the
same open file description at the same time).
I can't however find anything in POSIX that says that this is what happens
with handles for file descriptors 0, 1, 2 on execve (and, in particular,
that the requirement to seek on the stream does not apply). If we think
this is what the semantics should be for glibc, we could still document it
as such.
> I think we have a step missing in the cleaning process: the new channel
> may indeed need seeking. The current manual suggests that cleaning is
> only needed on the old channel, but I don't think this is accurate, for
> both linked and independent channels. For example, an input stream may
> have old file contents buffered.
For an input stream with old contents buffered (that is the new, linked
handle), I think it would have been the active handle earlier, and so have
needed to be cleaned when it ceased to be the active handle. (In the case
of independent channels, the manual already says "You should clean an
input stream before reading data that may have been modified using an
independent channel. Otherwise, you might read obsolete data that had
been in the stream's buffer.".)
--
Joseph S. Myers
josmyers@redhat.com
next prev parent reply other threads:[~2024-09-26 22:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-25 21:28 Joseph Myers
2024-09-26 8:28 ` Florian Weimer
2024-09-26 22:39 ` Joseph Myers [this message]
2024-09-30 10:10 ` Florian Weimer
2024-10-07 22:58 ` Joseph Myers
2024-10-25 16:12 ` Ping " Joseph Myers
2024-10-28 15:39 ` Florian Weimer
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=e05a4e05-e460-2aca-b287-c63f3f3362a3@redhat.com \
--to=josmyers@redhat.com \
--cc=fweimer@redhat.com \
--cc=libc-alpha@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 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).