mirror of
https://github.com/curl/curl.git
synced 2024-11-27 05:50:21 +08:00
signal handling to cleanup on SIGINT and SIGTERM
This commit is contained in:
parent
fb2425b147
commit
636d2fe00a
@ -122,16 +122,16 @@ do {
|
|||||||
|
|
||||||
sub catch_zap {
|
sub catch_zap {
|
||||||
my $signame = shift;
|
my $signame = shift;
|
||||||
print STDERR "ftpserver.pl received SIG$signame, exiting\n";
|
|
||||||
ftpkillslaves(1);
|
ftpkillslaves(1);
|
||||||
|
unlink($pidfile);
|
||||||
if($serverlogslocked) {
|
if($serverlogslocked) {
|
||||||
$serverlogslocked = 0;
|
$serverlogslocked = 0;
|
||||||
clear_advisor_read_lock($SERVERLOGS_LOCK);
|
clear_advisor_read_lock($SERVERLOGS_LOCK);
|
||||||
}
|
}
|
||||||
die "Somebody sent me a SIG$signame";
|
exit;
|
||||||
}
|
}
|
||||||
$SIG{INT} = \&catch_zap;
|
$SIG{INT} = \&catch_zap;
|
||||||
$SIG{KILL} = \&catch_zap;
|
$SIG{TERM} = \&catch_zap;
|
||||||
|
|
||||||
my $sfpid;
|
my $sfpid;
|
||||||
|
|
||||||
@ -153,6 +153,7 @@ sub sysread_or_die {
|
|||||||
logmsg "Error: ftp$ftpdnum$ext sysread error: $!\n";
|
logmsg "Error: ftp$ftpdnum$ext sysread error: $!\n";
|
||||||
kill(9, $sfpid);
|
kill(9, $sfpid);
|
||||||
waitpid($sfpid, 0);
|
waitpid($sfpid, 0);
|
||||||
|
unlink($pidfile);
|
||||||
if($serverlogslocked) {
|
if($serverlogslocked) {
|
||||||
$serverlogslocked = 0;
|
$serverlogslocked = 0;
|
||||||
clear_advisor_read_lock($SERVERLOGS_LOCK);
|
clear_advisor_read_lock($SERVERLOGS_LOCK);
|
||||||
@ -166,6 +167,7 @@ sub sysread_or_die {
|
|||||||
logmsg "Error: ftp$ftpdnum$ext read zero\n";
|
logmsg "Error: ftp$ftpdnum$ext read zero\n";
|
||||||
kill(9, $sfpid);
|
kill(9, $sfpid);
|
||||||
waitpid($sfpid, 0);
|
waitpid($sfpid, 0);
|
||||||
|
unlink($pidfile);
|
||||||
if($serverlogslocked) {
|
if($serverlogslocked) {
|
||||||
$serverlogslocked = 0;
|
$serverlogslocked = 0;
|
||||||
clear_advisor_read_lock($SERVERLOGS_LOCK);
|
clear_advisor_read_lock($SERVERLOGS_LOCK);
|
||||||
@ -191,6 +193,7 @@ sub startsf {
|
|||||||
logmsg "Failed sockfilt command: $cmd\n";
|
logmsg "Failed sockfilt command: $cmd\n";
|
||||||
kill(9, $sfpid);
|
kill(9, $sfpid);
|
||||||
waitpid($sfpid, 0);
|
waitpid($sfpid, 0);
|
||||||
|
unlink($pidfile);
|
||||||
if($serverlogslocked) {
|
if($serverlogslocked) {
|
||||||
$serverlogslocked = 0;
|
$serverlogslocked = 0;
|
||||||
clear_advisor_read_lock($SERVERLOGS_LOCK);
|
clear_advisor_read_lock($SERVERLOGS_LOCK);
|
||||||
@ -199,9 +202,6 @@ sub startsf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove the file here so that if startsf() fails, it is very noticeable
|
|
||||||
unlink($pidfile);
|
|
||||||
|
|
||||||
startsf();
|
startsf();
|
||||||
|
|
||||||
logmsg sprintf("FTP server listens on port IPv%d/$port\n", $ipv6?6:4);
|
logmsg sprintf("FTP server listens on port IPv%d/$port\n", $ipv6?6:4);
|
||||||
@ -939,6 +939,8 @@ while(1) {
|
|||||||
print SFWRITE "QUIT\n";
|
print SFWRITE "QUIT\n";
|
||||||
waitpid $sfpid, 0;
|
waitpid $sfpid, 0;
|
||||||
|
|
||||||
|
unlink($pidfile);
|
||||||
|
|
||||||
if($serverlogslocked) {
|
if($serverlogslocked) {
|
||||||
$serverlogslocked = 0;
|
$serverlogslocked = 0;
|
||||||
clear_advisor_read_lock($SERVERLOGS_LOCK);
|
clear_advisor_read_lock($SERVERLOGS_LOCK);
|
||||||
|
Loading…
Reference in New Issue
Block a user