#! @PERL@
#
# Copyright(c) 1998-2002 Caucho Technology
#
# Helpful for getting file path information
#
use File::Basename;
use Socket;
use POSIX;
#
$port = 8099;
$FCGI_ARGS = "";

$has_command = 0;

while ( $#ARGV >= 0) {
    if ($ARGV[0] eq "-port") {
	$port=$ARGV[1];
	shift(@ARGV);
	shift(@ARGV);
    }
    else {
	$has_command = 1;
	$FCGI_ARGS .= " '" . $ARGV[0] . "'";
	shift(@ARGV);
    }
}

if (! $has_command) {
    die("fastcgirunner.pl requires a command like 'fastcgirunner.pl php'\n");
}
# create a keepalive socket
# when the wrapper dies, the httpd class will detect that and
# close gracefully
$addr = pack("S n a4 x8", AF_INET, $port, "\0\0\0");
($protoname, $aliases, $proto) = getprotobyname('tcp');
socket(S, AF_INET, SOCK_STREAM, $proto) || die "socket: $!";
bind(S, $addr) || die "bind: $!";
$myaddr = getsockname(S);
($fam, $port, $addr) = unpack("S n a4 x8", $myaddr);
listen(S, 5) || die "connect: $!";

open(STDIN, "<&" . fileno(S)) or die;
print("@FCGI_ARGS");
exec("@FCGI_ARGS");
print("Can't start fcgi\n");




