mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-09 07:30:02 +00:00
Update Daemon in all tools (bug 944420).
This commit is contained in:
18
bin/pt-trend
18
bin/pt-trend
@@ -1075,10 +1075,11 @@ sub daemonize {
|
||||
PTDEBUG && _d('About to fork and daemonize');
|
||||
defined (my $pid = fork()) or die "Cannot fork: $OS_ERROR";
|
||||
if ( $pid ) {
|
||||
PTDEBUG && _d('I am the parent and now I die');
|
||||
PTDEBUG && _d('Parent PID', $PID, 'exiting after forking child PID',$pid);
|
||||
exit;
|
||||
}
|
||||
|
||||
PTDEBUG && _d('Daemonizing child PID', $PID);
|
||||
$self->{PID_owner} = $PID;
|
||||
$self->{child} = 1;
|
||||
|
||||
@@ -1089,13 +1090,13 @@ sub daemonize {
|
||||
|
||||
$OUTPUT_AUTOFLUSH = 1;
|
||||
|
||||
if ( -t STDIN ) {
|
||||
close STDIN;
|
||||
open STDIN, '/dev/null'
|
||||
or die "Cannot reopen STDIN to /dev/null: $OS_ERROR";
|
||||
}
|
||||
PTDEBUG && _d('Redirecting STDIN to /dev/null');
|
||||
close STDIN;
|
||||
open STDIN, '/dev/null'
|
||||
or die "Cannot reopen STDIN to /dev/null: $OS_ERROR";
|
||||
|
||||
if ( $self->{log_file} ) {
|
||||
PTDEBUG && _d('Redirecting STDOUT and STDERR to', $self->{log_file});
|
||||
close STDOUT;
|
||||
open STDOUT, '>>', $self->{log_file}
|
||||
or die "Cannot open log file $self->{log_file}: $OS_ERROR";
|
||||
@@ -1106,18 +1107,21 @@ sub daemonize {
|
||||
}
|
||||
else {
|
||||
if ( -t STDOUT ) {
|
||||
PTDEBUG && _d('No log file and STDOUT is a terminal;',
|
||||
'redirecting to /dev/null');
|
||||
close STDOUT;
|
||||
open STDOUT, '>', '/dev/null'
|
||||
or die "Cannot reopen STDOUT to /dev/null: $OS_ERROR";
|
||||
}
|
||||
if ( -t STDERR ) {
|
||||
PTDEBUG && _d('No log file and STDERR is a terminal;',
|
||||
'redirecting to /dev/null');
|
||||
close STDERR;
|
||||
open STDERR, '>', '/dev/null'
|
||||
or die "Cannot reopen STDERR to /dev/null: $OS_ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
PTDEBUG && _d('I am the child and now I live daemonized');
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user