The following commit has been merged in the sourcev3 branch:
commit 8809ecced7e0972959891426fb2a9fbf893d3a74
Author: Frank Lichtenheld <[EMAIL PROTECTED]>
Date:   Fri Feb 15 22:58:26 2008 +0100

    Dpkg::IPC: Add a sanitiy_check for options of fork_and_exec
    
    * scripts/Dpkg/IPC.pm (_sanity_check_opts): Check for some
    probable errors in options.
    (fork_and_exec): Apply _sanity_check_opts to the options to
    catch some errors that might go unnoticed otherwise and to
    error out early for some other errors.

diff --git a/scripts/Dpkg/IPC.pm b/scripts/Dpkg/IPC.pm
index cbc1ad0..ee7c2c1 100644
--- a/scripts/Dpkg/IPC.pm
+++ b/scripts/Dpkg/IPC.pm
@@ -105,10 +105,35 @@ but not the pid.
 
 =cut
 
-sub fork_and_exec {
+sub _sanity_check_opts {
     my (%opts) = @_;
+
+    error("exec parameter is mandatory in fork_and_exec()")
+       unless $opts{"exec"};
+
+    my $to = my $from = 0;
+    foreach (qw(file handle string pipe)) {
+       $to++ if $opts{"to_$_"};
+       $from++ if $opts{"from_$_"};
+    }
+    error("not more than one of to_* parameters is allowed")
+       if $to > 1;
+    error("not more than one of from_* parameters is allowed")
+       if $from > 1;
+
+    foreach (qw(to_string from_string to_pipe from_pipe)) {
+       if (exists $opts{$_} and
+           (!ref($opts{$_}) or ref($opts{$_}) ne 'SCALAR')) {
+           error("paramter $_ must be a scalar reference");
+       }
+    }
+
+    return %opts;
+}
+
+sub fork_and_exec {
+    my (%opts) = _sanity_check_opts(@_);
     $opts{"close_in_child"} ||= [];
-    error("exec parameter is mandatory in fork_and_exec()") unless 
$opts{"exec"};
     my @prog;
     if (ref($opts{"exec"}) =~ /ARRAY/) {
        push @prog, @{$opts{"exec"}};

-- 
dpkg's main repository


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

Reply via email to