Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Always redirect STDOUT to logfile #19

Open
wants to merge 10 commits into
base: integration
Choose a base branch
from
11 changes: 8 additions & 3 deletions bin/pgaudit_analyze
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use lib dirname($0) . '/../lib';
use PgAudit::CSV;
use PgAudit::Wait;

# Flush the output buffer. $| is named $OUTPUT_AUTOFLUSH in English.pm.
$|++;

####################################################################################################################################
# Usage
####################################################################################################################################
Expand Down Expand Up @@ -597,11 +600,9 @@ sub daemonInit
chdir '/'
or confess "chdir() failed: $!";

# Close stdin/stdout/stderr
# Close stdin and stderr. 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: $!";
open STDERR, '<', '/dev/null'
or confess "Couldn't close standard error: $!";

Expand Down Expand Up @@ -646,6 +647,10 @@ my $strNextLogFile = nextLogFile($strLogPath);
open(my $hLog, '>>', $strLogOutFile)
or confess "unable to open pgAudit Analyze log file $strLogOutFile: $!";

# Redirect stdout to log file
open(STDOUT, '>&', $hLog)
or confess "unable to close standard output and redirect to log file: $!";

# Daemonize the process
daemonInit()
if ($bDaemon);
Expand Down