On Mon, 15 May 2023 16:11:46 GMT, Volker Simonis <simo...@openjdk.org> wrote:
> > 2. I think you don't actually have to hand in the in-pipe-read-end fd > > number via command line arg, just to have the child to close it. You could > > just, in the parent, set the fd to FD_CLOEXEC. Since posix_spawn() exec's > > the spawn helper, this would close the file descriptor for you. Extending > > this thought, you could do this with all pipe ends you want to cauterize in > > the child process. > > I've deliberately not used `FD_CLOEXEC` because the file descriptor closing > code in `childProcess()` is shared by all launch mechanisms. So to make it > work, I'd had to reset the corresponding file descriptors to `-1` in the > child anyway. > > I therefor felt the current fix is smaller, simpler and easier to understand. I don't understand what you mean. A) vfork, fork: `(parent)->fork()->(child)->childProcess()` B) posix_spawn: `(parent)->posix_spawn()(does clone() then exec())->jspawnhelper main()->childProcess()` With your patch, you close the offending fd in `jspawnhelper main()`. With my suggestion, it would be closed on the `exec` call `posix_spawn` does. Neither variant affects the working of vfork/fork mode. Am I missing something? ------------- PR Comment: https://git.openjdk.org/jdk/pull/13956#issuecomment-1549274987