Only attempt to clear the server-logs lock when previously set by this same server.

This commit is contained in:
Yang Tse 2009-11-26 10:15:08 +00:00
parent fba233bb34
commit cbd527843b
4 changed files with 69 additions and 13 deletions

View File

@ -6,7 +6,7 @@
# | (__| |_| | _ <| |___ # | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____| # \___|\___/|_| \_\_____|
# #
# Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al. # Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
# #
# This software is licensed as described in the file COPYING, which # This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms # you should have received as part of this distribution. The terms
@ -86,6 +86,7 @@ my $listenaddr = "127.0.0.1"; # just a default
my $pidfile = ".ftpd.pid"; # a default, use --pidfile my $pidfile = ".ftpd.pid"; # a default, use --pidfile
my $SERVERLOGS_LOCK="log/serverlogs.lock"; # server logs advisor read lock my $SERVERLOGS_LOCK="log/serverlogs.lock"; # server logs advisor read lock
my $serverlogslocked=0;
do { do {
if($ARGV[0] eq "-v") { if($ARGV[0] eq "-v") {
@ -123,7 +124,10 @@ sub catch_zap {
my $signame = shift; my $signame = shift;
print STDERR "ftpserver.pl received SIG$signame, exiting\n"; print STDERR "ftpserver.pl received SIG$signame, exiting\n";
ftpkillslaves(1); ftpkillslaves(1);
clear_advisor_read_lock($SERVERLOGS_LOCK); if($serverlogslocked) {
$serverlogslocked = 0;
clear_advisor_read_lock($SERVERLOGS_LOCK);
}
die "Somebody sent me a SIG$signame"; die "Somebody sent me a SIG$signame";
} }
$SIG{INT} = \&catch_zap; $SIG{INT} = \&catch_zap;
@ -149,7 +153,10 @@ 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);
clear_advisor_read_lock($SERVERLOGS_LOCK); if($serverlogslocked) {
$serverlogslocked = 0;
clear_advisor_read_lock($SERVERLOGS_LOCK);
}
die "Died in sysread_or_die() at $fcaller " . die "Died in sysread_or_die() at $fcaller " .
"line $lcaller. ftp$ftpdnum$ext sysread error: $!\n"; "line $lcaller. ftp$ftpdnum$ext sysread error: $!\n";
} }
@ -159,7 +166,10 @@ 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);
clear_advisor_read_lock($SERVERLOGS_LOCK); if($serverlogslocked) {
$serverlogslocked = 0;
clear_advisor_read_lock($SERVERLOGS_LOCK);
}
die "Died in sysread_or_die() at $fcaller " . die "Died in sysread_or_die() at $fcaller " .
"line $lcaller. ftp$ftpdnum$ext read zero\n"; "line $lcaller. ftp$ftpdnum$ext read zero\n";
} }
@ -181,7 +191,10 @@ 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);
clear_advisor_read_lock($SERVERLOGS_LOCK); if($serverlogslocked) {
$serverlogslocked = 0;
clear_advisor_read_lock($SERVERLOGS_LOCK);
}
die "Failed to start sockfilt!"; die "Failed to start sockfilt!";
} }
} }
@ -810,6 +823,7 @@ while(1) {
logmsg "====> Client connect\n"; logmsg "====> Client connect\n";
set_advisor_read_lock($SERVERLOGS_LOCK); set_advisor_read_lock($SERVERLOGS_LOCK);
$serverlogslocked = 1;
# flush data: # flush data:
$| = 1; $| = 1;
@ -916,12 +930,18 @@ while(1) {
} # while(1) } # while(1)
logmsg "====> Client disconnected\n"; logmsg "====> Client disconnected\n";
clear_advisor_read_lock($SERVERLOGS_LOCK); if($serverlogslocked) {
$serverlogslocked = 0;
clear_advisor_read_lock($SERVERLOGS_LOCK);
}
} }
print SFWRITE "QUIT\n"; print SFWRITE "QUIT\n";
waitpid $sfpid, 0; waitpid $sfpid, 0;
clear_advisor_read_lock($SERVERLOGS_LOCK); if($serverlogslocked) {
$serverlogslocked = 0;
clear_advisor_read_lock($SERVERLOGS_LOCK);
}
exit; exit;

View File

