More Daemon debugging.

This commit is contained in:
Daniel Nichter
2012-02-14 10:20:40 -07:00
parent e9f6325592
commit c67adc1a8f
3 changed files with 14 additions and 9 deletions

View File

@@ -55,11 +55,12 @@ sub daemonize {
PTDEBUG && _d('About to fork and daemonize'); PTDEBUG && _d('About to fork and daemonize');
defined (my $pid = fork()) or die "Cannot fork: $OS_ERROR"; defined (my $pid = fork()) or die "Cannot fork: $OS_ERROR";
if ( $pid ) { if ( $pid ) {
PTDEBUG && _d('I am the parent and now I die'); PTDEBUG && _d('Parent PID', $PID, 'exiting after forking child PID',$pid);
exit; exit;
} }
# I'm daemonized now. # I'm daemonized now.
PTDEBUG && _d('Daemonizing child PID', $PID);
$self->{PID_owner} = $PID; $self->{PID_owner} = $PID;
$self->{child} = 1; $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, # 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. # in which case we don't want to break it.
if ( -t STDIN ) { if ( -t STDIN ) {
PTDEBUG && _d('STDIN is a terminal; redirecting from /dev/null');
close STDIN; close STDIN;
open STDIN, '/dev/null' open STDIN, '/dev/null'
or die "Cannot reopen STDIN to /dev/null: $OS_ERROR"; or die "Cannot reopen STDIN to /dev/null: $OS_ERROR";
} }
if ( $self->{log_file} ) { if ( $self->{log_file} ) {
PTDEBUG && _d('Redirecting STDOUT and STDERR to', $self->{log_file});
close STDOUT; close STDOUT;
open STDOUT, '>>', $self->{log_file} open STDOUT, '>>', $self->{log_file}
or die "Cannot open log file $self->{log_file}: $OS_ERROR"; or die "Cannot open log file $self->{log_file}: $OS_ERROR";
@@ -93,18 +96,21 @@ sub daemonize {
} }
else { else {
if ( -t STDOUT ) { if ( -t STDOUT ) {
PTDEBUG && _d('No log file and STDOUT is a terminal;',
'redirecting to /dev/null');
close STDOUT; close STDOUT;
open STDOUT, '>', '/dev/null' open STDOUT, '>', '/dev/null'
or die "Cannot reopen STDOUT to /dev/null: $OS_ERROR"; or die "Cannot reopen STDOUT to /dev/null: $OS_ERROR";
} }
if ( -t STDERR ) { if ( -t STDERR ) {
PTDEBUG && _d('No log file and STDERR is a terminal;',
'redirecting to /dev/null');
close STDERR; close STDERR;
open STDERR, '>', '/dev/null' open STDERR, '>', '/dev/null'
or die "Cannot reopen STDERR to /dev/null: $OS_ERROR"; or die "Cannot reopen STDERR to /dev/null: $OS_ERROR";
} }
} }
PTDEBUG && _d('I am the child and now I live daemonized');
return; return;
} }

View File

@@ -270,8 +270,6 @@ sub wait_for_table {
} }
return 1; return 1;
}, },
0.25,
15,
); );
} }
@@ -280,12 +278,13 @@ sub wait_for_files {
return wait_until( return wait_until(
sub { sub {
foreach my $file (@files) { foreach my $file (@files) {
return 0 if ! -f $file; if ( ! -f $file ) {
PTDEVDEBUG && _d('Waiting for file', $file);
return 0;
}
} }
return 1; return 1;
}, },
0.25,
15,
); );
} }

View File

@@ -113,7 +113,7 @@ SKIP: {
: -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0" : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"
: die "Cannot find fd 0 symlink in /proc/$pid"; : die "Cannot find fd 0 symlink in /proc/$pid";
PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file, 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; my $stdin = readlink $proc_fd_0;
is( is(
$stdin, $stdin,
@@ -129,7 +129,7 @@ SKIP: {
: -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0" : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"
: die "Cannot find fd 0 symlink in /proc/$pid"; : die "Cannot find fd 0 symlink in /proc/$pid";
PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file, 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; $stdin = readlink $proc_fd_0;
like( like(
$stdin, $stdin,