summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/initscripts/initscripts-1.0/urandom
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/initscripts/initscripts-1.0/urandom')
-rwxr-xr-xmeta/recipes-core/initscripts/initscripts-1.0/urandom49
1 files changed, 49 insertions, 0 deletions
diff --git a/meta/recipes-core/initscripts/initscripts-1.0/urandom b/meta/recipes-core/initscripts/initscripts-1.0/urandom
new file mode 100755
index 0000000000..af1625b5fd
--- /dev/null
+++ b/meta/recipes-core/initscripts/initscripts-1.0/urandom
@@ -0,0 +1,49 @@
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides: urandom
4# Required-Start: $local_fs mountvirtfs
5# Required-Stop: $local_fs
6# Default-Start: S
7# Default-Stop: 0 6
8# Short-Description: Save and restore the random seed
9# Description: Save the random seed on shutdown and restore it on boot,
10# to ensure that the seed isn't predicable on startup
11# (because the boot process is predictable)
12### END INIT INFO
13
14test -c /dev/urandom || exit 0
15
16RANDOM_SEED_FILE=/var/lib/urandom/random-seed
17
18. /etc/default/rcS
19[ -f /etc/default/urandom ] && . /etc/default/urandom
20
21case "$1" in
22 start|"")
23 test "$VERBOSE" != no && echo "Initializing random number generator..."
24 # Load and then save 512 bytes, which is the size of the entropy
25 # pool. Also load the current date, in case the seed file is
26 # empty.
27 ( date +%s.%N; [ -f "$RANDOM_SEED_FILE" ] && cat "$RANDOM_SEED_FILE" ) \
28 >/dev/urandom
29 rm -f "$RANDOM_SEED_FILE"
30 umask 077
31 dd if=/dev/urandom of=$RANDOM_SEED_FILE count=1 \
32 >/dev/null 2>&1 || echo "urandom start: failed."
33 umask 022
34 ;;
35 stop)
36 # Carry a random seed from shut-down to start-up;
37 # see documentation in linux/drivers/char/random.c
38 test "$VERBOSE" != no && echo "Saving random seed..."
39 umask 077
40 dd if=/dev/urandom of=$RANDOM_SEED_FILE count=1 \
41 >/dev/null 2>&1 || echo "urandom stop: failed."
42 ;;
43 *)
44 echo "Usage: urandom {start|stop}" >&2
45 exit 1
46 ;;
47esac
48
49exit 0