@ -74,6 +74,7 @@
static bool use_ipv6 = FALSE; static bool use_ipv6 = FALSE;
#endif #endif
static const char *ipv_inuse = "IPv4"; static const char *ipv_inuse = "IPv4";
static int serverlogslocked = 0;
#define REQBUFSIZ 150000 #define REQBUFSIZ 150000
#define REQBUFSIZ_TXT "149999" #define REQBUFSIZ_TXT "149999"
@ -1112,6 +1113,11 @@ int main(int argc, char *argv[])
goto sws_cleanup; goto sws_cleanup;
} }
/*
** As soon as this server writes its pid file the test harness will
** attempt to connect to this server and initiate its verification.
*/
wrotepidfile = write_pidfile(pidname); wrotepidfile = write_pidfile(pidname);
if(!wrotepidfile) if(!wrotepidfile)
goto sws_cleanup; goto sws_cleanup;
@ -1128,7 +1134,14 @@ int main(int argc, char *argv[])
break; break;
} }
/*
** As soon as this server acepts a connection from the test harness it
** must set the server logs advisor read lock to indicate that server
** logs should not be read until this lock is removed by this server.
*/
set_advisor_read_lock(SERVERLOGS_LOCK); set_advisor_read_lock(SERVERLOGS_LOCK);
serverlogslocked = 1;
#ifdef CURL_SWS_FORK_ENABLED #ifdef CURL_SWS_FORK_ENABLED
if(use_fork) { if(use_fork) {
@ -1215,7 +1228,10 @@ int main(int argc, char *argv[])
sclose(msgsock); sclose(msgsock);
msgsock = CURL_SOCKET_BAD; msgsock = CURL_SOCKET_BAD;
clear_advisor_read_lock(SERVERLOGS_LOCK); if(serverlogslocked) {
serverlogslocked = 0;
clear_advisor_read_lock(SERVERLOGS_LOCK);
}
if (req.testno == DOCNUMBER_QUIT) if (req.testno == DOCNUMBER_QUIT)
break; break;
@ -1238,7 +1254,10 @@ sws_cleanup:
if(wrotepidfile) if(wrotepidfile)
unlink(pidname); unlink(pidname);
clear_advisor_read_lock(SERVERLOGS_LOCK); if(serverlogslocked) {
serverlogslocked = 0;
clear_advisor_read_lock(SERVERLOGS_LOCK);
}
restore_signal_handlers(); restore_signal_handlers();

View File

@ -103,6 +103,7 @@
static bool use_ipv6 = FALSE; static bool use_ipv6 = FALSE;
#endif #endif
static const char *ipv_inuse = "IPv4"; static const char *ipv_inuse = "IPv4";
static int serverlogslocked = 0;
struct testcase { struct testcase {
char *buffer; /* holds the file data to send to the client */ char *buffer; /* holds the file data to send to the client */
@ -546,6 +547,7 @@ int main(int argc, char **argv)
} }
set_advisor_read_lock(SERVERLOGS_LOCK); set_advisor_read_lock(SERVERLOGS_LOCK);
serverlogslocked = 1;
from.sin_family = AF_INET; from.sin_family = AF_INET;
@ -574,13 +576,19 @@ int main(int argc, char **argv)
} }
sclose(peer); sclose(peer);
clear_advisor_read_lock(SERVERLOGS_LOCK); if(serverlogslocked) {
serverlogslocked = 0;
clear_advisor_read_lock(SERVERLOGS_LOCK);
}
logmsg("end of one transfer"); logmsg("end of one transfer");
} }
clear_advisor_read_lock(SERVERLOGS_LOCK); if(serverlogslocked) {
serverlogslocked = 0;
clear_advisor_read_lock(SERVERLOGS_LOCK);
}
return result; return result;
} }
@ -766,7 +774,10 @@ static void timer(int signum)
timeout += rexmtval; timeout += rexmtval;
if(timeout >= maxtimeout) { if(timeout >= maxtimeout) {
clear_advisor_read_lock(SERVERLOGS_LOCK); if(serverlogslocked) {
serverlogslocked = 0;
clear_advisor_read_lock(SERVERLOGS_LOCK);
}
exit(1); exit(1);
} }
#ifdef HAVE_SIGSETJMP #ifdef HAVE_SIGSETJMP

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -260,6 +260,12 @@ void clear_advisor_read_lock(const char *filename)
int error = 0; int error = 0;
int res; int res;
/*
** Log all removal failures. Even those due to file not existing.
** This allows to detect if unexpectedly the file has already been
** removed by a process different than the one that should do this.
*/
do { do {
res = unlink(filename); res = unlink(filename);
} while(res && ((error = ERRNO) == EINTR)); } while(res && ((error = ERRNO) == EINTR));