bitcoind: Add -daemonwait option to wait for initialization

This adds a `-daemonwait` flag that does the same as `-daemon` except
it, from a user perspective, backgrounds the process only after
initialization is complete.

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.

This replaces the use of the libc function `daemon()` by a custom
implementation which is inspired by the glibc implementation, but 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.
This commit is contained in:
Wladimir J. van der Laan
2021-01-25 22:45:54 +01:00
parent c3e6fdee6d
commit e017a913d0
5 changed files with 128 additions and 18 deletions

View File

@ -92,9 +92,9 @@
don't. */
#define HAVE_DECL_BSWAP_64 0
/* Define to 1 if you have the declaration of `daemon', and to 0 if you don't.
/* Define to 1 if you have the declaration of `fork', and to 0 if you don't.
*/
#define HAVE_DECL_DAEMON 0
#define HAVE_DECL_FORK 0
/* Define to 1 if you have the declaration of `htobe16', and to 0 if you
don't. */
@ -132,6 +132,10 @@
don't. */
#define HAVE_DECL_LE64TOH 0
/* Define to 1 if you have the declaration of `setsid', and to 0 if you don't.
*/
#define HAVE_DECL_SETSID 0
/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
don't. */
#define HAVE_DECL_STRERROR_R 0