SVN: rc-scripts/trunk/rc.d/init.d/random
glen
glen at pld-linux.org
Mon Jun 14 19:25:05 CEST 2010
Author: glen
Date: Mon Jun 14 19:25:05 2010
New Revision: 11556
Modified:
rc-scripts/trunk/rc.d/init.d/random
Log:
- reorganize into functions
Modified: rc-scripts/trunk/rc.d/init.d/random
==============================================================================
--- rc-scripts/trunk/rc.d/init.d/random (original)
+++ rc-scripts/trunk/rc.d/init.d/random Mon Jun 14 19:25:05 2010
@@ -24,53 +24,68 @@
poolfile=/proc/sys/kernel/random/poolsize
[ -r $poolfile ] && bytes="$(cat $poolfile)" || bytes=512
-
-# See how we were called.
-case "$1" in
- start)
+start() {
# Check if the service is already running?
- if [ ! -f /var/lock/subsys/random ]; then
- emit starting JOB=random
- show "Initializing random number generator"
- busy
- # Carry a random seed from start-up to start-up
- if [ -f $random_seed ]; then
- cat $random_seed >/dev/urandom
- else
- touch $random_seed
- fi
- chmod 600 $random_seed
- dd if=/dev/urandom of=$random_seed count=1 bs=$bytes 2>/dev/null
- touch /var/lock/subsys/random
- deltext
- ok
- emit --nowait started JOB=random
- fi
- ;;
- stop)
if [ -f /var/lock/subsys/random ]; then
- # Carry a random seed from shut-down to start-up
- emit stopping JOB=random
- show "Saving random seed"
- busy
+ return
+ fi
+
+ emit starting JOB=random
+ show "Initializing random number generator"
+ busy
+ # Carry a random seed from start-up to start-up
+ if [ -f $random_seed ]; then
+ cat $random_seed >/dev/urandom
+ else
touch $random_seed
- chmod 600 $random_seed
- dd if=/dev/urandom of=$random_seed count=1 bs=$bytes 2>/dev/null
+ fi
+ chmod 600 $random_seed
+ dd if=/dev/urandom of=$random_seed count=1 bs=$bytes 2>/dev/null
+ touch /var/lock/subsys/random
+ deltext
+ ok
+ emit --nowait started JOB=random
+}
- rm -f /var/lock/subsys/random
- deltext
- ok
- emit --no-wait stopped JOB=random
+stop() {
+ if [ ! -f /var/lock/subsys/random ]; then
+ return
fi
- ;;
- status)
- entropy_avail="$(cat /proc/sys/kernel/random/entropy_avail)"
+
+ # Carry a random seed from shut-down to start-up
+ emit stopping JOB=random
+ show "Saving random seed"
+ busy
+ touch $random_seed
+ chmod 600 $random_seed
+ dd if=/dev/urandom of=$random_seed count=1 bs=$bytes 2>/dev/null
+
+ rm -f /var/lock/subsys/random
+ deltext
+ ok
+ emit --no-wait stopped JOB=random
+}
+
+status() {
+ entropy_avail="$(cat /proc/sys/kernel/random/entropy_avail)"
if [ "$entropy_avail" -eq 0 -o ! -c /dev/random ] ; then
nls "The random data source is missing"
- exit 1
+ RETVAL=1
else
nls "$entropy_avail bytes of entropy available"
fi
+}
+
+# See how we were called.
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ status)
+ status
;;
*)
msg_usage "$0 {start|stop|status}"
More information about the pld-cvs-commit
mailing list