diff options
Diffstat (limited to 'shared/systemd/src/basic/random-util.c')
| -rw-r--r-- | shared/systemd/src/basic/random-util.c | 36 |
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 */ |