This adds a -daemonwait
flag that does the same as -daemon
except that it, from a user perspective, backgrounds the process only after initialization is complete. This is similar to the behaviour of some other software such as c-lightning.
This can be useful when the process launching bitcoind wants to guarantee that either the RPC server is running, or that initialization failed, before continuing. The exit code indicates the initialization result.
The use of the libc function daemon()
is replaced by a custom implementation which is inspired by the glibc implementation, but which also creates a pipe from the child to the parent process for communication.
An additional advantage of having our own daemon()
implementation is that no MACOS-specific pragmas are needed anymore to silence a deprecation warning.
TODO:
-
Factor out
token_read
andtoken_write
to an utility, and use them inshutdown.cpp
as well—this is exactly the same kind of communication mechanism.- RAII-ify pipe endpoints.
-
Improve granularity of the
configure.ac
checks. This currently still checks for the functiondaemon()
which makes no sense as it’s not used. It should check for individual functions such asfork()
andsetsid()
etc—the former being required, the second optional. -
[-]
Signal propagation during initialization: if say, pressing Ctrl-C duringThis is not necessary, see #21007 (comment).-daemonwait
it would be good to pass this SIGINT on to the child process instead of detaching the parent process and letting the child run free.
Future:
- Consider if it makes sense to use this in the RPC tests (there would be no more need for “is RPC ready” polling loops). I think this is out of scope for this PR.