chiark / gitweb /
Dgit: forkcheck_*: break out from setup_sigwarn
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 11 Jan 2017 23:15:11 +0000 (23:15 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 12 Jan 2017 00:31:17 +0000 (00:31 +0000)
Other places are going to want this too, notably END blocks.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Debian/Dgit.pm

index be8cbeea2a8667a69e6f0c54a4b9bacc2ffad94a..5e0bbd5e63ce0b8f8ddac59b63bbd34476cb9d03 100644 (file)
@@ -36,7 +36,7 @@ BEGIN {
 
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
 
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
-    @EXPORT      = qw(setup_sigwarn
+    @EXPORT      = qw(setup_sigwarn forkcheck_setup forkcheck_mainprocess
                      dep14_version_mangle
                       debiantags debiantag_old debiantag_new
                      server_branch server_ref
                      dep14_version_mangle
                       debiantags debiantag_old debiantag_new
                      server_branch server_ref
@@ -81,10 +81,21 @@ sub NOCOMMITCHECK () { return 0x8; }
 our $debugprefix;
 our $debuglevel = 0;
 
 our $debugprefix;
 our $debuglevel = 0;
 
+our $forkcheck_mainprocess;
+
+sub forkcheck_setup () {
+    $forkcheck_mainprocess = $$;
+}
+
+sub forkcheck_mainprocess () {
+    # You must have called forkcheck_setup or setup_sigwarn already
+    getppid != $forkcheck_mainprocess;
+}
+
 sub setup_sigwarn () {
 sub setup_sigwarn () {
-    our $sigwarn_mainprocess = $$;
+    forkcheck_setup();
     $SIG{__WARN__} = sub { 
     $SIG{__WARN__} = sub { 
-       die $_[0] unless getppid == $sigwarn_mainprocess;
+       die $_[0] if forkcheck_mainprocess;
     };
 }
 
     };
 }