daemons: initialize libsodium at setup

According to the doc (https://download.libsodium.org/doc):
"sodium_init() initializes the library and should be called before
any other function provided by Sodium. [...]
the function ensures that the system's random number generator has
been properly seeded.".
This commit is contained in:
darosior 2019-10-02 17:29:19 +02:00 committed by neil saitug
parent 2c69ece7fe
commit fe2543d8dc

View File

@ -11,6 +11,7 @@
#include <common/utils.h>
#include <common/version.h>
#include <signal.h>
#include <sodium.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@ -146,6 +147,12 @@ void daemon_setup(const char *argv0,
memleak_init();
#endif
/* We rely on libsodium for some of the crypto stuff, so we'd better
* not start if it cannot do its job correctly. */
if (sodium_init() == -1)
errx(1, "Could not initialize libsodium. Maybe not enough entropy"
" available ?");
/* We handle write returning errors! */
signal(SIGPIPE, SIG_IGN);
wally_init(0);