#!/sbin/runscript # Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/sys-apps/rng-tools/files/2-r2/rngd,v 1.2 2010/09/15 08:36:14 robbat2 Exp $ depend() { need localmount after random } BINARY=/usr/sbin/rngd # Do NOT add /dev/tpm to this. DEFAULT_DEVICE="/dev/hw_random* /dev/hwrandom* /dev/i810_rng /dev/hwrng*" DEFAULT_TPM_DEVICE="/dev/tpm*" [ $DO_NOT_REMIX_URANDOM -eq 0 ] && DEFAULT_DEVICE="${DEFAULT_DEVICE} /dev/urandom" find_device() { # The echo is to cause globbing for d in $*; do [ -e "$d" ] && break done echo "$d" } find_rng_device() { local d="$(find_device $(echo ${DEVICE-${DEFAULT_DEVICE}}))" [ -z "${d}" ] && d=/dev/null echo "$d" } find_tpm_device() { local d="$(find_device $(echo ${TPM_DEVICE-${DEFAULT_TPM_DEVICE}}))" [ -z "${d}" ] && d=/dev/null echo "$d" } start() { local d t d="$(find_rng_device)" [ "${NO_TPM}" == "1" ] || t="$(find_tpm_device)" [ -z "${d}" ] && d=/dev/null [ -z "${t}" ] && t=/dev/null # TODO: find a better way to handle multiple feedback devices. # Notice that we only warn if TPM is not available. [ "$d" == "/dev/urandom" -a "$t" == "/dev/null" ] && ewarn "No hardware RNG found, using $d as feedback input" # Now sanity check and start. if [ "$d" != "/dev/null" -o "$t" != "/dev/null" ]; then ebegin "Starting hardware RNG daemon" start-stop-daemon --start --quiet --exec ${BINARY} -- -b -s ${STEP-64} -t ${TIMEOUT-60} --no-tpm=${NO_TPM-0} -W ${WATERMARK-2048} -r $d eend $? "Failed to start hardware RNG daemon" else eerror "No hardware RNG or feedback source available." return 1 fi } stop() { ebegin "Stopping hardware RNG daemon" start-stop-daemon --stop --quiet --exec ${BINARY} eend $? "Failed to stop hardware RNG daemon" }