瀏覽代碼

Dpkg::IPC: Add support for sig and delete_sig spawn() options

Guillem Jover 12 年之前
父節點
當前提交
747ec69e69
共有 2 個文件被更改,包括 36 次插入1 次删除
  1. 1 0
      debian/changelog
  2. 35 1
      scripts/Dpkg/IPC.pm

+ 1 - 0
debian/changelog

@@ -74,6 +74,7 @@ dpkg (1.17.11) UNRELEASED; urgency=low
   * Remove unused pkglibdir variable from libdpkg.pc.in.
   * Perl modules:
     - Add new set_as_auto() method to Dpkg::Substvars.
+    - Add support for sig and delete_sig spawn() options in Dpkg::IPC.
   * Mark Format and Installed-Size as automatic substvars in dpkg-genchanges
     and dpkg-gencontrol respectively.
   * Warn on usage of deprecated Source-Version substvar.

+ 35 - 1
scripts/Dpkg/IPC.pm

@@ -1,5 +1,6 @@
 # Copyright © 2008-2009 Raphaël Hertzog <hertzog@debian.org>
 # Copyright © 2008 Frank Lichtenheld <djpig@debian.org>
+# Copyright © 2008-2010,2012-2014 Guillem Jover <guillem@debian.org>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,7 +20,7 @@ package Dpkg::IPC;
 use strict;
 use warnings;
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 use Dpkg::ErrorHandling;
 use Dpkg::Gettext;
@@ -127,6 +128,16 @@ hash before calling exec. This allows exporting environment variables.
 Array reference. The child process will remove all environment variables
 listed in the array before calling exec.
 
+=item sig
+
+Hash reference. The child process will populate %SIG with the items of the
+hash before calling exec. This allows setting signal dispositions.
+
+=item delete_sig
+
+Array reference. The child process will reset all signals listed in the
+array to their default dispositions before calling exec.
+
 =back
 
 =cut
@@ -179,6 +190,14 @@ sub _sanity_check_opts {
 	croak 'parameter delete_env must be an array reference';
     }
 
+    if (exists $opts{sig} and ref($opts{sig}) ne 'HASH') {
+	croak 'parameter sig must be a hash reference';
+    }
+
+    if (exists $opts{delete_sig} and ref($opts{delete_sig}) ne 'ARRAY') {
+	croak 'parameter delete_sig must be an array reference';
+    }
+
     return %opts;
 }
 
@@ -238,6 +257,15 @@ sub spawn {
 	if ($opts{delete_env}) {
 	    delete $ENV{$_} foreach (@{$opts{delete_env}});
 	}
+	# Define signal dispositions.
+	if ($opts{sig}) {
+	    foreach (keys %{$opts{sig}}) {
+		$SIG{$_} = $opts{sig}{$_};
+	    }
+	}
+	if ($opts{delete_sig}) {
+	    delete $SIG{$_} foreach (@{$opts{delete_sig}});
+	}
 	# Change the current directory
 	if ($opts{chdir}) {
 	    chdir($opts{chdir}) or syserr(_g('chdir to %s'), $opts{chdir});
@@ -365,6 +393,12 @@ __END__
 
 =back
 
+=head1 CHANGES
+
+=head2 Version 1.01
+
+New options: spawn() now accepts 'sig' and 'delete_sig'.
+
 =head1 AUTHORS
 
 Written by Raphaël Hertzog <hertzog@debian.org> and