Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sh_exec(): remove a vfork(2) use for the >; redirection
vfork has been removed from the POSIX standard and macOS gives a deprecation warning for it. Additionally, the old (2004) POSIX spec for it states: https://pubs.opengroup.org/onlinepubs/009696799/functions/vfork.html | The vfork() function shall be equivalent to fork(), except that | the behavior is undefined if the process created by vfork() | either modifies any data other than a variable of type pid_t used | to store the return value from vfork(), or returns from the | function in which vfork() was called, or calls any other function | before successfully calling _exit() or one of the exec family of | functions. According to that spec, this vfork(2) usage was very much engaged in undefined behaviour, as the first thing it does after vforking is call _sh_fork(), and it never calls an exec function. The lib_vfork feature test in src/lib/libast/features/lib does try to verify that vfork works and does not merely exist, but it does not attempt to run anything substantial in the child process (besides, 'undefined behaviour' does not mean the test would necessarily fail). That test may be good enough for the spawnveg(3) vfork fallback, but it is inherently unreliable for determining if we can run anything substantial in the child. (This if(rewrite) code block is used when the >; redirection operator (IOREWRITE) is used with an external command. It won't work without the extra (v)fork, as the external command will be replacing the ksh child process but ksh needs to decide if the command succeeds before rewriting the output from a temp file.)
- Loading branch information