blob: 9babb9a375e5fb2a66f216d1968312ec094a6d93 [file] [log] [blame]
Todd Zullingerd13a73e2023-11-16 14:30:10 -05001use 5.008001;
Max Kirillov6c213e82018-07-27 06:48:59 +03002use strict;
3use warnings;
4
5my $body_filename = $ARGV[0];
6my @command = @ARGV[1 .. $#ARGV];
7
8# read data
9my $body_size = -s $body_filename;
10$ENV{"CONTENT_LENGTH"} = $body_size;
11open(my $body_fh, "<", $body_filename) or die "Cannot open $body_filename: $!";
12my $body_data;
13defined read($body_fh, $body_data, $body_size) or die "Cannot read $body_filename: $!";
14close($body_fh);
15
Max Kirillov6c213e82018-07-27 06:48:59 +030016# write data
17my $pid = open(my $out, "|-", @command);
18{
19 # disable buffering at $out
20 my $old_selected = select;
21 select $out;
22 $| = 1;
23 select $old_selected;
24}
25print $out $body_data or die "Cannot write data: $!";
26
Jeff Kinge8f55562021-09-09 18:57:57 -040027$SIG{ALRM} = sub {
28 kill 'KILL', $pid;
Max Kirillov6c213e82018-07-27 06:48:59 +030029 die "Command did not exit after reading whole body";
Jeff Kinge8f55562021-09-09 18:57:57 -040030};
31alarm 60;
32
33my $ret = waitpid($pid, 0);
34if ($ret != $pid) {
35 die "confusing return from waitpid: $ret";
Max Kirillov6c213e82018-07-27 06:48:59 +030036}