#! /bin/sh
### BEGIN INIT INFO
# Provides:          sendsigs
# Required-Start:    
# Required-Stop:     umountnfs
# Default-Start:
# Default-Stop:      0 6
# Short-Description: Kill all remaining processes.
# Description: 
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/lsb/init-functions

do_stop () {
	# Kill all processes.
	log_action_begin_msg "Asking all remaining processes to terminate"
	killall5 -15 # SIGTERM
	log_action_end_msg 0
	for seq in 1 2 3 4 5 ; do
		# use SIGCONT/signal 18 to check if there are
		# processes left.  No need to check the exit code
		# value, because either killall5 work and it make
		# sense to wait for processes to die, or it fail and
		# there is nothing to wait for.
		killall5 -18 || break

		sleep 1
	done
	log_action_begin_msg "Killing all remaining processes"
	killall5 -9 # SIGKILL
	log_action_end_msg 0
}

splash_back() {
    # Restore usplash if it was enabled and killed by do_stop
    for x in $(cat /proc/cmdline); do
	case $x in
	splash*)
	    SPLASH=true;
	    ;;
	esac
    done

    [ "$SPLASH" = "true" ] || return 0

    if [ -x /sbin/usplash ]; then
        /sbin/usplash -c &
    fi
}

case "$1" in
  start)
	# No-op
	;;
  restart|reload|force-reload)
	echo "Error: argument '$1' not supported" >&2
	exit 3
	;;
  stop)
	do_stop
	splash_back
	;;
  *)
	echo "Usage: $0 start|stop" >&2
	exit 3
	;;
esac

:
