close 990264 thanks On Thu, Jun 24, 2021 at 01:49:55PM +0000, Thorsten Glaser wrote: > Vincent Lefevre dixit: > > >Like with ksh93, output error is not checked for some builtins > >(at least pwd and ulimit), e.g. after closing stdout. > > > >$ exec >&- > >$ for i in echo pwd print ulimit; do echo "[$i]" >&2; $i; echo $? >&2; done > > You have just left POSIX land: > > At program start-up, three streams are predefined and need not be > opened explicitly: standard input (for reading conventional input), > standard output (for writing conventional output), and standard error > (for writing diagnostic output). When opened, the standard error > stream is not fully buffered; the standard input and standard output > streams are fully buffered if and only if the stream can be > determined not to refer to an interactive device. > > At the start of those commands, stdout is closed, so you violate that > constraint. Note POSIX is not just demands on the implementation but > also on the user, for example, it specifically permits extensions where > the behaviour is otherwise unspecified, i.e. which could not happen in > a conforming user.
There was an update on this from the Austin Group that will be in the next version of the POSIX standard relating to the streams that need to be opened at startup. Here's the changed verbiage which is explicit about the streams needing to be "already open": "At program start-up, three streams shall be predefined and already open: stdin (standard input, for conventional input) for reading, stdout (standard output, for conventional output) for writing, and stderr (standard error, for diagnostic output) for writing." [1] Also, some more elaboration by POSIX on unspecified behavior if the standard streams are not open for reading and writing: "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." [2] [1] - https://austingroupbugs.net/view.php?id=1347#c5161 [2] - https://pubs.opengroup.org/onlinepubs/9699919799/functions/execve.html -- Anuradha