#!/bin/bash
#
# © Copyright IBM Corp. 2008.  All Rights Reserved.
#
# description: rtcheck checks if the system is Real Time capable.
#              A run at boot time by root caches all user independent
#              tests to increase performance at run time.
#
### BEGIN INIT INFO
# Provides: rtcheck
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop: 1 6
# Description: Run rtcheck system tests
### END INIT INFO


# source function library
. /etc/rc.status

rc_reset

RETVAL=0

start() {
	echo -n $"Checking if system is Real Time capable: "

	rtcheck -v > /var/log/rtcheck
	RETVAL=$?

	# because this is for global tests only,
	# return of 1 or 0 is acceptable
	# 0 => all tests passed
	# 1 => memlock (per-user-test) failed
	[[ "$RETVAL" -eq 1 ]] || [[ "$RETVAL" -eq 0 ]]

	rc_status -v
}

stop() {
	# reset rtcheck's system cache
	rm -f /var/cache/rtcheck
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	*)
		echo $"Usage: $0 {start|stop|restart}"
		exit 1
		;;
esac

exit $RETVAL
