Port EST driver from NetBSD, as it has better support for newer CPUs
[dragonfly.git] / etc / rc.d / random
bloba16add34fd1f98ff6ebc6bb162751f75eaf72a81
1 #!/bin/sh
3 # $FreeBSD: src/etc/rc.d/random,v 1.3 2003/04/18 17:55:05 mtm Exp $
4 # $DragonFly: src/etc/rc.d/random,v 1.3 2005/11/19 21:47:32 swildner Exp $
7 # PROVIDE: random
8 # REQUIRE: diskless mountcritlocal initrandom
9 # BEFORE: netif
10 # KEYWORD: shutdown
12 . /etc/rc.subr
14 name="random"
15 start_cmd="random_start"
16 stop_cmd="random_stop"
18 feed_dev_random()
20 if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
21 cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null
25 random_start()
27 # Reseed /dev/random with previously stored entropy.
28 case ${entropy_dir} in
29 [Nn][Oo])
32 entropy_dir=${entropy_dir:-/var/db/entropy}
33 if [ -d "${entropy_dir}" ]; then
34 if [ -w /dev/random ]; then
35 for seedfile in ${entropy_dir}/*; do
36 feed_dev_random "${seedfile}"
37 done
41 esac
43 case ${entropy_file} in
44 [Nn][Oo] | '')
47 if [ -w /dev/random ]; then
48 feed_dev_random "${entropy_file}"
51 esac
54 random_stop()
56 # Write some entropy so when the machine reebots /dev/random
57 # can be reseeded
59 case ${entropy_file} in
60 [Nn][Oo] | '')
63 echo -n 'Writing entropy file:'
64 rm -f ${entropy_file}
65 oumask=`umask`
66 umask 077
67 if touch ${entropy_file}; then
68 entropy_file_confirmed="${entropy_file}"
69 else
70 # Try this as a reasonable alternative for read-only
71 # roots, diskless workstations, etc.
72 rm -f /var/db/entropy
73 if touch /var/db/entropy; then
74 entropy_file_confirmed=/var/db/entropy
77 case ${entropy_file_confirmed} in
78 '')
79 err 1 '${entropy_file_confirmed}:' \
80 ' entropy file write failed.'
83 dd if=/dev/random of=${entropy_file_confirmed} \
84 bs=4096 count=1 2> /dev/null
85 echo '.'
87 esac
88 umask ${oumask}
90 esac
93 load_rc_config $name
94 run_rc_command "$1"