From 94ae13cf01361a44d37006d0b9d8ac9f92ff6976 Mon Sep 17 00:00:00 2001 From: Duncan Ferguson Date: Fri, 18 Jun 2010 23:48:47 +0100 Subject: [PATCH] Revert "Further functionality changes - still nothing working" This reverts commit dc233c0cfd406c2c6f8cb291e2472e6538347936. --- bin/cssh | 128 ++++++++++++++------- lib/App/ClusterSSH.pm | 2 +- lib/App/ClusterSSH/Gui/Terminal.pm | 17 +-- lib/App/ClusterSSH/Gui/Terminal/Command.pm | 21 +--- t/25gui_command.t | 4 +- 5 files changed, 102 insertions(+), 70 deletions(-) diff --git a/bin/cssh b/bin/cssh index 1fa366f..0ffcd2d 100755 --- a/bin/cssh +++ b/bin/cssh @@ -123,6 +123,8 @@ my %windows; # hash for all window definitions my %menus; # hash for all menu definitions my @servers; # array of servers provided on cmdline my %servers; # hash of server cx info +my $helper_script = ""; +my $xdisplay; my %keyboardmap; my $sysconfigdir = "/etc"; my %ssh_hostnames; @@ -828,23 +830,23 @@ sub send_text($@) { for my $event (qw/KeyPress KeyRelease/) { logmsg( 2, "sending event=$event code=:$code: state=:$state:" ); - $app->gui->xdisplay->SendEvent( + $xdisplay->SendEvent( $servers{$svr}{wid}, 0, - $app->gui->xdisplay->pack_event_mask($event), - $app->gui->xdisplay->pack_event( + $xdisplay->pack_event_mask($event), + $xdisplay->pack_event( 'name' => $event, 'detail' => $code, 'state' => $state, 'time' => time(), 'event' => $servers{$svr}{wid}, - 'root' => $app->gui->xdisplay->root(), + 'root' => $xdisplay->root(), 'same_screen' => 1, ), ); } } - $app->gui->xdisplay->flush(); + $xdisplay->flush(); } sub send_text_to_all_servers { @@ -862,15 +864,15 @@ sub send_resizemove($$$$$) { logmsg( 3, "Moving window $win to x:$x_pos y:$y_pos (size x:$x_siz y:$y_siz)" ); - #logmsg( 2, "resize move normal: ", $app->gui->xdisplay->atom('WM_NORMAL_HINTS') ); - #logmsg( 2, "resize move size: ", $app->gui->xdisplay->atom('WM_SIZE_HINTS') ); + #logmsg( 2, "resize move normal: ", $xdisplay->atom('WM_NORMAL_HINTS') ); + #logmsg( 2, "resize move size: ", $xdisplay->atom('WM_SIZE_HINTS') ); # set the window to have "user" set size & position, rather than "program" - $app->gui->xdisplay->req( + $xdisplay->req( 'ChangeProperty', $win, - $app->gui->xdisplay->atom('WM_NORMAL_HINTS'), - $app->gui->xdisplay->atom('WM_SIZE_HINTS'), + $xdisplay->atom('WM_NORMAL_HINTS'), + $xdisplay->atom('WM_SIZE_HINTS'), 32, 'Replace', @@ -878,7 +880,7 @@ sub send_resizemove($$$$$) { pack( 'LLLLL' . 'x[L]' x 12, 1 | 2, $x_pos, $y_pos, $x_siz, $y_siz ), ); - $app->gui->xdisplay->req( + $xdisplay->req( 'ConfigureWindow', $win, 'x' => $x_pos, @@ -887,7 +889,51 @@ sub send_resizemove($$$$$) { 'height' => $y_siz, ); - #$app->gui->xdisplay->flush(); # dont flush here, but after all tiling worked out + #$xdisplay->flush(); # dont flush here, but after all tiling worked out +} + +sub setup_helper_script() { + logmsg( 2, "Setting up helper script" ); + $helper_script = <<" HERE"; + my \$pipe=shift; + my \$svr=shift; + my \$user=shift; + my \$port=shift; + my \$command="$config{$config{comms}} $config{$config{comms}."_args"} "; + open(PIPE, ">", \$pipe) or die("Failed to open pipe: \$!\\n"); + print PIPE "\$\$:\$ENV{WINDOWID}" + or die("Failed to write to pipe: $!\\n"); + close(PIPE) or die("Failed to close pipe: $!\\n"); + if(\$svr =~ m/==\$/) + { + \$svr =~ s/==\$//; + warn("\\nWARNING: failed to resolve IP address for \$svr.\\n\\n" + ); + sleep 5; + } + if(\$user) { + unless("$config{comms}" eq "telnet") { + \$user = \$user ? "-l \$user " : ""; + \$command .= \$user; + } + } + if("$config{comms}" eq "telnet") { + \$command .= "\$svr \$port"; + } else { + if (\$port) { + \$command .= "-p \$port \$svr"; + } else { + \$command .= "\$svr"; + } + } + \$command .= " $config{command} || sleep 5"; +# warn("Running:\$command\\n"); # for debug purposes + exec(\$command); + HERE + + # eval $helper_script || die ($@); # for debug purposes + logmsg( 2, $helper_script ); + logmsg( 2, "Helper script done" ); } sub split_hostname { @@ -965,10 +1011,9 @@ sub open_client_windows(@) { my $server = App::ClusterSSH::Host->parse_host_string($_); logmsg( 2, 'Working on server ', $server, ' for ', $_ ); - my $terminal = App::ClusterSSH::Gui::Terminal->new( host => $server, comms => $config{ $config{comms} }, terminal => $config{terminal},); + my $terminal = App::ClusterSSH::Host->new( host => $server, ); logmsg( 2, 'Terminal ID: ', $terminal->get_id, ' for ', $_ ); - my $color = ''; if ( $config{terminal_colorize} ) { my $c = pick_color($server); @@ -1039,7 +1084,7 @@ sub show_console() { # fudge the counter to drop a redraw event; $config{internal_map_count} -= 4; - $app->gui->xdisplay->flush(); + $xdisplay->flush(); $windows{main_window}->update(); select( undef, undef, undef, 0.2 ); #sleep for a mo @@ -1077,9 +1122,9 @@ sub retile_hosts { "Not meant to be tiling; just reshow windows as they were" ); foreach my $server ( reverse( keys(%servers) ) ) { - $app->gui->xdisplay->req( 'MapWindow', $servers{$server}{wid} ); + $xdisplay->req( 'MapWindow', $servers{$server}{wid} ); } - $app->gui->xdisplay->flush(); + $xdisplay->flush(); show_console(); return; } @@ -1110,8 +1155,8 @@ sub retile_hosts { + $config{terminal_decoration_height}; # fetch screen size - $config{internal_screen_height} = $app->gui->xdisplay->{height_in_pixels}; - $config{internal_screen_width} = $app->gui->xdisplay->{width_in_pixels}; + $config{internal_screen_height} = $xdisplay->{height_in_pixels}; + $config{internal_screen_width} = $xdisplay->{width_in_pixels}; # Now, work out how many columns of terminals we can fit on screen $config{internal_columns} = int( @@ -1197,10 +1242,10 @@ sub retile_hosts { logmsg( 3, "x:$current_x y:$current_y, r:$current_row c:$current_col" ); - $app->gui->xdisplay->req( 'UnmapWindow', $servers{$server}{wid} ); + $xdisplay->req( 'UnmapWindow', $servers{$server}{wid} ); if ( $config{unmap_on_redraw} =~ /yes/i ) { - $app->gui->xdisplay->req( 'UnmapWindow', $servers{$server}{wid} ); + $xdisplay->req( 'UnmapWindow', $servers{$server}{wid} ); } logmsg( 2, "Moving $server window" ); @@ -1211,7 +1256,7 @@ sub retile_hosts { $config{internal_terminal_height} ); - $app->gui->xdisplay->flush(); + $xdisplay->flush(); select( undef, undef, undef, 0.1 ); # sleep for a moment for the WM if ( $config{window_tiling_direction} =~ /right/i ) { @@ -1250,20 +1295,20 @@ sub retile_hosts { if ( $config{window_tiling_direction} =~ /right/i ) { foreach my $server ( reverse(@hosts) ) { logmsg( 2, "Setting focus on $server" ); - $app->gui->xdisplay->req( 'MapWindow', $servers{$server}{wid} ); + $xdisplay->req( 'MapWindow', $servers{$server}{wid} ); # flush every time and wait a moment (The WMs are so slow...) - $app->gui->xdisplay->flush(); + $xdisplay->flush(); select( undef, undef, undef, 0.1 ); # sleep for a mo } } else { foreach my $server (@hosts) { logmsg( 2, "Setting focus on $server" ); - $app->gui->xdisplay->req( 'MapWindow', $servers{$server}{wid} ); + $xdisplay->req( 'MapWindow', $servers{$server}{wid} ); # flush every time and wait a moment (The WMs are so slow...) - $app->gui->xdisplay->flush(); + $xdisplay->flush(); select( undef, undef, undef, 0.1 ); # sleep for a mo } } @@ -1289,16 +1334,16 @@ sub capture_terminal() { my %atoms; - for my $atom ( $app->gui->xdisplay->req( 'ListProperties', $servers{loki}{wid} ) ) { - $atoms{ $app->gui->xdisplay->atom_name($atom) } - = $app->gui->xdisplay->req( 'GetProperty', $servers{loki}{wid}, + for my $atom ( $xdisplay->req( 'ListProperties', $servers{loki}{wid} ) ) { + $atoms{ $xdisplay->atom_name($atom) } + = $xdisplay->req( 'GetProperty', $servers{loki}{wid}, $atom, "AnyPropertyType", 0, 200, 0 ); - print $app->gui->xdisplay->atom_name($atom), " ($atom) => "; + print $xdisplay->atom_name($atom), " ($atom) => "; print "join here\n"; print join( "\n", - $app->gui->xdisplay->req( + $xdisplay->req( 'GetProperty', $servers{loki}{wid}, $atom, "AnyPropertyType", 0, 200, 0 ) @@ -1308,10 +1353,10 @@ sub capture_terminal() { print "list by number\n"; for my $atom ( 1 .. 90 ) { - print "$atom: ", $app->gui->xdisplay->req( 'GetAtomName', $atom ), "\n"; + print "$atom: ", $xdisplay->req( 'GetAtomName', $atom ), "\n"; print join( "\n", - $app->gui->xdisplay->req( + $xdisplay->req( 'GetProperty', $servers{loki}{wid}, $atom, "AnyPropertyType", 0, 200, 0 ) @@ -1323,7 +1368,7 @@ sub capture_terminal() { print "size hints\n"; print join( "\n", - $app->gui->xdisplay->req( + $xdisplay->req( 'GetProperty', $servers{loki}{wid}, 42, "AnyPropertyType", 0, 200, 0 ) @@ -1336,10 +1381,10 @@ sub capture_terminal() { } print "geom\n"; - print join " ", $app->gui->xdisplay->req( 'GetGeometry', $servers{loki}{wid} ), $/; + print join " ", $xdisplay->req( 'GetGeometry', $servers{loki}{wid} ), $/; print "attrib\n"; print join " ", - $app->gui->xdisplay->req( 'GetWindowAttributes', $servers{loki}{wid} ), + $xdisplay->req( 'GetWindowAttributes', $servers{loki}{wid} ), $/; } @@ -1805,23 +1850,23 @@ sub key_event { "Sending event $event with code $keycode (state=$state) to window $servers{$_}{wid}" ); - $app->gui->xdisplay->SendEvent( + $xdisplay->SendEvent( $servers{$_}{wid}, 0, - $app->gui->xdisplay->pack_event_mask($event), - $app->gui->xdisplay->pack_event( + $xdisplay->pack_event_mask($event), + $xdisplay->pack_event( 'name' => $event, 'detail' => $keycode, 'state' => $state, 'time' => time(), 'event' => $servers{$_}{wid}, - 'root' => $app->gui->xdisplay->root(), + 'root' => $xdisplay->root(), 'same_screen' => 1, ) ) || warn("Error returned from SendEvent: $!"); } } - $app->gui->xdisplay->flush(); + $xdisplay->flush(); } sub create_menubar() { @@ -2036,6 +2081,7 @@ change_main_window_title(); logmsg( 2, "Capture map events" ); capture_map_events(); +setup_helper_script(); open_client_windows(@servers); # Check here if we are tiling windows. Here instead of in func so diff --git a/lib/App/ClusterSSH.pm b/lib/App/ClusterSSH.pm index 18b43de..e96d633 100644 --- a/lib/App/ClusterSSH.pm +++ b/lib/App/ClusterSSH.pm @@ -45,7 +45,7 @@ sub REAPER { my $kid; do { $kid = waitpid( -1, WNOHANG ); - #logmsg( 2, "REAPER currently returns: $kid" ); + logmsg( 2, "REAPER currently returns: $kid" ); } until ( $kid == -1 || $kid == 0 ); } diff --git a/lib/App/ClusterSSH/Gui/Terminal.pm b/lib/App/ClusterSSH/Gui/Terminal.pm index 71e8205..66e2ede 100644 --- a/lib/App/ClusterSSH/Gui/Terminal.pm +++ b/lib/App/ClusterSSH/Gui/Terminal.pm @@ -7,9 +7,6 @@ use version; our $VERSION = version->new(qw$Revision: 1$); use Carp; -use File::Temp qw/:POSIX/; -use POSIX qw/:sys_wait_h strftime mkfifo/; -use Fcntl; use base qw/ App::ClusterSSH::Base /; use App::ClusterSSH::Gui::Terminal::Command; @@ -46,26 +43,24 @@ sub new { # this is the child # Since this is the child, we can mark any server unresolved without # affecting the main program - $self->{command} = App::ClusterSSH::Gui::Terminal::Command->new(%args, pipe => $self->{pipenm},); - $self->debug( 0, 'Running: ', $self->{command}->script ); - #exec($^X,'-e',$self->{command}->script,'--', '-d', '-b', 'ssh', '-a', 'a_args', '-p','sdfsdf','options') == 0 or die( 'Exec failed: ', $! ); - exec('echo',$^X,'-e',$self->{command}->script,'--', '-c','hostname') == 0 or die( 'Exec failed: ', $! ); + $self->{command} = App::ClusterSSH::Terminal::Command->new(); + $self->debug( 4, 'Running: ', $self->{command} ); + exec($self->{command}, '-p','sdfsdf','options') == 0 or die( 'Exec failed: ', $! ); } - die; if ( !$terminal_id_for{ $args{host}->{hostname} } ) { $terminal_id_for{ $args{host}->{hostname} } = $self; - $self->{id} = $args{host}->{hostname}; + $self->{id} = $terminal_id_for{ $args{host}->{hostname} }; } else { - my $count = 1; + my $count = 0; until ( !$terminal_id_for{ $args{host}->{hostname} . ' ' . $count } ) { $count++; } $terminal_id_for{ $args{host}->{hostname} . ' ' . $count } = $self; $self->{id} - = $args{host}->{hostname} . ' ' . $count ; + = $terminal_id_for{ $args{host}->{hostname} . ' ' . $count }; } return $self; } diff --git a/lib/App/ClusterSSH/Gui/Terminal/Command.pm b/lib/App/ClusterSSH/Gui/Terminal/Command.pm index 48eb519..66ff012 100644 --- a/lib/App/ClusterSSH/Gui/Terminal/Command.pm +++ b/lib/App/ClusterSSH/Gui/Terminal/Command.pm @@ -15,9 +15,6 @@ sub new { my $self = $class->SUPER::new(%args); -use Data::Dump qw(dump); -die dump \%args; - return $self; } @@ -45,38 +42,32 @@ sub script() { my %o; getopts( "p:s:u:p:c:d:b:a:", \%o ); -# print "%_ => $o{$_}",$/ foreach (keys %o); - if($o{p}) { open( my $pipe, ">", $o{p} ) or die( "Failed to open pipe: ", $!, $/ ); - print {$pipe} ($$, ":", $ENV{WINDOWID} || "ERROR") + print {$pipe} $$, ":", $ENV{WINDOWID} or die( "Failed to write to pipe: ", $!, $/ ); close($pipe) or die( "Failed to close pipe: ", $!, $/ ); } - my $command = join( " ", $o{b}||" ", $o{a}||" ", ); + my $command = join( " ", $o{b}, $o{a}, ); if ( $o{u} ) { - if ( $o{b} && $o{b} !~ /telnet$/ ) { + if ( $o{b} !~ /telnet$/ ) { $command .= join( " ", "-l", $o{u} ); } } - if ( $o{b} && $o{b} =~ /telnet$/ ) { + if ( $o{b} =~ /telnet$/ ) { $command .= join( " ", $o{s}, $o{p} ); } else { if ( $o{p} ) { $command .= join( " ", "-p", $o{p} ); } - if($o{s}) { - $command .= $o{s}; - } + $command .= $o{s}; } - if($o{c}) { - $command .= $o{c}; - } + $command .= $o{c}; if ( $o{d} ) { warn( "Running: ", $command, $/ ); diff --git a/t/25gui_command.t b/t/25gui_command.t index c23b58c..c613d31 100644 --- a/t/25gui_command.t +++ b/t/25gui_command.t @@ -18,8 +18,8 @@ my $obj; trap { $obj = App::ClusterSSH::Gui::Terminal::Command->new(); }; -is( $trap->leaveby, 'return', 'returned ok' ); -is( $trap->die, undef, 'returned ok' ); +is( $trap->leaveby, 'die', 'returned ok' ); +like( $trap->die, qr/command is undefined at /, 'Got appropriate croak message' ); is( $trap->stderr, '', 'Expecting no STDERR' ); is( $trap->stdout, '', 'Expecting no STDOUT' );