#!/bin/sh
#ifndef _BLURB_
#define _BLURB_
#/*
#
#            Coda: an Experimental Distributed File System
#                             Release 4.0
#
#          Copyright (c) 1987-1996 Carnegie Mellon University
#                         All Rights Reserved
#
#Permission  to  use, copy, modify and distribute this software and its
#documentation is hereby granted,  provided  that  both  the  copyright
#notice  and  this  permission  notice  appear  in  all  copies  of the
#software, derivative works or  modified  versions,  and  any  portions
#thereof, and that both notices appear in supporting documentation, and
#that credit is given to Carnegie Mellon University  in  all  documents
#and publicity pertaining to direct or indirect use of this code or its
#derivatives.
#
#CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
#SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
#FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
#DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
#RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
#ANY DERIVATIVE WORK.
#
#Carnegie  Mellon  encourages  users  of  this  software  to return any
#improvements or extensions that  they  make,  and  to  grant  Carnegie
#Mellon the rights to redistribute these changes without encumbrance.
#*/
#
#static char *rcsid = "$Header: /afs/cs/project/coda-src/cvs/coda/coda-src/scripts/vutil,v 4.5 98/08/05 23:49:59 braam Exp $";
#endif /*_BLURB_*/


prog=$0
kill=/bin/kill
vpid=`/bin/cat /usr/coda/venus.cache/pid`
ckpfile=/usr/coda/venus.cache/DUMP
copfile=/usr/coda/venus.cache/COPMODES
mcfile=/usr/coda/venus.cache/MCAST
debugfile=/usr/coda/venus.cache/DEBUG

usage ()
{
    echo Usage: 
    echo ${prog} ckp
    echo ${prog} cs 
    echo ${prog} d debug_level 
    echo ${prog} "m {0,2,3,6,7}"
    echo ${prog} "mc {0,1} "
    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

par=${1#-}
#echo $par

case $par in
	ckp )
	    echo > ${ckpfile}
	    ${kill} -USR1 ${vpid}
	    ;;

	m )
	    if [ x$2 = x0 ]; then  usage ; fi
	    val="$2"
	    if [ "$val" != 0 -a "$val" != 2 -a "$val" != 3 -a "$val" != 6 -a "$val" != 7 ]; then
		usage
	    fi
	    echo "$val" > ${copfile}
	    ${kill} -USR1 ${vpid}
	    ;;

	cs )
	    ${kill} -XFSZ ${vpid}
	    ;;

	d )
	    if [ x$2 = x ]; then  usage ; fi
	    echo "$2 $3" > ${debugfile}
	    ${kill} -USR1 ${vpid}
	    ;;

	mc )
	    if [ x$2 = x ]; then  usage ; fi
	    if  [ x$3 != x -a "$3" != 1 ]; then usage ; fi
	    echo "$2 $3" > ${mcfile}
	    ${kill} -USR1 ${vpid}
	    ;;

	p )
	    if [ x$2 = x ]; then  usage ; fi
	    val="$2"
	    if [ $val = 0 ]; then
		${kill} -EMT ${vpid}
	    else
		if [ "$val" != 1 ]; then usage ; fi
		${kill} -IOT ${vpid}
	    fi
	    ;;

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

	stats )
	    ${kill} -XCPU ${vpid}
	    ;;

	swap )
	    ${kill} -VTALRM ${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

