From fe2543d8dc10b542b6e3113340253e41eca69906 Mon Sep 17 00:00:00 2001 From: darosior Date: Wed, 2 Oct 2019 17:29:19 +0200 Subject: [PATCH] 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.". --- common/daemon.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/daemon.c b/common/daemon.c index f93fa1884..36c16938f 100644 --- a/common/daemon.c +++ b/common/daemon.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -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);