This is needed to allow bitcoin-gui to connect to existing node process with -ipcconnect instead of spawning a new process. It's possible to spawn a new bitcoin-node process without knowing the current data dir or network, but connecting to an existing bitcoin-node requires knowing the datadir and network first.
Completes backport (4/4) of bitcoin-core/gui PR35:
https://github.com/bitcoin-core/gui/pull/35/commits/519cae8fd6e44aef3470415d7c5e12acb0acd9f4
Depends on D8655.