#!/bin/sh
#
# os9	Allow users to run OS9(tm) applications by just typing ./file
#
# chkconfig: 35 98 10
# description: Allow users to run OS9(tm) applications by just typing ./file

. /etc/rc.d/init.d/functions
RETVAL=0

start() {
	echo -n $"Registering binary handler for OS9 applications"
	/sbin/modprobe binfmt_misc &>/dev/null
	echo ':os9:M::\x87\xcd::/usr/local/bin/os9l1:' >/proc/sys/fs/binfmt_misc/register || :
}

stop() {
	echo -n $"Unregistering binary handler for OS9 applications"
	echo "-1" >/proc/sys/fs/binfmt_misc/os9 || :
}

reload() {
	stop
	start
}

os9_status() {
	if [ -e /proc/sys/fs/binfmt_misc/os9 ]; then
		echo $"OS9 binary format handlers are registered."
		return 0
	else
		echo $"OS9 binary format handlers are not registered."
		return 3
	fi
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		os9_status
		RETVAL=$?
		;;
	restart)
		stop
		start
		;;
	condrestart)
		if [ -e /proc/sys/fs/binfmt_misc/os9 ]; then
			stop
			start
		fi
		;;
	*)
		echo $"Usage: $prog {start|stop|status|restart|condrestart}"
		exit 1
esac
exit $RETVAL

