From 98fbd24d62bfe1fbbf8aaf7adb367e44da66fcd8 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 3 Aug 2008 12:45:35 +0100 Subject: fix iteration over random devices Actually iterate over the various random devices. Fixes a infinite loop on startup when /dev/urandom isn't readable. Patch by Matt Kraai on Debian bug 491270, closes #333 Signed-off-by: Lennart Poettering --- src/pulsecore/random.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/pulsecore/random.c') diff --git a/src/pulsecore/random.c b/src/pulsecore/random.c index 5deac37b..da381065 100644 --- a/src/pulsecore/random.c +++ b/src/pulsecore/random.c @@ -77,6 +77,8 @@ static int random_proper(void *ret_data, size_t length) { if (ret == 0) break; + + device++; } return ret; -- cgit From f417bb42cf68920c5679a39296fca1c48864d7cb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 3 Aug 2008 17:00:52 +0200 Subject: some pa_bool_t'ization --- src/pulsecore/random.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/pulsecore/random.c') diff --git a/src/pulsecore/random.c b/src/pulsecore/random.c index da381065..518c281a 100644 --- a/src/pulsecore/random.c +++ b/src/pulsecore/random.c @@ -37,7 +37,7 @@ #include "random.h" -static int has_whined = 0; +static pa_bool_t has_whined = TRUE; static const char * const devices[] = { "/dev/urandom", "/dev/random", NULL }; @@ -89,9 +89,11 @@ void pa_random_seed(void) { unsigned int seed; if (random_proper(&seed, sizeof(unsigned int)) < 0) { - if (!has_whined) + + if (!has_whined) { pa_log_warn("Failed to get proper entropy. Falling back to seeding with current time."); - has_whined = 1; + has_whined = TRUE; + } seed = (unsigned int) time(NULL); } @@ -109,9 +111,10 @@ void pa_random(void *ret_data, size_t length) { if (random_proper(ret_data, length) >= 0) return; - if (!has_whined) + if (!has_whined) { pa_log_warn("Failed to get proper entropy. Falling back to unsecure pseudo RNG."); - has_whined = 1; + has_whined = TRUE; + } for (p = ret_data, l = length; l > 0; p++, l--) *p = (uint8_t) rand(); -- cgit