Fix blocked entropy generation
authorCristian Ciocaltea <cristian.ciocaltea@gmail.com>
Tue, 21 Jan 2020 14:43:24 +0000 (16:43 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 21 Jan 2020 15:56:08 +0000 (16:56 +0100)
The OpenWrt Jitter RNG daemon is currently unable to continuously
provide entropy, except once on process startup.

This patch brings the following fixes:
- poll /dev/random for unblocking write operations, instead of read
- register the low entropy callback after uloop initialization, not
  before

Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
[commit subject tweak, uloop_done cleanup]
Signed-off-by: Petr Štetiar <ynezz@true.cz>
urngd.c

diff --git a/urngd.c b/urngd.c
index d8ed159141e073e5a9c6f368bb883e709a8fe8a8..35ccdec49af2c2fa2958cf7bd9d8f1cbeb43cb50 100644 (file)
--- a/urngd.c
+++ b/urngd.c
@@ -180,7 +180,7 @@ static bool urngd_init(struct urngd *u)
                return false;
        }
 
-       uloop_fd_add(&u->rnd_fd, ULOOP_READ);
+       uloop_fd_add(&u->rnd_fd, ULOOP_WRITE);
 
        return true;
 }
@@ -227,14 +227,16 @@ int main(int argc, char **argv)
 
        ulog_open(ulog_channels, LOG_DAEMON, "urngd");
 
-       if (!urngd_init(&urngd_service))
+       uloop_init();
+       if (!urngd_init(&urngd_service)) {
+               uloop_done();
                return -1;
+       }
 
        LOG("v%s started.\n", URNGD_VERSION);
 
        gather_entropy(&urngd_service);
 
-       uloop_init();
        uloop_run();
        uloop_done();