From 1725130a15a6577d925f308debb8e7b16ba3c6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Thu, 9 Dec 2021 17:03:10 +0000 Subject: [PATCH] fix: avoid double-close log messages on HUP --- bin/shell/connect.pl | 9 +++++---- lib/perl/OVH/Bastion/log.inc | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/shell/connect.pl b/bin/shell/connect.pl index 2ed6449..57c0828 100755 --- a/bin/shell/connect.pl +++ b/bin/shell/connect.pl @@ -29,15 +29,16 @@ sub exit_sig { ); } + # nullify my own handlers so that they don't get re-executed when my parent + # exits because of the signal, and I get sent back a SIGHUP (see Prctl below) + $SIG{$_} = 'IGNORE' for qw{ INT HUP TERM SEGV }; + # signal my current process group kill $sig, 0; exit(117); # EXIT_GOT_SIGNAL } -$SIG{'INT'} = \&exit_sig; -$SIG{'HUP'} = \&exit_sig; -$SIG{'TERM'} = \&exit_sig; -$SIG{'SEGV'} = \&exit_sig; +$SIG{$_} = \&exit_sig for qw{ INT HUP TERM SEGV }; # beautify for ps local $0 = '' . __FILE__ . ' ' . join(' ', @command); diff --git a/lib/perl/OVH/Bastion/log.inc b/lib/perl/OVH/Bastion/log.inc index 81e3339..7684733 100644 --- a/lib/perl/OVH/Bastion/log.inc +++ b/lib/perl/OVH/Bastion/log.inc @@ -646,6 +646,8 @@ sub _write_log { return; } +my $_log_access_update_done = 0; + sub log_access_update { my %params = @_; my $account = $params{'account'}; @@ -654,6 +656,10 @@ sub log_access_update { my $uniq_id = $params{'uniq_id'}; my $fnret; + # ensure we never get called more than once in a process + return R('OK_DUPLICATE') if $_log_access_update_done; + $_log_access_update_done = 1; + # if we get a valid account, we'll try to log to its files, if enabled. # if not, or if its invalid, still try to log what we can (hence don't return here) my ($remoteaccount, $sysaccount);