use warnings;
use base qw(Exporter);
use Symbol qw(gensym);
+use IO::Handle;
use PublicInbox::ProcessPipe;
our @EXPORT_OK = qw/which spawn popen_rd/;
open my $fh, '>', $f or die "failed to open $f: $!\n";
flock($fh, LOCK_EX) or die "LOCK_EX failed on $f: $!\n";
eval 'use Inline C => $vfork_spawn';
+ my $err = $@;
flock($fh, LOCK_UN) or die "LOCK_UN failed on $f: $!\n";
+ die $err if $err;
};
if ($@) {
warn "Inline::C failed for vfork: $@\n";
sub popen_rd {
my ($cmd, $env, $opts) = @_;
- unless (wantarray || defined $vfork_spawn || defined $env) {
- open my $fh, '-|', @$cmd or
- die('open `'.join(' ', @$cmd) . " pipe failed: $!\n");
- return $fh
- }
pipe(my ($r, $w)) or die "pipe: $!\n";
$opts ||= {};
my $blocking = $opts->{Blocking};
- $r->blocking($blocking) if defined $blocking;
+ IO::Handle::blocking($r, $blocking) if defined $blocking;
$opts->{1} = fileno($w);
my $pid = spawn($cmd, $env, $opts);
- close $w;
return ($r, $pid) if wantarray;
my $ret = gensym;
tie *$ret, 'PublicInbox::ProcessPipe', $pid, $r;