about summary refs log tree commit diff
path: root/shared/systemd/src/basic/random-util.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2019-12-18 18:30:31 +0100
committerMichael Biebl <biebl@debian.org>2019-12-18 18:30:31 +0100
commit4bde769dba8f804547ce1f5fcda731035d3d45f1 (patch)
tree3a4907fdbf4972fad5a036ef64ce643d704e8733 /shared/systemd/src/basic/random-util.c
parentbbf6329c27676323a899b7328575cc3f6c5f48cc (diff)
parent28028b26b3371756811e95d894f709f4b1207c00 (diff)
Update upstream source from tag 'upstream/1.22.0'
Update to upstream version '1.22.0'
with Debian dir a81ba1028908d08fc4866734c3df4a042bf9a511
Diffstat (limited to 'shared/systemd/src/basic/random-util.c')
-rw-r--r--shared/systemd/src/basic/random-util.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/shared/systemd/src/basic/random-util.c b/shared/systemd/src/basic/random-util.c
index c70871bf..86917ca3 100644
--- a/shared/systemd/src/basic/random-util.c
+++ b/shared/systemd/src/basic/random-util.c
@@ -19,16 +19,13 @@
 #  include <sys/auxv.h>
 #endif
 
-#if USE_SYS_RANDOM_H
-#  include <sys/random.h>
-#else
-#  include <linux/random.h>
-#endif
-
 #include "alloc-util.h"
 #include "fd-util.h"
+#include "fileio.h"
 #include "io-util.h"
-#include "missing.h"
+#include "missing_random.h"
+#include "missing_syscall.h"
+#include "parse-util.h"
 #include "random-util.h"
 #include "siphash24.h"
 #include "time-util.h"
@@ -398,3 +395,28 @@ void random_bytes(void *p, size_t n) {
         /* If for some reason some user made /dev/urandom unavailable to us, or the kernel has no entropy, use a PRNG instead. */
         pseudo_random_bytes(p, n);
 }
+
+#if 0 /* NM_IGNORED */
+size_t random_pool_size(void) {
+        _cleanup_free_ char *s = NULL;
+        int r;
+
+        /* Read pool size, if possible */
+        r = read_one_line_file("/proc/sys/kernel/random/poolsize", &s);
+        if (r < 0)
+                log_debug_errno(r, "Failed to read pool size from kernel: %m");
+        else {
+                unsigned sz;
+
+                r = safe_atou(s, &sz);
+                if (r < 0)
+                        log_debug_errno(r, "Failed to parse pool size: %s", s);
+                else
+                        /* poolsize is in bits on 2.6, but we want bytes */
+                        return CLAMP(sz / 8, RANDOM_POOL_SIZE_MIN, RANDOM_POOL_SIZE_MAX);
+        }
+
+        /* Use the minimum as default, if we can't retrieve the correct value */
+        return RANDOM_POOL_SIZE_MIN;
+}
+#endif /* NM_IGNORED */