diff --git a/lib/Daemon.pm b/lib/Daemon.pm index 9d55a858..0b8b0a32 100644 --- a/lib/Daemon.pm +++ b/lib/Daemon.pm @@ -55,11 +55,12 @@ 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; } # I'm daemonized now. + PTDEBUG && _d('Daemonizing child PID', $PID); $self->{PID_owner} = $PID; $self->{child} = 1; @@ -73,12 +74,14 @@ sub daemonize { # Only reopen STDIN to /dev/null if it's a tty. It may be a pipe, # in which case we don't want to break it. if ( -t STDIN ) { + PTDEBUG && _d('STDIN is a terminal; redirecting from /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"; @@ -93,18 +96,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; } diff --git a/lib/PerconaTest.pm b/lib/PerconaTest.pm index 4943d7ba..2d02e90a 100644 --- a/lib/PerconaTest.pm +++ b/lib/PerconaTest.pm @@ -270,8 +270,6 @@ sub wait_for_table { } return 1; }, - 0.25, - 15, ); } @@ -280,12 +278,13 @@ sub wait_for_files { return wait_until( sub { foreach my $file (@files) { - return 0 if ! -f $file; + if ( ! -f $file ) { + PTDEVDEBUG && _d('Waiting for file', $file); + return 0; + } } return 1; }, - 0.25, - 15, ); } diff --git a/t/lib/Daemon.t b/t/lib/Daemon.t index 21faee35..6a35b117 100644 --- a/t/lib/Daemon.t +++ b/t/lib/Daemon.t @@ -113,7 +113,7 @@ SKIP: { : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0" : die "Cannot find fd 0 symlink in /proc/$pid"; PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file, - 'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`); + 'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`, `lsof -p $pid`); my $stdin = readlink $proc_fd_0; is( $stdin, @@ -129,7 +129,7 @@ SKIP: { : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0" : die "Cannot find fd 0 symlink in /proc/$pid"; PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file, - 'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`); + 'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`, `lsof -p $pid`); $stdin = readlink $proc_fd_0; like( $stdin,