Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: move pidfiles and portfiles under the log directory #10874

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions tests/ftp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ sub killpid {
# killsockfilters kills sockfilter processes for a given server.
#
sub killsockfilters {
my ($proto, $ipvnum, $idnum, $verbose, $which) = @_;
my ($piddir, $proto, $ipvnum, $idnum, $verbose, $which) = @_;
my $server;
my $pidfile;
my $pid;
Expand All @@ -335,7 +335,7 @@ sub killsockfilters {
$server = servername_id($proto, $ipvnum, $idnum) if($verbose);

if(!$which || ($which eq 'main')) {
$pidfile = mainsockf_pidfilename($proto, $ipvnum, $idnum);
$pidfile = mainsockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$pid = processexists($pidfile);
if($pid > 0) {
printf("* kill pid for %s-%s => %d\n", $server,
Expand All @@ -349,7 +349,7 @@ sub killsockfilters {
return if($proto ne 'ftp');

if(!$which || ($which eq 'data')) {
$pidfile = datasockf_pidfilename($proto, $ipvnum, $idnum);
$pidfile = datasockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$pid = processexists($pidfile);
if($pid > 0) {
printf("* kill pid for %s-data => %d\n", $server,
Expand All @@ -365,12 +365,12 @@ sub killsockfilters {
# killallsockfilters kills sockfilter processes for all servers.
#
sub killallsockfilters {
my $verbose = $_[0];
my ($piddir, $verbose) = @_;

for my $proto (('ftp', 'imap', 'pop3', 'smtp')) {
for my $ipvnum (('4', '6')) {
for my $idnum (('1', '2')) {
killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
}
}
}
Expand Down
55 changes: 33 additions & 22 deletions tests/ftpserver.pl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
# All socket/network/TCP related stuff is done by the 'sockfilt' program.
#

use strict;
use warnings;

BEGIN {
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
push(@INC, ".");
Expand All @@ -51,10 +54,9 @@ BEGIN
}
}

use strict;
use warnings;
use IPC::Open2;
use Digest::MD5;
use File::Basename;

require "getpart.pm";
require "ftp.pm";
Expand Down Expand Up @@ -88,6 +90,7 @@ BEGIN
my $testno = 0; # test case number (read from ftpserver.cmd)
my $path = '.';
my $logdir = $path .'/log';
my $piddir;

#**********************************************************************
# global vars used for server address and primary listener port
Expand All @@ -98,8 +101,9 @@ BEGIN
#**********************************************************************
# global vars used for file names
#
my $PORTFILE="ftpserver.port"; # server port file name
my $portfile; # server port file path
my $pidfile; # server pid file name
my $portfile=".ftpserver.port"; # server port file name
my $logfile; # server log file name
my $mainsockf_pidfile; # pid file for primary connection sockfilt process
my $mainsockf_logfile; # log file for primary connection sockfilt process
Expand Down Expand Up @@ -197,7 +201,7 @@ BEGIN
sub exit_signal_handler {
my $signame = shift;
# For now, simply mimic old behavior.
killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
Expand Down Expand Up @@ -397,7 +401,7 @@ sub sysread_or_die {
logmsg "Error: $srvrname server, sysread error: $!\n";
logmsg "Exited from sysread_or_die() at $fcaller " .
"line $lcaller. $srvrname server, sysread error: $!\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
Expand All @@ -412,7 +416,7 @@ sub sysread_or_die {
logmsg "Error: $srvrname server, read zero\n";
logmsg "Exited from sysread_or_die() at $fcaller " .
"line $lcaller. $srvrname server, read zero\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
Expand Down Expand Up @@ -441,7 +445,7 @@ sub startsf {

if($pong !~ /^PONG/) {
logmsg "Failed sockfilt command: $mainsockfcmd\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
Expand Down Expand Up @@ -2453,7 +2457,7 @@ sub PASV_ftp {

# kill previous data connection sockfilt when alive
if($datasockf_runs eq 'yes') {
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt for $datasockf_mode data channel killed\n";
}
datasockf_state('STOPPED');
Expand Down Expand Up @@ -2494,7 +2498,7 @@ sub PASV_ftp {
logmsg "DATA sockfilt unexpected response: $pong\n";
logmsg "DATA sockfilt for passive data channel failed\n";
logmsg "DATA sockfilt killed now\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
sendcontrol "500 no free ports!\r\n";
Expand Down Expand Up @@ -2533,7 +2537,7 @@ sub PASV_ftp {
logmsg "DATA sockfilt unknown listener port\n";
logmsg "DATA sockfilt for passive data channel failed\n";
logmsg "DATA sockfilt killed now\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
sendcontrol "500 no free ports!\r\n";
Expand Down Expand Up @@ -2603,7 +2607,7 @@ sub PASV_ftp {
"on port $pasvport\n";
logmsg "accept failed or connection not even attempted\n";
logmsg "DATA sockfilt killed now\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
return;
Expand All @@ -2627,7 +2631,7 @@ sub PORT_ftp {

# kill previous data connection sockfilt when alive
if($datasockf_runs eq 'yes') {
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt for $datasockf_mode data channel killed\n";
}
datasockf_state('STOPPED');
Expand Down Expand Up @@ -2708,7 +2712,7 @@ sub PORT_ftp {
logmsg "DATA sockfilt unexpected response: $pong\n";
logmsg "DATA sockfilt for active data channel failed\n";
logmsg "DATA sockfilt killed now\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
# client shall timeout awaiting connection from server
Expand Down Expand Up @@ -3038,25 +3042,32 @@ sub customize {
# Initialize command line option dependent variables
#

if($pidfile) {
# Use our pidfile directory to store the other pidfiles
$piddir = dirname($pidfile);
}
else {
# Use the current directory to store all the pidfiles
$piddir = $path;
$pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
}
if(!$portfile) {
$portfile = $piddir . "/" . $PORTFILE;
}
if(!$srcdir) {
$srcdir = $ENV{'srcdir'} || '.';
}
if(!$pidfile) {
$pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
}

$mainsockf_pidfile = "$path/".
mainsockf_pidfilename($proto, $ipvnum, $idnum);
$mainsockf_pidfile = mainsockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$mainsockf_logfile =
mainsockf_logfilename($logdir, $proto, $ipvnum, $idnum);
$serverlogs_lockfile = "$logdir/$SERVERLOGS_LOCK";

if($proto eq 'ftp') {
$datasockf_pidfile = "$path/".
datasockf_pidfilename($proto, $ipvnum, $idnum);
$datasockf_pidfile = datasockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$datasockf_logfile =
datasockf_logfilename($logdir, $proto, $ipvnum, $idnum);
}
Expand Down Expand Up @@ -3093,7 +3104,7 @@ sub customize {

# kill previous data connection sockfilt when alive
if($datasockf_runs eq 'yes') {
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt for $datasockf_mode data channel killed now\n";
}
datasockf_state('STOPPED');
Expand Down Expand Up @@ -3340,7 +3351,7 @@ sub customize {
}
}

killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
if($serverlogslocked) {
$serverlogslocked = 0;
Expand Down
27 changes: 20 additions & 7 deletions tests/http-server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
#
#***************************************************************************

use strict;
use warnings;

BEGIN {
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
push(@INC, ".");
}

use strict;
use warnings;
use File::Basename;

use serverhelp qw(
server_pidfilename
Expand Down Expand Up @@ -57,6 +59,7 @@ BEGIN
my $flags = "";
my $path = '.';
my $logdir = $path .'/log';
my $piddir;

while(@ARGV) {
if($ARGV[0] eq '--pidfile') {
Expand Down Expand Up @@ -138,14 +141,24 @@ BEGIN
shift @ARGV;
}

if(!$srcdir) {
$srcdir = $ENV{'srcdir'} || '.';
#***************************************************************************
# Initialize command line option dependent variables
#

if($pidfile) {
# Use our pidfile directory to store the other pidfiles
$piddir = dirname($pidfile);
}
if(!$pidfile) {
$pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
else {
# Use the current directory to store all the pidfiles
$piddir = $path;
$pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
}
if(!$portfile) {
$portfile = "$path/". server_portfilename($proto, $ipvnum, $idnum);
$portfile = server_portfilename($piddir, $proto, $ipvnum, $idnum);
}
if(!$srcdir) {
$srcdir = $ENV{'srcdir'} || '.';
}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
Expand Down
16 changes: 10 additions & 6 deletions tests/rtspserver.pl
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
#
#***************************************************************************

use strict;
use warnings;

BEGIN {
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
push(@INC, ".");
}

use strict;
use warnings;

use serverhelp qw(
server_pidfilename
server_logfilename
Expand Down Expand Up @@ -112,12 +112,16 @@ BEGIN
shift @ARGV;
}

#***************************************************************************
# Initialize command line option dependent variables
#

if(!$pidfile) {
$pidfile = server_pidfilename($path, $proto, $ipvnum, $idnum);
}
if(!$srcdir) {
$srcdir = $ENV{'srcdir'} || '.';
}
if(!$pidfile) {
$pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
}
Expand Down
Loading