6c213e863a
Push passes to another commands, as described in https://public-inbox.org/git/20171129032214.GB32345@sigill.intra.peff.net/ As it gets complicated to correctly track the data length, instead transfer the data through parent process and cut the pipe as the specified length is reached. Do it only when CONTENT_LENGTH is set, otherwise pass the input directly to the forked commands. Add tests for cases: * CONTENT_LENGTH is set, script's stdin has more data, with all combinations of variations: fetch or push, plain or compressed body, correct or truncated input. * CONTENT_LENGTH is specified to a value which does not fit into ssize_t. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Max Kirillov <max@max630.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
38 lines
855 B
Perl
Executable File
38 lines
855 B
Perl
Executable File
#!/usr/bin/perl
|
|
use 5.008;
|
|
use strict;
|
|
use warnings;
|
|
|
|
my $body_filename = $ARGV[0];
|
|
my @command = @ARGV[1 .. $#ARGV];
|
|
|
|
# read data
|
|
my $body_size = -s $body_filename;
|
|
$ENV{"CONTENT_LENGTH"} = $body_size;
|
|
open(my $body_fh, "<", $body_filename) or die "Cannot open $body_filename: $!";
|
|
my $body_data;
|
|
defined read($body_fh, $body_data, $body_size) or die "Cannot read $body_filename: $!";
|
|
close($body_fh);
|
|
|
|
my $exited = 0;
|
|
$SIG{"CHLD"} = sub {
|
|
$exited = 1;
|
|
};
|
|
|
|
# write data
|
|
my $pid = open(my $out, "|-", @command);
|
|
{
|
|
# disable buffering at $out
|
|
my $old_selected = select;
|
|
select $out;
|
|
$| = 1;
|
|
select $old_selected;
|
|
}
|
|
print $out $body_data or die "Cannot write data: $!";
|
|
|
|
sleep 60; # is interrupted by SIGCHLD
|
|
if (!$exited) {
|
|
close($out);
|
|
die "Command did not exit after reading whole body";
|
|
}
|