1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

removed the forks, we don't need forking for single-task testing

This commit is contained in:
Daniel Stenberg 2000-11-21 12:00:24 +00:00
parent 641351ee16
commit 19a754dc8c

View File

@ -117,10 +117,10 @@ sub LIST_command {
logmsg "$$: pass data to child pid\n"; logmsg "$$: pass data to child pid\n";
for(@ftpdir) { for(@ftpdir) {
print KID_TO_WRITE $_; print SOCK $_;
# print STDERR "PASS: $_"; print STDERR "PASS: $_";
} }
close(KID_TO_WRITE); close(SOCK);
logmsg "$$: done passing data to child pid\n"; logmsg "$$: done passing data to child pid\n";
print "226 ASCII transfer complete\r\n"; print "226 ASCII transfer complete\r\n";
@ -144,10 +144,10 @@ sub RETR_command {
open(FILE, "<$filename"); open(FILE, "<$filename");
while(<FILE>) { while(<FILE>) {
print KID_TO_WRITE $_; print SOCK $_;
# print STDERR "PASS: $_";
} }
close(KID_TO_WRITE); close(FILE);
close(SOCK);
print "226 File transfer complete\r\n"; print "226 File transfer complete\r\n";
} }
@ -176,21 +176,6 @@ sub RETR_command {
# #
sub PASV_command { sub PASV_command {
$pid = open(KID_TO_WRITE, "|-");
$SIG{ALRM} = sub { die "whoops, pipe broke" };
if(0 == $pid) {
# the child process runs the child function
logmsg "$$ is a child PASV\n";
}
else {
# parent continues
# print STDERR "parent after fork!\n";
logmsg "$$ is a parent from PASV\n";
return; # continue please
}
my $port = 10000;
socket(Server2, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; socket(Server2, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
setsockopt(Server2, SOL_SOCKET, SO_REUSEADDR, setsockopt(Server2, SOL_SOCKET, SO_REUSEADDR,
pack("l", 1)) || die "setsockopt: $!"; pack("l", 1)) || die "setsockopt: $!";
@ -203,7 +188,7 @@ sub PASV_command {
if(11000 == $port) { if(11000 == $port) {
print "500 no free ports!\r\n"; print "500 no free ports!\r\n";
logmsg "couldn't find free port\n"; logmsg "couldn't find free port\n";
exit; return 0;
} }
listen(Server2,SOMAXCONN) || die "listen: $!"; listen(Server2,SOMAXCONN) || die "listen: $!";
@ -213,71 +198,31 @@ sub PASV_command {
my $waitedpid; my $waitedpid;
my $paddr; my $paddr;
$paddr = accept(Client2, Server2); $paddr = accept(SOCK, Server2);
my($port,$iaddr) = sockaddr_in($paddr); my($port,$iaddr) = sockaddr_in($paddr);
my $name = gethostbyaddr($iaddr,AF_INET); my $name = gethostbyaddr($iaddr,AF_INET);
logmsg "$$: data connection from $name [", inet_ntoa($iaddr), "] at port $port\n"; logmsg "$$: data connection from $name [", inet_ntoa($iaddr), "] at port $port\n";
open(STDOUT, ">&Client2") || die "can't dup client to stdout"; return \&SOCK;
while(<STDIN>) {
print $_;
}
close(Client2);
logmsg "process dies here\n";
exit;
} }
sub PORT_command { sub PORT_command {
my $arg = $_[0]; my $arg = $_[0];
# print STDERR "fooo: $arg\n";
$pid = open(KID_TO_WRITE, "|-");
$SIG{ALRM} = sub { die "whoops, pipe broke" };
if(0 == $pid) {
# the child process runs the child function
}
else {
# parent continues
# print STDERR "parent after fork!\n";
return; # continue please
}
# open(STDOUT, ">&Client") || die "can't dup client to stdout";
if($arg !~ /(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/) { if($arg !~ /(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/) {
logmsg "bad PORT-line: $arg\n"; logmsg "bad PORT-line: $arg\n";
print "500 silly you, go away\r\n"; print "500 silly you, go away\r\n";
exit; return 0;
} }
my $iaddr = inet_aton("$1.$2.$3.$4"); my $iaddr = inet_aton("$1.$2.$3.$4");
my $paddr = sockaddr_in(($5<<8)+$6, $iaddr); my $paddr = sockaddr_in(($5<<8)+$6, $iaddr);
my $proto = getprotobyname('tcp') || 6; my $proto = getprotobyname('tcp') || 6;
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "major failure"; socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "major failure";
# print STDERR "socket()\n";
connect(SOCK, $paddr) || return 1; connect(SOCK, $paddr) || return 1;
# print STDERR "connect()\n";
#while (defined($line = <SOCK>)) { return \&SOCK;
#print STDERR $line;
#}
# print STDERR "sending stdin to client\n";
while(<STDIN>) {
print SOCK $_;
# print STDERR "SEND: $_";
}
close(SOCK);
# print STDERR "close(SOCK)\n";
exit; # we're a chiuld process who dies!
} }
$SIG{CHLD} = \&REAPER; $SIG{CHLD} = \&REAPER;