with-authinfo-kludge: Add machinery to restore signals in child processes.
[with-authinfo-kludge] / with-authinfo-kludge
index 3cdefe3..4317d8d 100755 (executable)
@@ -173,10 +173,20 @@ sub write_to_file ($$) {
   rename $new, $file or sysfail "failed to rename `$new' to `$file': $!";
 }
 
+my %OLDSIGS;
+sub set_sighandler ($$) {
+  my ($sig, $handler) = @_;
+  unless (exists $OLDSIGS{$sig}) { $OLDSIGS{$sig} = $SIG{$sig}; }
+  $SIG{$sig} = $handler;
+}
+
 my $INKIDP = 0;
 sub myfork () {
   my $kid = fork;
-  if (defined $kid && !$kid) { $INKIDP = 1; }
+  if (defined $kid && !$kid) {
+    $INKIDP = 1;
+    for my $sig (keys %OLDSIGS) { $SIG{$sig} = $OLDSIGS{$sig}; }
+  }
   return $kid;
 }
 
@@ -747,7 +757,7 @@ sub wait_for_ssh () {
   else { inform "  all tunnels started ok"; }
 }
 
-$SIG{"CHLD"} = sub {
+set_sighandler "CHLD", sub {
   KID: for (;;) {
     defined (my $kid = waitpid -1, WNOHANG)
       or sysfail "failed to reap child: $!";