[PATCH] Calculate POOLBYTES correctly. Note that /proc/sys/kernel/random/poolsize reports the number of bits, not bytes, so a conversion is necessary.

root root at localhost.localdomain
Sat Sep 11 22:23:20 UTC 2010


---
 urandom |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/urandom b/urandom
index f5b4bcb..ffca615 100755
--- a/urandom
+++ b/urandom
@@ -14,8 +14,11 @@
 
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 SAVEDFILE=/var/lib/urandom/random-seed
-POOLSIZE=512
-[ -f /proc/sys/kernel/random/poolsize ] && POOLSIZE="$(cat /proc/sys/kernel/random/poolsize)"
+if ! POOLBYTES=$((
+  ($(cat /proc/sys/kernel/random/poolsize 2>/dev/null) + 7) / 8
+)) ; then
+  POOLBYTES=512
+fi
 . /lib/init/vars.sh
 
 . /lib/lsb/init-functions
@@ -23,7 +26,7 @@ POOLSIZE=512
 case "$1" in
   start|"")
 	[ "$VERBOSE" = no ] || log_action_begin_msg "Initializing random number generator"
-	# Load and then save $POOLSIZE bytes,
+	# Load and then save $POOLBYTES bytes,
 	# which is the size of the entropy pool
 	if [ -f "$SAVEDFILE" ]
 	then
@@ -31,7 +34,7 @@ case "$1" in
 	fi
 	rm -f $SAVEDFILE
 	umask 077
-	dd if=/dev/urandom of=$SAVEDFILE bs=$POOLSIZE count=1 >/dev/null 2>&1
+	dd if=/dev/urandom of=$SAVEDFILE bs=$POOLBYTES count=1 >/dev/null 2>&1
 	ES=$?
 	umask 022
 	[ "$VERBOSE" = no ] || log_action_end_msg $ES
@@ -41,7 +44,7 @@ case "$1" in
 	# see documentation in linux/drivers/char/random.c
 	[ "$VERBOSE" = no ] || log_action_begin_msg "Saving random seed"
 	umask 077
-	dd if=/dev/urandom of=$SAVEDFILE bs=$POOLSIZE count=1 >/dev/null 2>&1
+	dd if=/dev/urandom of=$SAVEDFILE bs=$POOLBYTES count=1 >/dev/null 2>&1
 	ES=$?
 	[ "$VERBOSE" = no ] || log_action_end_msg $ES
 	;;
-- 
1.5.6.5


--------------030906080109050106090405--





More information about the Pkg-sysvinit-devel mailing list