#!/bin/sh
# $Id: ipck,v 1.2 2003/12/02 05:29:36 cwilson Exp $

#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
SELF=$0
FULLSELF=`realpath ${SELF}`
DIR=`dirname $FULLSELF`
MOD=`basename $FULLSELF | sed -e 's,^ipck,,'`
IPCS=${DIR}/ipcs${MOD}
IPCRM=${DIR}/ipcrm${MOD}

syntaxe()
{
 echo ""
 echo "IPC destruction"
 echo "---------------"
 echo ""
 echo "    ipck [all | allsem | allmsg | allshm]"
 echo ""
}

if test $# -eq 1
then
 case $1 in
 all)
 echo "kill all ipc"
 a=`${IPCS} | grep "_sem" | awk '{print $2}'`
 if test " $a" != " " 
 then
  ${IPCRM} sem $a
 fi
 a=`${IPCS} | grep "_shm" | awk '{print $2}'`
 if test " $a" != " " 
 then
  ${IPCRM} shm $a
 fi
 a=`${IPCS} | grep "_msg" | awk '{print $2}'`
 if test " $a" != " " 
 then
  ${IPCRM} msg $a
 fi
 ;;
 allsem)
 echo "kill all sem"
 a=`${IPCS} | grep "_sem" | awk '{print $2}'`
 if test " $a" != " " 
 then
  ${IPCRM} sem $a
 fi
 ;;
 allmsg)
 echo "kill all msg"
 a=`${IPCS} | grep "_msg" | awk '{print $2}'`
 if test " $a" != " " 
 then
  ${IPCRM} msg $a
 fi
 ;;
 allshm)
 echo "kill all shm"
 a=`${IPCS} | grep "_shm" | awk '{print $2}'`
 if test " $a" != " " 
 then
  ${IPCRM} shm $a
 fi
 ;;
 *)
 syntaxe
 ;;
 esac
else
 syntaxe
fi
