#!/usr/bin/env perl
#
# Copyright (c) 2001-2006 CNRS/LAAS
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

# Kill MY Genom modules under Unix
#
# Sara Fleury - Avril 2001
#
# $Id$
#----------------------------------------------------------------------
#

use warnings;

$killmodule =  "killmodule";

$h2owner = $ENV{'H2DEV_DIR'};
if (defined($h2owner)) {
  $pid_file_pattern = "$h2owner/.*.pid-*";
} else {
  $pid_file_pattern = "$ENV{'HOME'}/.*.pid-*";
}

# Get a list of files corresponding to running modules
@list_files=`ls $pid_file_pattern`;

# walk the list
foreach $file (@list_files) {
  $_ = $file;

  # extract the module name
  if (/.(\w*).pid/) {
    $module = $1;
    
    # call killmodule
    printf "killmodule $module\n";
    `$killmodule $module`;
  }

  # module name not found ?!
  else {
    printf "Cannot get module name of $file\n";
  }
}

# done
exit 0;
