#!/bin/sh
##
# VampirTrace
# http://www.tu-dresden.de/zih/vampirtrace
#
# Copyright (c) 2005-2012, ZIH, TU Dresden, Federal Republic of Germany
#
# Copyright (c) 1998-2005, Forschungszentrum Juelich, Juelich Supercomputing
#                          Centre, Federal Republic of Germany
#
# See the file COPYING in the package base directory for details
##

# global variables
#
_VTIOFSL_EXENAME="vtiofsl-stop"
_VTIOFSL_ROOT=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
_VTIOFSL_SERVERS=$VT_IOFSL_SERVERS

# source common stuff
. $_VTIOFSL_ROOT/vtiofsl-common $@

#
# subroutine _vtiofsl_show_helptext() - shows the help text
#
_vtiofsl_show_helptext()
{
  echo ""
  echo " $_VTIOFSL_EXENAME - stop running IOFSL servers."
  echo ""
  echo " Syntax: $_VTIOFSL_EXENAME [options]"
  echo ""
  echo "   options:"
  echo "     -h, --help          Show this help message."
  echo ""
  echo "     -V, --version       Show VampirTrace version."
  echo ""
  echo "     -v, --verbose       Increase output verbosity."
  echo "                         (can be used more than once)"
  echo ""
  echo "     -q, --quiet         Enable quiet mode."
  echo "                         (only emergency output)"
  echo ""
  echo "   note:"
  echo "     This script needs to be sourced from a shell, since it sets"
  echo "     environment variables."
  echo ""

  _vtiofsl_exit 0
}

#
# "main"-routine
#

# parse command line options
#
arg_error_msg=
while test $# -ne 0; do
  case $1 in
    *)
      _vtiofsl_parse_common_option $1
      if test $? -ne 0; then
        arg_error_msg="unrecognized option -- '$1'"
        break
      fi
      shift
      ;;
  esac
done
if test x"$arg_error_msg" != x; then
  _vtiofsl_error_msg "$arg_error_msg\nTry \`$EXENAME --help' for more "\
"information."
  _vtiofsl_exit 1
fi

# check for running IOFSL servers
#
if test x"$VT_IOFSL_SERVERS" = x; then
  _vtiofsl_error_msg "Error: Environment variable VT_IOFSL_SERVERS not set "\
"(IOFSL server running?). Aborting."
  _vtiofsl_exit 1
fi

# source platform specific stuff
. $_VTIOFSL_ROOT/vtiofsl-platform

# stop IOFSL servers
#
_vtiofsl_stop_servers
rc=$?

# unset environment variables on success; otherwise abort
#
if test $rc -eq 0; then
  unset VT_IOFSL_SERVERS
#  unset VT_IOFSL_MODE
#  unset VT_IOFSL_ASYNC_IO
else
  _vtiofsl_exit $rc
fi

