oh-my-git/scripts/net-test
mundifex c2a2f87f4c Fix deadlock in stash levels
- use vertical tab character instead of "MAGIC" string to denote end of input
- check for terminator using pattern match instead of eq

Users are unable to provide special characters to Bash process so this should
be relatively safe. Pattern match succeeds even when `git stash` omits newline
while rendering commit subjects.

Fixes git-learning-game/oh-my-git#56
2021-03-26 21:34:22 -05:00

60 lines
1.3 KiB
Perl
Executable file

#!/usr/bin/env perl
use IPC::Open3;
use IO::Socket;
my $bash = "bash";
if ($#ARGV >= 0) {
$bash = $ARGV[0];
}
my $pid = open3(my $in, my $out, my $err, $bash);
$socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1",
PeerPort => 6666,
Proto => "tcp",
Type => SOCK_STREAM);
print $in 'export PATH="/usr/bin:/mingw64/bin:$PATH"' . "\n";
while(true) {
#STDOUT->flush();
my $len;
$socket->recv($len, 4);
my $actual_len = unpack("L", $len);
if ($actual_len == 0) {
#print("not connected");
exit;
}
#print("still connected");
my $s2;
$socket->recv($s2, $actual_len);
#print($s2);
STDOUT->flush();
$s = "";
$command = $s2 . "\necho -e \"\\v\"\n";
print $in $command;
inner_while: while (true) {
$line = <$out>;
if ($line =~ s/\cK//) {
STDOUT->flush();
last inner_while;
}
$s = $s . $line;
}
#print "got complete output";
#print $s;
#print length($s);
STDOUT->flush();
my $send_length = pack("L", length($s));
$socket->send($send_length);
$socket->send($s);
my $exit_code = pack("L", 0);
$socket->send($exit_code);
}