]> Sergey Matveev's repositories - public-inbox.git/commitdiff
cgi: remove dependency on IPC::Run in CGI
authorEric Wong <e@80x24.org>
Wed, 30 Apr 2014 01:03:30 +0000 (01:03 +0000)
committerEric Wong <e@80x24.org>
Wed, 30 Apr 2014 01:07:35 +0000 (01:07 +0000)
We may not have PATH available on some servers (e.g. webrick)
and must rely on the hardcoded system PATH.  My installation of
IPC::Run does not seem to work without PATH set in the env,
however normal Perl "open" calls work fine.

lib/PublicInbox/Config.pm
public-inbox.cgi

index 364e6091e2281b3b7e06ecf1f97c0d80718a1b14..364f82cd845372c98b59c66d5bcedb531f6ac6d2 100644 (file)
@@ -4,7 +4,6 @@ package PublicInbox::Config;
 use strict;
 use warnings;
 use File::Path::Expand qw/expand_filename/;
-use IPC::Run;
 
 # returns key-value pairs of config directives in a hash
 # if keys may be multi-value, the value is an array ref containing all values
@@ -13,10 +12,13 @@ sub new {
        my ($in, $out);
 
        $file = default_file() unless defined($file);
-       IPC::Run::run([qw/git config --file/, $file, '-l'], \$in, \$out);
-       $? == 0 or die "git config --file $file -l failed: $?\n";
+       my @cmd = (qw/git config/, "--file=$file", '-l');
+       my $cmd = join(' ', @cmd);
+       my $pid = open(my $fh, '-|', @cmd);
+       defined $pid or die "$cmd failed: $!\n";
        my %rv;
-       foreach my $line (split(/\n/, $out)) {
+       foreach my $line (<$fh>) {
+               chomp $line;
                my ($k, $v) = split(/=/, $line, 2);
                my $cur = $rv{$k};
 
@@ -30,6 +32,8 @@ sub new {
                        $rv{$k} = $v;
                }
        }
+       close $fh or die "failed to close ($cmd) pipe: $!\n";
+       $? and warn "$$ $cmd exited with: ($pid) $?\n";
        bless \%rv, $class;
 }
 
index b63223f509fc24cb05905e05c163c621303b7077..da87d2c34800b487cb0ff2d7dc77d5d25bd09d3c 100755 (executable)
@@ -147,13 +147,21 @@ sub mid2blob {
        my $hex = Digest::SHA::sha1_hex($ctx->{mid});
        $hex =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/i or
                        die "BUG: not a SHA-1 hex: $hex";
-       require IPC::Run;
-       my ($in, $blob, $err);
-       open my $null, '+<', '/dev/null' or die "open: $!\n";
-       IPC::Run::run(['git', "--git-dir=$ctx->{git_dir}",
-                       qw(cat-file blob), "HEAD:$1/$2"],
-                       $null, \$blob, $null);
-       $? == 0 ? \$blob : undef;
+
+       my @cmd = ('git', "--git-dir=$ctx->{git_dir}",
+                       qw(cat-file blob), "HEAD:$1/$2");
+       my $cmd = join(' ', @cmd);
+       my $pid = open my $fh, '-|';
+       defined $pid or die "fork failed: $!\n";
+       if ($pid == 0) {
+               open STDERR, '>', '/dev/null'; # ignore errors
+               exec @cmd;
+               exit 1;
+       } else {
+               my $blob = eval { local $/; <$fh> };
+               close $fh;
+               $? == 0 ? \$blob : undef;
+       }
 }
 
 # /$LISTNAME/m/$MESSAGE_ID.txt                    -> raw original