Currently, RunCommandParseJSON
runs its target with whatever fds happen to be open inherited on POSIX platforms. I don’t think there’s any practical scenario where this is a problem right now, but there’s a lot of potential for weird problems (eg, if a process manages to outlive bitcoind - perhaps it’s hanging - the listening port(s) won’t get released and starting bitcoind again will fail). It’s also a potential security issue if a child process is intended to be sandboxed at some point. Not to mention plain ugly :)
Note that boost::process has a boost::process::limit_handles
extension for this, but it requires a newer Boost and is even in the latest version still somewhat broken on Windows (where it probably doesn’t matter since handle inheritance is off by default - but will execute undefined behaviour dereferencing/writing of an end-iterator): https://github.com/boostorg/process/issues/200
Instead of closing directly, we have to set the FD_CLOEXEC
flag and let exec
close them; otherwise, boost::process’s internal pipe would be closed and we get the wrong exception thrown (not actually a problem outside of our tests, but might as well do this cleanly).