#!/bin/sh

. /usr/share/rng-tools-debian/init-system-common

case $1 in
(start)
	readoptions
	hrngselect
	if ! finddevice; then
		logger -t rng-tools-debian \
		    'not starting: no hardware RNG device found'
		# Note 3: should go with RestartPreventExitStatus=…?
		exit 1
	fi
	if skipdevice; then
		logger -t rng-tools-debian \
		    "not starting: /dev/hwrng is used by the kernel automatically"
		exit 1 #XXX correct? mirrors above
	fi
	# Note 1: should this not be “exec /usr/sbin/rngd …” for Type=forking?
	# Note 2: could be modelled as Type=exec with rngd -f?
	/usr/sbin/rngd -p /run/rngd.pid -r $HRNGDEVICE $RNGDOPTIONS && \
	    sleep 0.1
	;;
(*)
	logger -t rng-tools-debian \
	    'systemd-helper: unknown command'
	exit 1
	;;
esac
