File introduce-once-2.patch of Package haveged.37149
Index: haveged-1.9.14/src/haveged.c
===================================================================
--- haveged-1.9.14.orig/src/haveged.c
+++ haveged-1.9.14/src/haveged.c
@@ -635,6 +635,33 @@ static void run_daemon( /* RETURN: no
if (params->exit_code > 128)
error_exit("Stopping due to signal %d\n", params->exit_code - 128);
+ if (params->once == 1) {
+ if (ioctl(random_fd, RNDGETENTCNT, ¤t) == -1) {
+ error_exit("Couldn't query entropy-level from kernel");
+ }
+
+ /* get number of bytes needed to fill pool */
+ nbytes = (poolSize - current) / 8;
+ if (nbytes < 1) {
+ params->exit_code = 0;
+ error_exit("Entropy could not be refilled, couldn't discover number of bytes needed to fill the pool.\n");
+ }
+
+ /* get that many random bytes */
+ r = (nbytes + sizeof(H_UINT) - 1) / sizeof(H_UINT);
+ if (havege_rng(h, (H_UINT *)output->buf, r) < 1)
+ error_exit("RNG failed! %d", h->error);
+ output->buf_size = nbytes;
+ /* entropy is 8 bits per byte */
+ output->entropy_count = nbytes * 8;
+ if (ioctl(random_fd, RNDADDENTROPY, output) == -1) {
+ error_exit("RNDADDENTROPY failed!");
+ }
+
+ params->exit_code = 0;
+ error_exit("Entropy refilled once (%d bytes), exiting.\n", nbytes);
+ }
+
FD_ZERO(&write_fd);
#ifndef NO_COMMAND_MODE
if (socket_fd >= 0) {