Commit 5b0bfc29 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

improved the check for our own ftp server

parent 0383f7f1
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
@@ -448,26 +448,26 @@ sub runftpserver {
        print "RUN: Check port $FTPPORT for our own FTP server\n"
            if ($verbose);


        my $time=time();
        # check if this is our server running on this port:
        my $data=`$CURL -m4 --silent -i ftp://$HOSTIP:$FTPPORT/verifiedserver 2>/dev/null`;
        my @data=`$CURL -m4 --silent ftp://$HOSTIP:$FTPPORT/verifiedserver 2>/dev/null`;
        my $line;

        # if this took more than 2 secs, we assume it "hung" on a weird server
        my $took = time()-$time;

        if ( $data =~ /WE ROOLZ: (\d+)/ ) {
        foreach $line (@data) {
            if ( $line =~ /WE ROOLZ: (\d+)/ ) {
                # this is our test server with a known pid!
                $pid = 0+$1;
            }
        else {
            if($data || ($took > 2)) {
        }
        if(!$pid || ($took > 2)) {
            # this is not a known server
            print "RUN: Unknown server on our favourite port: $FTPPORT\n";
            return -1;
        }
    }
    }

    if($pid > 0) {
        print "RUN: Killing a previous server using pid $pid\n" if($verbose);
@@ -490,22 +490,31 @@ sub runftpserver {
    system($cmd);

    my $verified;
    $pid = 0;
    for(1 .. 10) {
        # verify that our server is up and running:
        my $data=`$CURL --silent -i ftp://$HOSTIP:$FTPPORT/verifiedserver 2>/dev/null`;

        if ( $data =~ /WE ROOLZ: (\d+)/ ) {
        my $line;
        my $cmd="$CURL --silent ftp://$HOSTIP:$FTPPORT/verifiedserver 2>/dev/null";
        print "$cmd\n" if($verbose);
        my @data = `$cmd`;
        foreach $line (@data) {
            print STDERR "We read: $_";
            if ( $line =~ /WE ROOLZ: (\d+)/ ) {
                $pid = 0+$1;
                $verified = 1;
                last;
            }
        else {
        }
        if(!$pid) {
            if($verbose) {
                print STDERR "RUN: Retrying FTP server existence in 3 sec\n";
            }
            sleep(3);
            next;
        }
        else {
            last;
        }
    }
    if(!$verified) {
        warn "RUN: failed to start our FTP server\n";