summaryrefslogtreecommitdiffstats
path: root/etc/rc.d/random
diff options
context:
space:
mode:
authorgordon <gordon@FreeBSD.org>2002-06-13 22:14:37 +0000
committergordon <gordon@FreeBSD.org>2002-06-13 22:14:37 +0000
commit9c5433cb225f7a4e56e87623ea2e4011179553a5 (patch)
tree3168589e209abd888b033397e3c46dee6131a116 /etc/rc.d/random
parent50d99cdfecd92f5323a18aa791a5b1cb9d8b7191 (diff)
downloadFreeBSD-src-9c5433cb225f7a4e56e87623ea2e4011179553a5.zip
FreeBSD-src-9c5433cb225f7a4e56e87623ea2e4011179553a5.tar.gz
Merge in all the changes that Mike Makonnen has been maintaining for a
while. This is only the script pieces, the glue for the build comes next. Submitted by: Mike Makonnen <makonnen@pacbell.net> Reviewed by: silence on -current and -hackers Prodded by: rwatson
Diffstat (limited to 'etc/rc.d/random')
-rw-r--r--etc/rc.d/random93
1 files changed, 93 insertions, 0 deletions
diff --git a/etc/rc.d/random b/etc/rc.d/random
new file mode 100644
index 0000000..1450b93
--- /dev/null
+++ b/etc/rc.d/random
@@ -0,0 +1,93 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# PROVIDE: random
+# REQUIRE: diskless mountcritlocal initrandom
+# BEFORE: network1
+# KEYWORD: FreeBSD shutdown
+
+. /etc/rc.subr
+
+name="random"
+start_cmd="random_start"
+stop_cmd="random_stop"
+
+feed_dev_random()
+{
+ if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
+ cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null
+ fi
+}
+
+random_start()
+{
+ # Reseed /dev/random with previously stored entropy.
+ case ${entropy_dir} in
+ [Nn][Oo])
+ ;;
+ *)
+ entropy_dir=${entropy_dir:-/var/db/entropy}
+ if [ -d "${entropy_dir}" ]; then
+ if [ -w /dev/random ]; then
+ for seedfile in ${entropy_dir}/*; do
+ feed_dev_random "${seedfile}"
+ done
+ fi
+ fi
+ ;;
+ esac
+
+ case ${entropy_file} in
+ [Nn][Oo] | '')
+ ;;
+ *)
+ if [ -w /dev/random ]; then
+ feed_dev_random "${entropy_file}"
+ fi
+ ;;
+ esac
+}
+
+random_stop()
+{
+ # Write some entropy so when the machine reebots /dev/random
+ # can be reseeded
+ #
+ case ${entropy_file} in
+ [Nn][Oo] | '')
+ ;;
+ *)
+ echo -n 'Writing entropy file:'
+ rm -f ${entropy_file}
+ oumask=`umask`
+ umask 077
+ if touch ${entropy_file} ; then
+ entropy_file_confirmed="${entropy_file}"
+ else
+ # Try this as a reasonable alternative for read-only
+ # roots, diskless workstations, etc.
+ rm -f /var/db/entropy
+ if touch /var/db/entropy ; then
+ entropy_file_confirmed=/var/db/entropy
+ fi
+ fi
+ case ${entropy_file_confirmed} in
+ '')
+ err 1 '${entropy_file_confirmed}:' \
+ ' entropy file write failed.'
+ ;;
+ *)
+ dd if=/dev/random of=${entropy_file_confirmed} \
+ bs=4096 count=1 2> /dev/null
+ echo '.'
+ ;;
+ esac
+ umask ${oumask}
+ ;;
+ esac
+}
+
+load_rc_config $name
+run_rc_command "$1"
OpenPOWER on IntegriCloud