2 # Copyright (c) 2007-2015 The OpenRC Authors.
3 # See the Authors file at the top-level directory of this distribution and
4 # https://github.com/OpenRC/openrc/blob/master/AUTHORS
6 # This file is part of OpenRC. It is subject to the license terms in
7 # the LICENSE file found in the top-level directory of this
8 # distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
9 # This file may not be copied, modified, propagated, or distributed
10 # except according to the terms contained in the LICENSE file.
12 : ${urandom_seed:=${URANDOM_SEED:-/var/lib/misc/random-seed}}
13 description="Initializes the random number generator."
18 keyword -docker -jail -lxc -openvz -prefix -systemd-nspawn
25 if [ -e /proc/sys/kernel/random/poolsize ]; then
26 : $(( psz = $(cat /proc/sys/kernel/random/poolsize) / 4096 ))
29 ( # sub shell to prevent umask pollution
31 dd if=/dev/urandom of="$urandom_seed" count=${psz} 2>/dev/null
37 [ -c /dev/urandom ] || return
38 if [ -f "$urandom_seed" ]; then
39 ebegin "Initializing random number generator"
40 cat "$urandom_seed" > /dev/urandom
41 eend $? "Error initializing random number generator"
43 rm -f "$urandom_seed" && save_seed
49 ebegin "Saving random seed"
51 eend $? "Failed to save random seed"