Browse Source

libdpkg-perl: Rename Dpkg::IPC::fork_and_exec() to Dpkg::IPC::spawn()

Guillem Jover 16 years ago
parent
commit
45dc465f07

+ 1 - 0
debian/changelog

@@ -63,6 +63,7 @@ dpkg (1.15.6) UNRELEASED; urgency=low
   * Fix error handling, clean up and refactor compression code.
   * Fix error handling, clean up and refactor compression code.
     Thanks to Jonathan Nieder for several of the patches.
     Thanks to Jonathan Nieder for several of the patches.
   * Do not print unambiguous epoch on dpkg file overwrite error.
   * Do not print unambiguous epoch on dpkg file overwrite error.
+  * Rename Dpkg::IPC::fork_and_exec() to Dpkg::IPC::spawn().
 
 
   [ Modestas Vainius ]
   [ Modestas Vainius ]
   * Implement symbol patterns (Closes: #563752). From now on, it is possible to
   * Implement symbol patterns (Closes: #563752). From now on, it is possible to

+ 4 - 4
scripts/Dpkg/Compression/Process.pm

@@ -133,7 +133,7 @@ sub _sanity_check {
 Starts a compressor program. You must indicate where it will read its
 Starts a compressor program. You must indicate where it will read its
 uncompressed data from and where it will write its compressed data to.
 uncompressed data from and where it will write its compressed data to.
 This is accomplished by passing one parameter C<to_*> and one parameter
 This is accomplished by passing one parameter C<to_*> and one parameter
-C<from_*> as accepted by B<Dpkg::IPC::fork_and_exec>.
+C<from_*> as accepted by B<Dpkg::IPC::spawn>.
 
 
 You must call C<wait_end_process> after having called this method to
 You must call C<wait_end_process> after having called this method to
 properly close the sub-process (and verify that it exited without error).
 properly close the sub-process (and verify that it exited without error).
@@ -146,7 +146,7 @@ sub compress {
     my @prog = $self->get_compress_cmdline();
     my @prog = $self->get_compress_cmdline();
     $opts{"exec"} = \@prog;
     $opts{"exec"} = \@prog;
     $self->{"cmdline"} = "@prog";
     $self->{"cmdline"} = "@prog";
-    $self->{"pid"} = fork_and_exec(%opts);
+    $self->{"pid"} = spawn(%opts);
     delete $self->{"pid"} if $opts{"to_string"}; # wait_child already done
     delete $self->{"pid"} if $opts{"to_string"}; # wait_child already done
 }
 }
 
 
@@ -155,7 +155,7 @@ sub compress {
 Starts a decompressor program. You must indicate where it will read its
 Starts a decompressor program. You must indicate where it will read its
 compressed data from and where it will write its uncompressed data to.
 compressed data from and where it will write its uncompressed data to.
 This is accomplished by passing one parameter C<to_*> and one parameter
 This is accomplished by passing one parameter C<to_*> and one parameter
-C<from_*> as accepted by B<Dpkg::IPC::fork_and_exec>.
+C<from_*> as accepted by B<Dpkg::IPC::spawn>.
 
 
 You must call C<wait_end_process> after having called this method to
 You must call C<wait_end_process> after having called this method to
 properly close the sub-process (and verify that it exited without error).
 properly close the sub-process (and verify that it exited without error).
@@ -168,7 +168,7 @@ sub uncompress {
     my @prog = $self->get_uncompress_cmdline();
     my @prog = $self->get_uncompress_cmdline();
     $opts{"exec"} = \@prog;
     $opts{"exec"} = \@prog;
     $self->{"cmdline"} = "@prog";
     $self->{"cmdline"} = "@prog";
-    $self->{"pid"} = fork_and_exec(%opts);
+    $self->{"pid"} = spawn(%opts);
     delete $self->{"pid"} if $opts{"to_string"}; # wait_child already done
     delete $self->{"pid"} if $opts{"to_string"}; # wait_child already done
 }
 }
 
 

+ 6 - 6
scripts/Dpkg/IPC.pm

@@ -23,7 +23,7 @@ use Dpkg::ErrorHandling;
 use Dpkg::Gettext;
 use Dpkg::Gettext;
 
 
 use base qw(Exporter);
 use base qw(Exporter);
-our @EXPORT = qw(fork_and_exec wait_child);
+our @EXPORT = qw(spawn wait_child);
 
 
 =head1 NAME
 =head1 NAME
 
 
@@ -40,7 +40,7 @@ from you.
 
 
 =over 4
 =over 4
 
 
-=item fork_and_exec
+=item spawn
 
 
 Creates a child process and executes another program in it.
 Creates a child process and executes another program in it.
 The arguments are interpreted as a hash of options, specifying
 The arguments are interpreted as a hash of options, specifying
@@ -97,7 +97,7 @@ C<wait_child> option.
 =item wait_child
 =item wait_child
 
 
 Scalar. If containing a true value, wait_child() will be called before
 Scalar. If containing a true value, wait_child() will be called before
-returning. The return value will of fork_and_exec() will be a true value,
+returning. The return value will of spawn() will be a true value,
 but not the pid.
 but not the pid.
 
 
 =item nocheck
 =item nocheck
@@ -130,7 +130,7 @@ listed in the array before calling exec.
 sub _sanity_check_opts {
 sub _sanity_check_opts {
     my (%opts) = @_;
     my (%opts) = @_;
 
 
-    internerr("exec parameter is mandatory in fork_and_exec()")
+    internerr("exec parameter is mandatory in spawn()")
 	unless $opts{"exec"};
 	unless $opts{"exec"};
 
 
     my $to = my $error_to = my $from = 0;
     my $to = my $error_to = my $from = 0;
@@ -177,7 +177,7 @@ sub _sanity_check_opts {
     return %opts;
     return %opts;
 }
 }
 
 
-sub fork_and_exec {
+sub spawn {
     my (%opts) = _sanity_check_opts(@_);
     my (%opts) = _sanity_check_opts(@_);
     $opts{"close_in_child"} ||= [];
     $opts{"close_in_child"} ||= [];
     my @prog;
     my @prog;
@@ -186,7 +186,7 @@ sub fork_and_exec {
     } elsif (not ref($opts{"exec"})) {
     } elsif (not ref($opts{"exec"})) {
 	push @prog, $opts{"exec"};
 	push @prog, $opts{"exec"};
     } else {
     } else {
-	internerr("invalid exec parameter in fork_and_exec()");
+	internerr("invalid exec parameter in spawn()");
     }
     }
     my ($from_string_pipe, $to_string_pipe, $error_to_string_pipe);
     my ($from_string_pipe, $to_string_pipe, $error_to_string_pipe);
     if ($opts{"to_string"}) {
     if ($opts{"to_string"}) {

+ 5 - 5
scripts/Dpkg/Shlibs/Cppfilt.pm

@@ -40,11 +40,11 @@ sub get_cppfilt {
     } else {
     } else {
 	$filt = { from => undef, to => undef,
 	$filt = { from => undef, to => undef,
 	            last_symbol => "", last_result => "" };
 	            last_symbol => "", last_result => "" };
-	$filt->{pid} = fork_and_exec(exec => [ 'c++filt',
-	                                       '--no-verbose',
-	                                       "--format=$type" ],
-	                             from_pipe => \$filt->{from},
-	                             to_pipe => \$filt->{to});
+	$filt->{pid} = spawn(exec => [ 'c++filt',
+	                               '--no-verbose',
+	                               "--format=$type" ],
+	                     from_pipe => \$filt->{from},
+	                     to_pipe => \$filt->{to});
 	internerr(_g("unable to execute c++filt")) unless defined $filt->{from};
 	internerr(_g("unable to execute c++filt")) unless defined $filt->{from};
 	$filt->{from}->autoflush(1);
 	$filt->{from}->autoflush(1);
 
 

+ 17 - 17
scripts/Dpkg/Source/Archive.pm

@@ -34,22 +34,22 @@ use base 'Dpkg::Compression::FileHandle';
 sub create {
 sub create {
     my ($self, %opts) = @_;
     my ($self, %opts) = @_;
     $opts{"options"} ||= [];
     $opts{"options"} ||= [];
-    my %fork_opts;
+    my %spawn_opts;
     # Possibly run tar from another directory
     # Possibly run tar from another directory
     if ($opts{"chdir"}) {
     if ($opts{"chdir"}) {
-        $fork_opts{"chdir"} = $opts{"chdir"};
+        $spawn_opts{"chdir"} = $opts{"chdir"};
         *$self->{"chdir"} = $opts{"chdir"};
         *$self->{"chdir"} = $opts{"chdir"};
     }
     }
     # Redirect input/output appropriately
     # Redirect input/output appropriately
     $self->ensure_open("w");
     $self->ensure_open("w");
-    $fork_opts{"to_handle"} = $self->get_filehandle();
-    $fork_opts{"from_pipe"} = \*$self->{'tar_input'};
+    $spawn_opts{"to_handle"} = $self->get_filehandle();
+    $spawn_opts{"from_pipe"} = \*$self->{'tar_input'};
     # Call tar creation process
     # Call tar creation process
-    $fork_opts{"delete_env"} = [ "TAR_OPTIONS" ];
-    $fork_opts{'exec'} = [ 'tar', '--null', '-T', '-', '--numeric-owner',
-                           '--owner', '0', '--group', '0',
-			   @{$opts{"options"}}, '-cf', '-' ];
-    *$self->{"pid"} = fork_and_exec(%fork_opts);
+    $spawn_opts{"delete_env"} = [ "TAR_OPTIONS" ];
+    $spawn_opts{'exec'} = [ 'tar', '--null', '-T', '-', '--numeric-owner',
+                            '--owner', '0', '--group', '0',
+                            @{$opts{"options"}}, '-cf', '-' ];
+    *$self->{"pid"} = spawn(%spawn_opts);
     *$self->{"cwd"} = getcwd();
     *$self->{"cwd"} = getcwd();
 }
 }
 
 
@@ -98,12 +98,12 @@ sub extract {
     $opts{"options"} ||= [];
     $opts{"options"} ||= [];
     $opts{"in_place"} ||= 0;
     $opts{"in_place"} ||= 0;
     $opts{"no_fixperms"} ||= 0;
     $opts{"no_fixperms"} ||= 0;
-    my %fork_opts = (wait_child => 1);
+    my %spawn_opts = (wait_child => 1);
 
 
     # Prepare destination
     # Prepare destination
     my $tmp;
     my $tmp;
     if ($opts{"in_place"}) {
     if ($opts{"in_place"}) {
-        $fork_opts{"chdir"} = $dest;
+        $spawn_opts{"chdir"} = $dest;
         $tmp = $dest; # So that fixperms call works
         $tmp = $dest; # So that fixperms call works
     } else {
     } else {
         my $template = basename($self->get_filename()) .  ".tmp-extract.XXXXX";
         my $template = basename($self->get_filename()) .  ".tmp-extract.XXXXX";
@@ -112,18 +112,18 @@ sub extract {
             mkdir($dest) || syserr(_g("cannot create directory %s"), $dest);
             mkdir($dest) || syserr(_g("cannot create directory %s"), $dest);
         }
         }
         $tmp = tempdir($template, DIR => Cwd::realpath("$dest/.."), CLEANUP => 1);
         $tmp = tempdir($template, DIR => Cwd::realpath("$dest/.."), CLEANUP => 1);
-        $fork_opts{"chdir"} = $tmp;
+        $spawn_opts{"chdir"} = $tmp;
     }
     }
 
 
     # Prepare stuff that handles the input of tar
     # Prepare stuff that handles the input of tar
     $self->ensure_open("r");
     $self->ensure_open("r");
-    $fork_opts{"from_handle"} = $self->get_filehandle();
+    $spawn_opts{"from_handle"} = $self->get_filehandle();
 
 
     # Call tar extraction process
     # Call tar extraction process
-    $fork_opts{"delete_env"} = [ "TAR_OPTIONS" ];
-    $fork_opts{'exec'} = [ 'tar', '--no-same-owner', '--no-same-permissions',
-                           @{$opts{"options"}}, '-xkf', '-' ];
-    fork_and_exec(%fork_opts);
+    $spawn_opts{"delete_env"} = [ "TAR_OPTIONS" ];
+    $spawn_opts{'exec'} = [ 'tar', '--no-same-owner', '--no-same-permissions',
+                            @{$opts{"options"}}, '-xkf', '-' ];
+    spawn(%spawn_opts);
     $self->close();
     $self->close();
 
 
     # Fix permissions on extracted files because tar insists on applying
     # Fix permissions on extracted files because tar insists on applying

+ 1 - 1
scripts/Dpkg/Source/Functions.pm

@@ -67,7 +67,7 @@ sub is_binary($) {
 
 
     # Use diff to check if it's a binary file
     # Use diff to check if it's a binary file
     my $diffgen;
     my $diffgen;
-    my $diff_pid = fork_and_exec(
+    my $diff_pid = spawn(
         'exec' => [ 'diff', '-u', '--', '/dev/null', $file ],
         'exec' => [ 'diff', '-u', '--', '/dev/null', $file ],
         'env' => { LC_ALL => 'C', LANG => 'C', TZ => 'UTC0' },
         'env' => { LC_ALL => 'C', LANG => 'C', TZ => 'UTC0' },
         'to_pipe' => \$diffgen
         'to_pipe' => \$diffgen

+ 3 - 3
scripts/Dpkg/Source/Package.pm

@@ -282,9 +282,9 @@ sub check_signature {
         push @exec, $dsc;
         push @exec, $dsc;
 
 
         my ($stdout, $stderr);
         my ($stdout, $stderr);
-        fork_and_exec('exec' => \@exec, wait_child => 1, nocheck => 1,
-                      to_string => \$stdout, error_to_string => \$stderr,
-                      timeout => 10);
+        spawn('exec' => \@exec, wait_child => 1, nocheck => 1,
+              to_string => \$stdout, error_to_string => \$stderr,
+              timeout => 10);
         if (WIFEXITED($?)) {
         if (WIFEXITED($?)) {
             my $gpg_status = WEXITSTATUS($?);
             my $gpg_status = WEXITSTATUS($?);
             print STDERR "$stdout$stderr" if $gpg_status;
             print STDERR "$stdout$stderr" if $gpg_status;

+ 3 - 3
scripts/Dpkg/Source/Patch.pm

@@ -96,7 +96,7 @@ sub add_diff_file {
     }
     }
     # Generate diff
     # Generate diff
     my $diffgen;
     my $diffgen;
-    my $diff_pid = fork_and_exec(
+    my $diff_pid = spawn(
         'exec' => [ 'diff', '-u', @options, '--', $old, $new ],
         'exec' => [ 'diff', '-u', @options, '--', $old, $new ],
         'env' => { LC_ALL => 'C', LANG => 'C', TZ => 'UTC0' },
         'env' => { LC_ALL => 'C', LANG => 'C', TZ => 'UTC0' },
         'to_pipe' => \$diffgen
         'to_pipe' => \$diffgen
@@ -437,7 +437,7 @@ sub apply {
     $self->prepare_apply($analysis, %opts);
     $self->prepare_apply($analysis, %opts);
     # Apply the patch
     # Apply the patch
     $self->ensure_open("r");
     $self->ensure_open("r");
-    fork_and_exec(
+    spawn(
 	'exec' => [ 'patch', @{$opts{"options"}} ],
 	'exec' => [ 'patch', @{$opts{"options"}} ],
 	'chdir' => $destdir,
 	'chdir' => $destdir,
 	'env' => { LC_ALL => 'C', LANG => 'C' },
 	'env' => { LC_ALL => 'C', LANG => 'C' },
@@ -477,7 +477,7 @@ sub check_apply {
     # Apply the patch
     # Apply the patch
     $self->ensure_open("r");
     $self->ensure_open("r");
     my $error;
     my $error;
-    my $patch_pid = fork_and_exec(
+    my $patch_pid = spawn(
 	'exec' => [ 'patch', @{$opts{"options"}} ],
 	'exec' => [ 'patch', @{$opts{"options"}} ],
 	'chdir' => $destdir,
 	'chdir' => $destdir,
 	'env' => { LC_ALL => 'C', LANG => 'C' },
 	'env' => { LC_ALL => 'C', LANG => 'C' },

+ 2 - 2
scripts/dpkg-scanpackages.pl

@@ -186,8 +186,8 @@ FILE:
 	chomp;
 	chomp;
 	my $fn = $_;
 	my $fn = $_;
 	my $output;
 	my $output;
-	my $pid = fork_and_exec('exec' => [ "dpkg-deb", "-I", $fn, "control" ],
-				'to_pipe' => \$output);
+	my $pid = spawn('exec' => [ "dpkg-deb", "-I", $fn, "control" ],
+			'to_pipe' => \$output);
 	my $fields = Dpkg::Control->new(type => CTRL_INDEX_PKG);
 	my $fields = Dpkg::Control->new(type => CTRL_INDEX_PKG);
 	$fields->parse_fh($output, $fn)
 	$fields->parse_fh($output, $fn)
 	    or error(_g("couldn't parse control information from %s."), $fn);
 	    or error(_g("couldn't parse control information from %s."), $fn);

+ 14 - 14
scripts/t/800_Dpkg_IPC.t

@@ -33,17 +33,17 @@ open TMP, '>', $tmp_name;
 print TMP $string;
 print TMP $string;
 close TMP;
 close TMP;
 
 
-my $pid = fork_and_exec(exec => "cat",
-			from_string => \$string,
-			to_string => \$string2);
+my $pid = spawn(exec => "cat",
+		from_string => \$string,
+		to_string => \$string2);
 
 
 ok($pid);
 ok($pid);
 
 
 is($string2, $string, "{from,to}_string");
 is($string2, $string, "{from,to}_string");
 
 
-$pid = fork_and_exec(exec => "cat",
-		     from_handle => $tmp_fh,
-		     to_handle => $tmp2_fh);
+$pid = spawn(exec => "cat",
+	     from_handle => $tmp_fh,
+	     to_handle => $tmp2_fh);
 
 
 ok($pid);
 ok($pid);
 
 
@@ -55,11 +55,11 @@ close TMP;
 
 
 is($string2, $string, "{from,to}_handle");
 is($string2, $string, "{from,to}_handle");
 
 
-$pid = fork_and_exec(exec => "cat",
-		     from_file => $tmp_name,
-		     to_file => $tmp2_name,
-		     wait_child => 1,
-		     timeout => 5);
+$pid = spawn(exec => "cat",
+	     from_file => $tmp_name,
+	     to_file => $tmp2_name,
+	     wait_child => 1,
+	     timeout => 5);
 
 
 ok($pid);
 ok($pid);
 
 
@@ -70,9 +70,9 @@ close TMP;
 is($string2, $string, "{from,to}_file");
 is($string2, $string, "{from,to}_file");
 
 
 eval {
 eval {
-    $pid = fork_and_exec(exec => ["sleep", "10"],
-		         wait_child => 1,
-		         timeout => 5);
+    $pid = spawn(exec => ["sleep", "10"],
+	         wait_child => 1,
+	         timeout => 5);
 };
 };
 ok($@, "fails on timeout");
 ok($@, "fails on timeout");
 
 

+ 2 - 2
scripts/t/900_update_alternatives.t

@@ -76,8 +76,8 @@ sub cleanup {
 
 
 sub call_ua {
 sub call_ua {
     my ($params, %opts) = @_;
     my ($params, %opts) = @_;
-    fork_and_exec("exec" => [ @ua, @$params ], nocheck => 1,
-		  wait_child => 1, env => { LC_ALL => "C" }, %opts);
+    spawn("exec" => [ @ua, @$params ], nocheck => 1,
+	  wait_child => 1, env => { LC_ALL => "C" }, %opts);
     if ($opts{"expect_failure"}) {
     if ($opts{"expect_failure"}) {
 	ok($? != 0, "update-alternatives @$params did not fail.");
 	ok($? != 0, "update-alternatives @$params did not fail.");
     } else {
     } else {