#!/usr/bin/perl

use Getopt::Long;

my $ME = $0;

END {
  defined fileno STDOUT or return;
  close STDOUT and return;
  warn "$ME: failed to close standard output: $!\n";
  $? ||= 1;
}

# Get the program name from $0 and strip directory names
$_=$0;
s/.*\///;
my $pname = $_;

$opt_o = 'reset';       # Default fence action
$opt_s = 'stonith';     # Default fence binary
$opt_t = 'none';        # Default fence type
$extra_args = '-E';

sub usage
{
    print "Helper that presents a RHCS-style interface for Linux-HA stonith plugins\n\n";
    print "Should never need to use invoked by the user directly\n\n";
    print "\n";
    print "Usage: $pname [options]\n";
    print "\n";
    print "Options:\n";
    print "  -h               usage\n";
    print "  -t <sub agent>   sub agent\n";
    print "  -n <name>        nodename\n";
    print "  -o <string>      Action:  on | off | reset (default) | stat | hostlist\n";
    print "  -s <stonith>     stonith command\n";
    print "  -q               quiet mode\n";
    print "  -V               version\n";

    exit 0;
}

sub fail
{
  ($msg) = @_;
  print $msg."\n" unless defined $opt_q;
  $t->close if defined $t;
  exit 1;
}

sub fail_usage
{
  ($msg)=@_;
  print STDERR $msg."\n" if $msg;
  print STDERR "Please use '-h' for usage.\n";
  exit 1;
}

sub version
{
  print "1.0.0\n";

  exit 0;
}

sub get_options_stdin
{
    my $opt;
    my $line = 0;
    while( defined($in = <>) )
    {
        $_ = $in;
        chomp;

	# strip leading and trailing whitespace
        s/^\s*//;
        s/\s*$//;

	# skip comments
        next if /^#/;

        $line+=1;
        $opt=$_;
        next unless $opt;

        ($name,$val)=split /\s*=\s*/, $opt;

        if ( $name eq "" )
        {  
           print STDERR "parse error: illegal name in option $line\n";
           exit 2;
	}
	
        # DO NOTHING -- this field is used by fenced
	elsif ($name eq "agent" ) {} 

	elsif ($name eq "plugin" ) 
	{ 
	    $opt_t = $val;
	} 
        elsif ($name eq "option" || $name eq "e
{
                                          C                                                                                              Q                                                                    6             6              C             $       j$       $t        $t       4 h       x$|       $t        = 4                  J$x       q$      libcrmcommon.so.2 __gmon_start__ _Jv_RegisterClasses cl_log _init crm_log_init_quiet calculate_xml_versioned_digest apply_xml_diff dump_xml_formatted crm_element_value stdin2xml crm_get_option filename2xml crm_help diff_xml_object crm_log_level crm_set_options crm_bump_log_level _fini string2xml libcib.so.1 diff_cib_object apply_cib_diff libncurses.so.5 libcoroipcc.so.4 libcpg.so.4 libcfg.so.4 libconfdb.so.4 libgnutls.so.26 libplumb.so.2 libpils.so.2 libbz2.so.1.0 libxslt.so.1 libxml2.so.2 xmlFreeNode xmlFreeDoc xmlDocGetRootElement xmlUnlinkNode libc.so.6 _IO_stdin_used fflush optind __stack_chk_fail putchar stdout optarg stderr fwrite fprintf __libc_start_main free libuuid.so.1 libpam.so.0 librt.so.1 libdl.so.2 libglib-2.0.so.0 libltdl.so.7 _edata __bss_start _end GLIBC_2.4 GLIBC_2.0 LIBXML2_2.4.30                                                                      *      0
ii     
   
ii                    L         !      $t  "    $x  (    $|  $    $       $  )    !      !      !      !      !      !      !      !  	    !  
    !      !      !  
    !      !      !      !      !      !      !      !      !      !      !      !      !      "       "      "      "      !|  B ? ;H/  A H 	aH H  | 8! N  |)xT! 68   !|  =  XH 	            !|  ? $  $/  @ d???; ; P?$p;@@ 0;$`   9) U :?  | .|	N!?  @A8  $ $   