#!/bin/sh
# BLURB gpl
# 
#                            Coda File System
#                               Release 6
# 
#           Copyright (c) 1987-2003 Carnegie Mellon University
#                   Additional copyrights listed below
# 
# This  code  is  distributed "AS IS" without warranty of any kind under
# the terms of the GNU General Public Licence Version 2, as shown in the
# file  LICENSE.  The  technical and financial  contributors to Coda are
# listed in the file CREDITS.
# 
#                         Additional copyrights
#                            none currently
# 
#*/

# the default pid and run_control files
pid_file=/usr/coda/venus.cache/pid
run_control_file=/usr/coda/venus.cache/VENUS_CTRL

# and override the defaults using the values from venus.conf
. "`codaconfedit venus.conf`"

prog=$0
kill=kill
vpid=`cat $pid_file`
umask 0

usage ()
{
    echo Usage: 
    echo ${prog} ckp
    echo ${prog} cs 
    echo ${prog} d debug_level 
    echo ${prog} "m {0,2,3,6,7}"
    echo ${prog} "p {0,1} "
    echo ${prog} shutdown 
    echo ${prog} stats 
    echo ${prog} swap
    if [ `uname` = Linux ]; then
	echo ${prog} kdebug level
	echo ${prog} ktrace {0,1}
    fi
    exit 1
}

if  [ $# = 0 ]; then 
    usage
fi

# strip the - from the command.  
if [ x$BASH_VERSION != x ] ; then
par=${1#-}
else
par=`echo $1 | sed -e "s/-//"`
fi
#echo $par

case $par in
	ckp )
	    # seems to be not implemented/activated in venus.
	    echo CHECKPOINT > ${run_control_file}
	    ${kill} -HUP ${vpid}
	    ;;

	m )
	    # seems to be not implemented/activated in venus.
	    val="$2"
	    if [ x$val != x0 -a x$val != x2 -a x$val != x3 -a x$val != x6 -a x$val != x7 ]; then
		usage
	    fi
	    echo "COPMODES $val" > ${run_control_file}
	    ${kill} -HUP ${vpid}
	    ;;

	cs )
	    echo "STATSINIT" > ${run_control_file}
	    ${kill} -HUP ${vpid}
	    ;;

	d )
	    if [ x$2 = x ]; then  usage ; fi
	    echo "DEBUG $2 $3 $4" > ${run_control_file}
	    ${kill} -HUP ${vpid}
	    ;;

	p )
	    # seems to be not implemented/activated in venus.
	    if  [ x$2 != x0 -a x$2 != x1 ]; then usage ; fi
	    echo "PROFILING $2" > ${run_control_file}
	    ;;

	shutdown )
	    ${kill} -TERM ${vpid}
	    ;;

	stats )
	    echo STATS > ${run_control_file}
	    ${kill} -HUP ${vpid}
	    ;;

	swap )
	    echo SWAPLOGS > ${run_control_file}
	    ${kill} -HUP ${vpid}
	    ;;

	kdebug )
	    if [ `uname` != Linux -o x$2 = x ]; then usage ; fi
            echo $2 > /proc/sys/coda/debug
	    ;;

	ktrace )
	    if [ `uname` != Linux -o x$2 = x ]; then usage ; fi
            echo $2 > /proc/sys/coda/printentry
	    ;;


	* )
	    echo "${prog}: unknown switch ($1)"
	    usage
	    ;;
esac

exit 0

