The following commit has been merged in the sourcev3 branch:
commit 1a4277f41bd2fd62dac94cdddea2d4db3eccbb5a
Author: Raphael Hertzog <[EMAIL PROTECTED]>
Date:   Fri Feb 15 19:30:21 2008 +0100

    Dpkg::IPC: extend fork_and_exec() to create pipes on request
    
    * scripts/Dpkg/IPC.pm (fork_and_exec): Now accept from_pipe and
    to_pipe parameters that should point to a scalar reference. The
    scalar will be set with the filehandle of the other side of the
    created pipe.

diff --git a/scripts/Dpkg/IPC.pm b/scripts/Dpkg/IPC.pm
index 090ecc9..b3937cd 100644
--- a/scripts/Dpkg/IPC.pm
+++ b/scripts/Dpkg/IPC.pm
@@ -28,6 +28,7 @@ our @EXPORT = qw(fork_and_exec wait_child);
 
 sub fork_and_exec {
     my (%opts) = @_;
+    $opts{"close_in_child"} ||= [];
     error("exec parameter is mandatory in fork_and_exec()") unless 
$opts{"exec"};
     my @prog;
     if (ref($opts{"exec"}) =~ /ARRAY/) {
@@ -37,6 +38,20 @@ sub fork_and_exec {
     } else {
        error(_g("invalid exec parameter in fork_and_exec()"));
     }
+    # Create pipes if needed
+    my ($input_pipe, $output_pipe);
+    if ($opts{"from_pipe"}) {
+       pipe($opts{"from_handle"}, $input_pipe) ||
+               syserr(_g("pipe for %s"), "@prog");
+       ${$opts{"from_pipe"}} = $input_pipe;
+       push @{$opts{"close_in_child"}}, $input_pipe;
+    }
+    if ($opts{"to_pipe"}) {
+       pipe($output_pipe, $opts{"to_handle"}) ||
+               syserr(_g("pipe for %s"), "@prog");
+       ${$opts{"to_pipe"}} = $output_pipe;
+       push @{$opts{"close_in_child"}}, $output_pipe;
+    }
     # Fork and exec
     my $pid = fork();
     syserr(_g("fork for %s"), "@prog") unless defined $pid;

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to