Add more debug info and also -v

This commit is contained in:
duncan_ferguson 2004-05-04 09:33:57 +00:00
parent dcd652e640
commit 35d85c1238

View file

@ -66,7 +66,13 @@ use Fcntl;
use Getopt::Std;
my %options;
getopts('x:y:z:d', \%options);
getopts('vx:y:z:d', \%options);
if($options{v})
{
print("Version: $VERSION\n");
exit;
}
unless ($ENV{TERM}) {
$ENV{TERM} = 'xterm';
@ -74,6 +80,9 @@ unless ($ENV{TERM}) {
$SIG{CHLD}='IGNORE';
# autoflush output
$|=1;
if($options{x})
{
if( ! -p $options{x} || ! $options{y} || ! $options{z})
@ -101,6 +110,7 @@ if($options{x})
if($pid==0)
{
# this is the child
print "ARGV=:",join(" ",@ARGV),":\n" if ($options{d});
exec(@ARGV) || die("Could not exec within x: $!");
} else {
print "Forked to:$pid from $$" if($options{d});
@ -121,13 +131,14 @@ if($options{x})
{
if(sysread($PIPELINE,my $chars,10000))
{
print "Pipe removed\n" if ($options{d} && ! -p $options{x});
last if(! -p $options{x});
print "Received:$chars:\n" if ($options{d});
print "Pipe removed\n" if ($options{d} && ! -p $options{x});
last OUTTER if(! -p $options{x});
foreach my $char (split(//, $chars))
{
print "Caught KILLOFF\n" if(ord($char) == $KILLOFF && $options{d});
last OUTTER if(ord($char) == $KILLOFF);
unless(ioctl(STDIN,$TIOCSTI,$char))
{
@ -137,27 +148,33 @@ if($options{x})
}
}
# if we can no longer write to client, it is gone
print "Whoops - $pid no longer there\n" if($options{d} && ! kill(0,$pid));
#print "KILL RETURNED:",kill(0,$pid),$/ if($options{d});
last unless(kill(0,$pid));
# sleep for 1/4s
select(undef,undef,undef,0.25);
}
}
print "Killing $pid\n" if($options{d});
print "Killing $pid\n" if($options{d} && kill(0,$pid));
kill(9,$pid) if (kill(0,$pid));
print "Removing pipe\n" if($options{d} && -p $options{x});
unlink($options{x}) if(-p $options{x});
print "sleeping for 25 seconds for reading any debug\n" if($options{d});
sleep 25 if($options{d});
exit;
}
warn("Weird error - should never get here: $!") if($options{d});
die("Weird error - should never get here: $!");
} else {
warn ("cchp should only be called via cssh/crsh\n") if($options{d});
die ("cchp should only be called via cssh/crsh\n");
}
############################################################################
# $Log$
# Revision 1.5 2004/05/04 09:33:57 duncan_ferguson
# Add more debug info and also -v
#
# Revision 1.4 2004/04/30 14:22:14 duncan_ferguson
# Remove unnecesary IO::Select and IO::Handle code with some rewrite to fix
# bug on redhat that locked code into a loop