From 91e8dfeff8ff5cc75711d594c643e1e9f47542ba Mon Sep 17 00:00:00 2001 From: Alex Malek Date: Fri, 9 Oct 2020 10:51:18 -0400 Subject: [PATCH 1/7] always redirect stdout to logfile --- bin/pgaudit_analyze | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/pgaudit_analyze b/bin/pgaudit_analyze index 6f0a8c3..1fe56c7 100755 --- a/bin/pgaudit_analyze +++ b/bin/pgaudit_analyze @@ -596,11 +596,9 @@ sub daemonInit chdir '/' or confess "chdir() failed: $!"; - # close stdin/stdout + # close stdin, stdout previously closed/redirected open STDIN, '<', '/dev/null' or confess "Couldn't close standard input: $!"; - open STDOUT, '>', $strLogOutFile - or confess "Couldn't close standard output: $!"; # create new process defined($pid = fork) @@ -634,6 +632,10 @@ my $strNextLogFile = nextLogFile($strLogPath); open(my $hLog, '>', $strLogOutFile) or confess "unable to open pgAudit Analyze log file $strLogOutFile: $!"; +# always redirect stdout to logfile +open (STDOUT, '>&', $hLog) + or confess "Couldn't close standard output and redirect to logfile: $!"; + # Daemonize the process daemonInit() if ($bDaemon); From e24faea495acab5a047a2fa394b6fee6bfe19300 Mon Sep 17 00:00:00 2001 From: Alex Malek Date: Wed, 5 May 2021 14:49:34 -0400 Subject: [PATCH 2/7] flush the output buffer --- bin/pgaudit_analyze | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/pgaudit_analyze b/bin/pgaudit_analyze index 1fe56c7..79c6238 100755 --- a/bin/pgaudit_analyze +++ b/bin/pgaudit_analyze @@ -19,7 +19,8 @@ use POSIX qw(setsid); use lib dirname($0) . '/../lib'; use PgAudit::CSV; use PgAudit::Wait; - +# flush the output buffer +$|++; #################################################################################################################################### # Usage #################################################################################################################################### From 55dc094b5cad3d0e1be45cd5afea239fa2ca4786 Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 11 May 2021 09:33:36 -0400 Subject: [PATCH 3/7] Caps. --- bin/pgaudit_analyze | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pgaudit_analyze b/bin/pgaudit_analyze index 79c6238..54c12df 100755 --- a/bin/pgaudit_analyze +++ b/bin/pgaudit_analyze @@ -633,7 +633,7 @@ my $strNextLogFile = nextLogFile($strLogPath); open(my $hLog, '>', $strLogOutFile) or confess "unable to open pgAudit Analyze log file $strLogOutFile: $!"; -# always redirect stdout to logfile +# Always redirect stdout to logfile open (STDOUT, '>&', $hLog) or confess "Couldn't close standard output and redirect to logfile: $!"; From 965f56e7c4ce23d52a6c8cec1528af7fb6b2f9c4 Mon Sep 17 00:00:00 2001 From: Alex Malek Date: Thu, 22 Jul 2021 09:58:39 -0400 Subject: [PATCH 4/7] improve comment to be clear what $| does and assist in finding documentation --- bin/pgaudit_analyze | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/pgaudit_analyze b/bin/pgaudit_analyze index 54c12df..a30ee9a 100755 --- a/bin/pgaudit_analyze +++ b/bin/pgaudit_analyze @@ -19,7 +19,8 @@ use POSIX qw(setsid); use lib dirname($0) . '/../lib'; use PgAudit::CSV; use PgAudit::Wait; -# flush the output buffer +# Flush the output buffer +# $| is named $OUTPUT_AUTOFLUSH in English.pm $|++; #################################################################################################################################### # Usage From 975952f09ac5425c445116e9d7e0aac0ef37d622 Mon Sep 17 00:00:00 2001 From: Heath Lord Date: Fri, 2 Jul 2021 09:54:58 -0400 Subject: [PATCH 5/7] Close STDERR when running as a daemon. When testing on the CentOS8 Stream OS and trying to run the pgaudit_analyze binary as a daemon over an SSH connection, the entire SSH connection would hang and never return. After a lot of investigation, we were able to determine that this was happening when using openssh 8.0p1-9.el8 and also 8.0p1-8.el8. However, when you downgrade openssh to 8.0p1-7.el8, launching the daemon works as it has in the past. After digging through the openssh commits we found this: On May 2, 2021, CentOS 8 Stream packagers introduced a change to its openssh libraries, which you can see here: https://git.centos.org/rpms/openssh/c/1c3003998fcc4d40fe9e4544bca70dbc03324e65?branch=c8s After a lot more digging and testing, the issue was related to the fact that STDERR was never closed so in the newer openssh versions it would not release the connection and would hang. After this change we are able to run the pgaudit_analyze daemon over an SSH connection like before. --- bin/pgaudit_analyze | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/pgaudit_analyze b/bin/pgaudit_analyze index 4a81843..aad5d15 100755 --- a/bin/pgaudit_analyze +++ b/bin/pgaudit_analyze @@ -599,10 +599,13 @@ sub daemonInit chdir '/' or confess "chdir() failed: $!"; - # close stdin, stdout previously closed/redirected + # close stdin and stderr, stdout previously closed/redirected open STDIN, '<', '/dev/null' or confess "Couldn't close standard input: $!"; + open STDERR, '<', '/dev/null' + or confess "Couldn't close standard error: $!"; + # create new process defined($pid = fork) or confess "fork() failed: $!"; From 3138768f77c9d404f7d671270abf8dd2c9432820 Mon Sep 17 00:00:00 2001 From: David Steele Date: Mon, 26 Jul 2021 08:26:17 -0400 Subject: [PATCH 6/7] Updates from review. --- bin/pgaudit_analyze | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/pgaudit_analyze b/bin/pgaudit_analyze index aad5d15..178a58a 100755 --- a/bin/pgaudit_analyze +++ b/bin/pgaudit_analyze @@ -19,9 +19,10 @@ use POSIX qw(setsid); use lib dirname($0) . '/../lib'; use PgAudit::CSV; use PgAudit::Wait; -# Flush the output buffer -# $| is named $OUTPUT_AUTOFLUSH in English.pm + +# Flush the output buffer. $| is named $OUTPUT_AUTOFLUSH in English.pm. $|++; + #################################################################################################################################### # Usage #################################################################################################################################### @@ -648,8 +649,8 @@ open(my $hLog, '>>', $strLogOutFile) or confess "unable to open pgAudit Analyze log file $strLogOutFile: $!"; # Always redirect stdout to logfile -open (STDOUT, '>&', $hLog) - or confess "Couldn't close standard output and redirect to logfile: $!"; +open(STDOUT, '>&', $hLog) + or confess "unable to close standard output and redirect to log file: $!"; # Daemonize the process daemonInit() From a52863f12c2d5af97a0771c79c1ccfd3a2af8c3e Mon Sep 17 00:00:00 2001 From: David Steele Date: Mon, 26 Jul 2021 08:28:41 -0400 Subject: [PATCH 7/7] Comment update. --- bin/pgaudit_analyze | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/pgaudit_analyze b/bin/pgaudit_analyze index 178a58a..a37e1d0 100755 --- a/bin/pgaudit_analyze +++ b/bin/pgaudit_analyze @@ -600,10 +600,9 @@ sub daemonInit chdir '/' or confess "chdir() failed: $!"; - # close stdin and stderr, stdout previously closed/redirected + # Close stdin and stderr. stdout previously closed/redirected. open STDIN, '<', '/dev/null' or confess "Couldn't close standard input: $!"; - open STDERR, '<', '/dev/null' or confess "Couldn't close standard error: $!"; @@ -648,7 +647,7 @@ my $strNextLogFile = nextLogFile($strLogPath); open(my $hLog, '>>', $strLogOutFile) or confess "unable to open pgAudit Analyze log file $strLogOutFile: $!"; -# Always redirect stdout to logfile +# Redirect stdout to log file open(STDOUT, '>&', $hLog) or confess "unable to close standard output and redirect to log file: $!";