Xml-rpc daemon hangs between requests despite 'exec'
Sam Seaver <[email protected]> Wed, 18 Jun 2003 13:30:58 -0400
| Newsgroups | gmane.comp.windows.devel.soap.general |
|---|---|
| Message-ID | <LISTSERV%[email protected]> |
Dear all,
I have this daemon runnning, code posted at bottom. It works fine when it
receives a request. It's main aim is to run a piece of software, as noted
by the exec at the bottom. The exec is used with a fork, so that the
response is sent, while the program is running.
All the LOG lines are to see where in the daemon it hangs, because my
problem is, if i send multiple requests, the daemon waits UNTIL the program
that is running in the fork FINISHES, before it then runs 'go' again...in
other words, despite the fork AND exec, it still waits for the fork to
return or whatever, does any have a clue?
Thanks
Sam Seaver
#!/usr/bin/env perl
use XMLRPC::Transport::HTTP;
use XML::Xerces;
use XML::Xerces::DOMParse;
use Carp;
use Fcntl ":flock";
use IO::File;
my $daemon = XMLRPC::Transport::HTTP::Daemon
-> new (LocalPort => 8081, Reuse => 1)
-> dispatch_to('Monster')
;
print "Contact to XMLRPC server at ", $daemon->url, "\n";
$daemon->handle;
package Monster;
sub go{
open LOG, ">> /home/tomcat/daemon.log" or die "opening log: $!\n";
LOG->autoflush(1);
printf LOG "PROC $$: %d %s run starts %s\n",
time, __FILE__, scalar(localtime);
shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
my $CP = shift;
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
my $filePath = "/usr/local/jakarta-tomcat-4.1.12/webapps/monster/jobs/";
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
$|=1;
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
my $parser = XML::Xerces::DOMParser->new();
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
$parser->setCreateEntityReferenceNodes(1);
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
my $error_handler = XML::Xerces::PerlErrorHandler->new();
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
$parser->setErrorHandler($error_handler);
my $in;
eval {$in = XML::Xerces::MemBufInputSource->new($CP);};
error($@) if $@;
eval {$parser->parse($in);};
error($@) if $@;
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
my $doc = $parser->getDocument();
my $cps = $doc->getElementsByTagName("ChainPairs");
my $id =
$cps->item(0)->getAttributes()->getNamedItem("index")->getNodeValue();
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
my $filePath2 = "$filePath$id/";
mkdir $filePath2;
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
my $fileNode = $doc->getElementsByTagName("File");
my $file = $fileNode->item(0)->getChildNodes->item(0)->getNodeValue();
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
$file = substr($file, 37);
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
$pdb = substr($file, 0, -4);
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
open (F, ">$filePath2$pdb.cp" ) or die "couldn't open file $pdb.cp: $!";
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
flock(F, LOCK_EX);
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
print F $CP;
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
flock(F, LOCK_UN);
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
close F;
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
$SIG{CHLD}=sub { use POSIX ":sys_wait_h"; waitpid(-1, &WNOHANG); print
"Child exited\n";};
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
$| = 1;
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
exec("/usr/local/bin/monster", "-i$id", "$filePath$file") unless fork();
printf LOG "PROC $$: %d %s(%d)\n", time, __FILE__, __LINE__;
return 0;
}