mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
no more time/re-start of sockfilt, no more redirect of stdin/stdout when
talking to sockfilt
This commit is contained in:
parent
ac5635f77d
commit
72e532cb67
@ -35,16 +35,21 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use IPC::Open2;
|
use IPC::Open2;
|
||||||
|
#use Time::HiRes qw( gettimeofday ); # not available in perl 5.6
|
||||||
|
|
||||||
require "getpart.pm";
|
require "getpart.pm";
|
||||||
require "ftp.pm";
|
require "ftp.pm";
|
||||||
|
|
||||||
|
|
||||||
my $ftpdnum="";
|
my $ftpdnum="";
|
||||||
|
|
||||||
# open and close each time to allow removal at any time
|
# open and close each time to allow removal at any time
|
||||||
sub logmsg {
|
sub logmsg {
|
||||||
|
# if later than perl 5.6 is used
|
||||||
|
# my ($seconds, $microseconds) = gettimeofday;
|
||||||
|
my $seconds = time();
|
||||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
|
||||||
localtime(time);
|
localtime($seconds);
|
||||||
open(FTPLOG, ">>log/ftpd$ftpdnum.log");
|
open(FTPLOG, ">>log/ftpd$ftpdnum.log");
|
||||||
printf FTPLOG ("%02d:%02d:%02d ", $hour, $min, $sec);
|
printf FTPLOG ("%02d:%02d:%02d ", $hour, $min, $sec);
|
||||||
print FTPLOG @_;
|
print FTPLOG @_;
|
||||||
@ -116,9 +121,12 @@ $SIG{KILL} = \&catch_zap;
|
|||||||
|
|
||||||
my $sfpid;
|
my $sfpid;
|
||||||
|
|
||||||
|
local(*SFREAD, *SFWRITE);
|
||||||
|
|
||||||
|
|
||||||
sub startsf {
|
sub startsf {
|
||||||
my $cmd="./server/sockfilt --port $port --logfile log/sockctrl$ftpdnum$ext.log --pidfile .sockfilt$ftpdnum$ext.pid $ipv6";
|
my $cmd="./server/sockfilt --port $port --logfile log/sockctrl$ftpdnum$ext.log --pidfile .sockfilt$ftpdnum$ext.pid $ipv6";
|
||||||
$sfpid = open2(\*SFREAD, \*SFWRITE, $cmd);
|
$sfpid = open2(*SFREAD, *SFWRITE, $cmd);
|
||||||
|
|
||||||
print STDERR "$cmd\n" if($verbose);
|
print STDERR "$cmd\n" if($verbose);
|
||||||
|
|
||||||
@ -131,8 +139,6 @@ sub startsf {
|
|||||||
kill(9, $sfpid);
|
kill(9, $sfpid);
|
||||||
die "Failed to start sockfilt!";
|
die "Failed to start sockfilt!";
|
||||||
}
|
}
|
||||||
open(STDIN, "<&SFREAD") || die "can't dup client to stdin";
|
|
||||||
open(STDOUT, ">&SFWRITE") || die "can't dup client to stdout";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove the file here so that if startsf() fails, it is very noticable
|
# remove the file here so that if startsf() fails, it is very noticable
|
||||||
@ -150,8 +156,8 @@ logmsg("logged pid $$ in $pidfile\n");
|
|||||||
sub sockfilt {
|
sub sockfilt {
|
||||||
my $l;
|
my $l;
|
||||||
foreach $l (@_) {
|
foreach $l (@_) {
|
||||||
printf "DATA\n%04x\n", length($l);
|
printf SFWRITE "DATA\n%04x\n", length($l);
|
||||||
print $l;
|
print SFWRITE $l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,29 +726,13 @@ while(1) {
|
|||||||
# We read 'sockfilt' commands.
|
# We read 'sockfilt' commands.
|
||||||
#
|
#
|
||||||
my $input;
|
my $input;
|
||||||
eval {
|
|
||||||
local $SIG{ALRM} = sub { die "alarm\n" };
|
logmsg "Awaiting input\n";
|
||||||
alarm 360; # just in case things go REALLY bad
|
sysread(SFREAD, $input, 5) || die "ftp$ftpdnum$ext read zero";
|
||||||
$input = <STDIN>;
|
|
||||||
alarm 0;
|
|
||||||
};
|
|
||||||
if ($@) {
|
|
||||||
# timed out
|
|
||||||
logmsg "reading stdin timed out\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if($input !~ /^CNCT/) {
|
if($input !~ /^CNCT/) {
|
||||||
# we wait for a connected client
|
# we wait for a connected client
|
||||||
if(!length($input)) {
|
logmsg "sockfilt said: $input";
|
||||||
# it probably died, restart it
|
|
||||||
kill(9, $sfpid);
|
|
||||||
waitpid $sfpid, 0;
|
|
||||||
startsf();
|
|
||||||
logmsg "restarted sockfilt\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logmsg "sockfilt said: $input";
|
|
||||||
}
|
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
logmsg "====> Client connect\n";
|
logmsg "====> Client connect\n";
|
||||||
@ -770,7 +760,7 @@ while(1) {
|
|||||||
# part only is FTP lingo.
|
# part only is FTP lingo.
|
||||||
|
|
||||||
# COMMAND
|
# COMMAND
|
||||||
sysread(STDIN, $i, 5) || die;
|
sysread(SFREAD, $i, 5) || die "ftp$ftpdnum$ext read zero";
|
||||||
|
|
||||||
if($i !~ /^DATA/) {
|
if($i !~ /^DATA/) {
|
||||||
logmsg "sockfilt said $i";
|
logmsg "sockfilt said $i";
|
||||||
@ -782,11 +772,11 @@ while(1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# SIZE of data
|
# SIZE of data
|
||||||
sysread(STDIN, $i, 5) || die;
|
sysread(SFREAD, $i, 5) || die;
|
||||||
my $size = hex($i);
|
my $size = hex($i);
|
||||||
|
|
||||||
# data
|
# data
|
||||||
sysread STDIN, $_, $size;
|
sysread SFREAD, $_, $size;
|
||||||
|
|
||||||
ftpmsg $_;
|
ftpmsg $_;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user