Simplify pipe management
We don't need to write perl like C.
This commit is contained in:
+4
-10
@@ -217,15 +217,10 @@ if ( (not defined $colors)
|
|||||||
$colors = 0;
|
$colors = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($p_read, $p_write);
|
my $pid = open(my $pipe, "-|");
|
||||||
pipe($p_read, $p_write);
|
|
||||||
my $pid = fork;
|
|
||||||
die "$0: fork: $!\n" unless ( defined $pid );
|
die "$0: fork: $!\n" unless ( defined $pid );
|
||||||
if ( $pid == 0 ) { # child
|
if ( $pid == 0 ) { # child
|
||||||
open STDOUT, ">&", $p_write or die;
|
open(STDERR, ">&STDOUT") or die;
|
||||||
open STDERR, ">&", $p_write or die;
|
|
||||||
close $p_write;
|
|
||||||
close $p_read;
|
|
||||||
|
|
||||||
my @server = ( 'new', '-s' );
|
my @server = ( 'new', '-s' );
|
||||||
|
|
||||||
@@ -249,8 +244,7 @@ if ( $pid == 0 ) { # child
|
|||||||
} else { # parent
|
} else { # parent
|
||||||
my ( $ip, $port, $key );
|
my ( $ip, $port, $key );
|
||||||
my $bad_udp_port_warning = 0;
|
my $bad_udp_port_warning = 0;
|
||||||
close $p_write;
|
LINE: while ( <$pipe> ) {
|
||||||
LINE: while ( <$p_read> ) {
|
|
||||||
chomp;
|
chomp;
|
||||||
if ( m{^MOSH IP } ) {
|
if ( m{^MOSH IP } ) {
|
||||||
if ( defined $ip ) {
|
if ( defined $ip ) {
|
||||||
@@ -271,7 +265,7 @@ if ( $pid == 0 ) { # child
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
waitpid $pid, 0;
|
waitpid $pid, 0;
|
||||||
close $p_read;
|
close $pipe;
|
||||||
|
|
||||||
if ( not defined $ip ) {
|
if ( not defined $ip ) {
|
||||||
die "$0: Did not find remote IP address (is SSH ProxyCommand disabled?).\n";
|
die "$0: Did not find remote IP address (is SSH ProxyCommand disabled?).\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user