# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
-# 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
# you should have received as part of this distribution. The terms
my $pidfile = ".ftpd.pid"; # a default, use --pidfile
my $SERVERLOGS_LOCK="log/serverlogs.lock"; # server logs advisor read lock
+my $serverlogslocked=0;
do {
if($ARGV[0] eq "-v") {
my $signame = shift;
print STDERR "ftpserver.pl received SIG$signame, exiting\n";
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";
}
$SIG{INT} = \&catch_zap;
logmsg "Error: ftp$ftpdnum$ext sysread error: $!\n";
kill(9, $sfpid);
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 " .
"line $lcaller. ftp$ftpdnum$ext sysread error: $!\n";
}
logmsg "Error: ftp$ftpdnum$ext read zero\n";
kill(9, $sfpid);
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 " .
"line $lcaller. ftp$ftpdnum$ext read zero\n";
}
logmsg "Failed sockfilt command: $cmd\n";
kill(9, $sfpid);
waitpid($sfpid, 0);
- clear_advisor_read_lock($SERVERLOGS_LOCK);
+ if($serverlogslocked) {
+ $serverlogslocked = 0;
+ clear_advisor_read_lock($SERVERLOGS_LOCK);
+ }
die "Failed to start sockfilt!";
}
}
logmsg "====> Client connect\n";
set_advisor_read_lock($SERVERLOGS_LOCK);
+ $serverlogslocked = 1;
# flush data:
$| = 1;
} # while(1)
logmsg "====> Client disconnected\n";
- clear_advisor_read_lock($SERVERLOGS_LOCK);
+ if($serverlogslocked) {
+ $serverlogslocked = 0;
+ clear_advisor_read_lock($SERVERLOGS_LOCK);
+ }
}
print SFWRITE "QUIT\n";
waitpid $sfpid, 0;
-clear_advisor_read_lock($SERVERLOGS_LOCK);
+if($serverlogslocked) {
+ $serverlogslocked = 0;
+ clear_advisor_read_lock($SERVERLOGS_LOCK);
+}
exit;
static bool use_ipv6 = FALSE;
#endif
static const char *ipv_inuse = "IPv4";
+static int serverlogslocked = 0;
#define REQBUFSIZ 150000
#define REQBUFSIZ_TXT "149999"
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);
if(!wrotepidfile)
goto sws_cleanup;
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);
+ serverlogslocked = 1;
#ifdef CURL_SWS_FORK_ENABLED
if(use_fork) {
sclose(msgsock);
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)
break;
if(wrotepidfile)
unlink(pidname);
- clear_advisor_read_lock(SERVERLOGS_LOCK);
+ if(serverlogslocked) {
+ serverlogslocked = 0;
+ clear_advisor_read_lock(SERVERLOGS_LOCK);
+ }
restore_signal_handlers();
static bool use_ipv6 = FALSE;
#endif
static const char *ipv_inuse = "IPv4";
+static int serverlogslocked = 0;
struct testcase {
char *buffer; /* holds the file data to send to the client */
}
set_advisor_read_lock(SERVERLOGS_LOCK);
+ serverlogslocked = 1;
from.sin_family = AF_INET;
}
sclose(peer);
- clear_advisor_read_lock(SERVERLOGS_LOCK);
+ if(serverlogslocked) {
+ serverlogslocked = 0;
+ clear_advisor_read_lock(SERVERLOGS_LOCK);
+ }
logmsg("end of one transfer");
}
- clear_advisor_read_lock(SERVERLOGS_LOCK);
+ if(serverlogslocked) {
+ serverlogslocked = 0;
+ clear_advisor_read_lock(SERVERLOGS_LOCK);
+ }
return result;
}
timeout += rexmtval;
if(timeout >= maxtimeout) {
- clear_advisor_read_lock(SERVERLOGS_LOCK);
+ if(serverlogslocked) {
+ serverlogslocked = 0;
+ clear_advisor_read_lock(SERVERLOGS_LOCK);
+ }
exit(1);
}
#ifdef HAVE_SIGSETJMP
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * 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
* you should have received as part of this distribution. The terms
int error = 0;
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 {
res = unlink(filename);
} while(res && ((error = ERRNO) == EINTR));