[PATCH v2] Ensure standard file descriptors are open on start
Joseph Myers
joseph@codesourcery.com
Wed Aug 19 16:28:25 GMT 2020
On Wed, 19 Aug 2020, Arsen Arsenović via Libc-alpha wrote:
> ISO C requires that standard input, output and error are always open on
> program startup.
ISO C doesn't talk about file descriptors at all. The objects stdin,
stdout and stderr need to be initialized, but it's fine for all I/O on
them to fail.
> + /* Ensure the standard streams are opened, as required by POSIX and C. For
> + dynamic programs this is already handled in the dynamic loader. */
Please give specific references, not just "as required by POSIX and C".
What exactly do you think requires these descriptors to be open? The
POSIX specification for execve explicitly says "If file descriptor 0, 1,
or 2 would otherwise be closed after a successful call to one of the exec
family of functions, implementations may open an unspecified file for the
file descriptor in the new process image. If a standard utility or a
conforming application is executed with file descriptor 0 not open for
reading or with file descriptor 1 or 2 not open for writing, the
environment in which the utility or application is executed shall be
deemed non-conforming, and consequently the utility or application might
not behave as described in this standard.". So at least that description
of the process of creating a new process image only permits opening those
file descriptors but does not require it and indeed explicitly does not
impose requirements on how code behaves if started with those file
descriptors not open.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/execve.html
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Libc-alpha
mailing list