From b149b79ed05457f69ac9f407d394f8ec35e41601 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 20 Sep 2017 20:30:04 +0100 Subject: [PATCH] with-authinfo-kludge: Add machinery to restore signals in child processes. In particular, this fixes a minor bug which restores `SIGCHLD' to its default disposition in children of `with-authinfo-kludge', even if it was ignored initially (which it probably shouldn't have been). --- with-authinfo-kludge | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/with-authinfo-kludge b/with-authinfo-kludge index 3cdefe3..4317d8d 100755 --- a/with-authinfo-kludge +++ b/with-authinfo-kludge @@ -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: $!"; -- 2.11.0