#!/bin/sh
### BEGIN INIT INFO
# Provides:            killall
# Required-Start:
# Should-Start:
# Required-Stop:
# Should-Stop:
# Default-Start:       0 2 6
# Default-Stop:
# Short-Description:   It kills all processes.
# Description:         It kills all processes.
# X-LFS-Provided-By:   LFS
### END INIT INFO

if [ -n "$1" ] && [ "$1" != start ]; then
	exit 0
fi

# Source function library.
. /etc/init.d/functions

echo_end()
{
	[ $1 = 0 ] && echo_success || echo_failure
	echo
}

omitpid=
[ -n "${IGNORE_OMITPIDS-}" ] ||
for pid in /.initrd/killall/[0-9]*; do
	[ ! -f "$pid" ] ||
		omitpid="${omitpid:+$omitpid }-o ${pid##*/}"
done

echo_msg 'Asking all remaining processes to terminate:'
killall5 -15 $omitpid
rc=$?

if [ $rc = 2 ]; then
	echo_success
	echo
	exit 0
fi
echo_end "$rc"

seq=5
if [ "$rc" = 0 ]; then
	for seq in 1 2 3 4 5; do
		killall5 -18 $omitpid || break
		sleep 1
	done
fi
[ "$seq" = 5 ] || exit 0

echo_msg 'Killing all remaining processes:'
killall5 -9 $omitpid
rc=$?

if [ $rc = 2 ]; then
	echo_success
	echo
	exit 0
fi
echo_end "$rc"
