| 1 |
package ProFTPD::Tests::Signals::ABRT; |
| 2 |
|
| 3 |
use lib qw(t/lib); |
| 4 |
use base qw(ProFTPD::TestSuite::Child); |
| 5 |
use strict; |
| 6 |
|
| 7 |
use File::Spec; |
| 8 |
use IO::Handle; |
| 9 |
|
| 10 |
use ProFTPD::TestSuite::FTP; |
| 11 |
use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite); |
| 12 |
|
| 13 |
$| = 1; |
| 14 |
|
| 15 |
my $order = 0; |
| 16 |
|
| 17 |
my $TESTS = { |
| 18 |
abrt_daemon_ok => { |
| 19 |
order => ++$order, |
| 20 |
test_class => [qw(bug)], |
| 21 |
}, |
| 22 |
}; |
| 23 |
|
| 24 |
sub new { |
| 25 |
return shift()->SUPER::new(@_); |
| 26 |
} |
| 27 |
|
| 28 |
sub list_tests { |
| 29 |
return testsuite_get_runnable_tests($TESTS); |
| 30 |
} |
| 31 |
|
| 32 |
sub server_abort { |
| 33 |
my $pid_file = shift; |
| 34 |
|
| 35 |
my $pid; |
| 36 |
if (open(my $fh, "< $pid_file")) { |
| 37 |
$pid = <$fh>; |
| 38 |
chomp($pid); |
| 39 |
close($fh); |
| 40 |
|
| 41 |
} else { |
| 42 |
croak("Can't read $pid_file: $!"); |
| 43 |
} |
| 44 |
|
| 45 |
unless (kill('ABRT', $pid)) { |
| 46 |
print STDERR "Error sending SIGABRT to PID $pid: $!\n"; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
sub abrt_daemon_ok { |
| 51 |
my $self = shift; |
| 52 |
my $tmpdir = $self->{tmpdir}; |
| 53 |
|
| 54 |
my $config_file = "$tmpdir/signals.conf"; |
| 55 |
my $pid_file = File::Spec->rel2abs("$tmpdir/signals.pid"); |
| 56 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/signals.scoreboard"); |
| 57 |
|
| 58 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 59 |
|
| 60 |
my $config = { |
| 61 |
PidFile => $pid_file, |
| 62 |
ScoreboardFile => $scoreboard_file, |
| 63 |
SystemLog => $log_file, |
| 64 |
|
| 65 |
TraceLog => $log_file, |
| 66 |
Trace => 'DEFAULT:10', |
| 67 |
|
| 68 |
IfModules => { |
| 69 |
'mod_delay.c' => { |
| 70 |
DelayEngine => 'off', |
| 71 |
}, |
| 72 |
}, |
| 73 |
}; |
| 74 |
|
| 75 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 76 |
|
| 77 |
my $ex; |
| 78 |
|
| 79 |
# Start server |
| 80 |
server_start($config_file); |
| 81 |
|
| 82 |
# Allow a short interval between startup and shutdown |
| 83 |
sleep(1); |
| 84 |
|
| 85 |
# Abort the server |
| 86 |
server_abort($pid_file); |
| 87 |
|
| 88 |
# Make sure that the pid file has been removed by the server as part of |
| 89 |
# its shutdown procedures. We need the delay since proftpd handles |
| 90 |
# signals synchronously; it make take a short while for proftpd to |
| 91 |
# process the SIGABRT and shut down all of the way. |
| 92 |
|
| 93 |
sleep(1); |
| 94 |
|
| 95 |
if (-e $pid_file) { |
| 96 |
die("Unclean shutdown: PidFile $pid_file still present"); |
| 97 |
} |
| 98 |
|
| 99 |
if (-e $scoreboard_file) { |
| 100 |
die("Unclean shutdown: ScoreboardFile $scoreboard_file still present"); |
| 101 |
} |
| 102 |
|
| 103 |
if ($ex) { |
| 104 |
die($ex); |
| 105 |
} |
| 106 |
|
| 107 |
unlink($log_file); |
| 108 |
} |
| 109 |
|
| 110 |
1; |