RFR: 8307990: jspawnhelper must close its writing side of a pipe before reading from it

Thomas Stuefe stuefe at openjdk.org
Tue May 16 09:03:48 UTC 2023


On Mon, 15 May 2023 16:11:46 GMT, Volker Simonis <simonis at 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


More information about the core-libs-dev mailing list