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

John Denker jsd at av8n.com
Sat Sep 11 16:22:36 UTC 2010


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

diff --git a/urandom b/urandom
index 1007147..5172e7f 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
@@ -31,7 +34,7 @@ do_status () {
 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
@@ -40,7 +43,7 @@ case "$1" in
 	rm -f $SAVEDFILE
 	# Hm, why is the saved pool re-created at boot? [pere 2009-09-03]
 	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
@@ -50,7 +53,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.7.0.4


--------------060008090703080509010000--





More information about the Pkg-sysvinit-devel mailing list