Hallo liebe Netzgemeinde, und en besonderes "Hallo" an seth_not@home, der mir schon beim letzten Mal (http://forum.de.selfhtml.org/archiv/2007/5/t152146/) behilflich war.
Auch dieses Mal klemmt es wieder beim Thema "fork".
An der Bash läuft mein Skript; Starte ich es jedoch als CGI, terminiert es nicht und malt mir endlos die Wartenachricht in den Browser.
Hier das Skriptchen:
------------------------------------------------------
#!/usr/bin/perl -w
Testskript fuer einzelnen "fork"
use CGI::Carp qw(fatalsToBrowser);
use POSIX;
print "Content-type: text/html\n\n";
print qq~
<HTML>
<HEAD><TITLE>Test</TITLE></HEAD>
<BODY>
<tt>~;
$|=1;
pipe READFD,WRITEFD;
my $oh= select(WRITEFD); select($oh);
my $Kind_pid = fork();
if($Kind_pid) {
#Teil 1
use POSIX ":sys_wait_h";
my $waitcount=1;
do {
$Kind_pid = waitpid(-1,&WNOHANG);
#Wartenachricht hier
print " ...".$waitcount; # Hier zaehlt er als CGI endlos hoch
$waitcount++;
sleep 2;
} until $Kind_pid == -1;
close(WRITEFD);
@returnvalue=<READFD>;
}
else {
#Teil 2
my $cvscan='';
sleep 10; # kuenstlich ausbremsen, damit Teil 1 was zu tun hat
my @childvs=echo "foobar"
; # beliebiger Befehl
# der Befehl wird laut "ps ax" auch beim Aufruf als CGI ausgefuehrt und beendet
close(READFD);
foreach $cvs (@childvs){
#print $cvs."<br>\n";
print WRITEFD $cvs;
}
exit(0);
}
#Weitere Verarbeitung hier
print "\nAusgabe hier\n";
print @returnvalue;
print qq~
</tt>
</BODY>
</HTML>
~;
------------------------------------------------------
Und nachfolgend noch ein bisschen Debug-Info...
------------------------------------------------------
Aufruf an der Bash:
user@host# perl cgi-bin/test.pl
Content-type: text/html
<HTML>
<HEAD><TITLE>Test</TITLE></HEAD>
<BODY>
<tt> ...1 ...2 ...3 ...4 ...5 ...6 ...7
Ausgabe hier
foobar
</tt>
</BODY>
</HTML>
-->Alles OK
------------------------------------------------------
Ausgabe im Browser (Quelltextanzeige)
<HTML>
<HEAD><TITLE>Test</TITLE></HEAD>
<BODY>
<tt> ...1 ...2 ...3 ...4 ...5 ...6 ...7 ...8 ...9 ...10 ...11 ...12 ...13 ...14 ...15
-->Mit anderen Worten, er terminiert nicht!
------------------------------------------------------
Verwendeter Webserver:
Package: thttpd
Priority: optional
Section: web
Installed-Size: 216
Maintainer: Daniel Baumann daniel.baumann@panthera-systems.net
Architecture: i386
Version: 2.23beta1-5
Provides: httpd, httpd-cgi
Depends: libc6 (>= 2.3.6-6), logrotate
Suggests: thttpd-util
Filename: pool/main/t/thttpd/thttpd_2.23beta1-5_i386.deb
Size: 54482
MD5sum: 18e7b8b8e80975a13b6ef3b9770cecb6
SHA1: 46a6f70d960e95f8b6e35aa992a6655ac9b2d5ff
SHA256: 2dc5e8fcf217e2fd97f90a6c1537d0f124e409b4d90810b31e4da48463e0803f
Description: tiny/turbo/throttling HTTP server
thttpd is a small, fast secure webserver. It features CGI support,
URL-traffic-based throttling and basic authentication.
thttpd has a very small memory footprint as it only forks itself in order
to execute CGI scripts. It is designed to be as fast as fully featured
web-servers and it performs extremely well under high load.
.
This package contains the thttpd server. For thttpd support programs see
the thttpd-util package.
Tag: interface::daemon, network::server, protocol::http, role::program, web::server, works-with::text, works-with-format::html
------------------------------------------------------
Config-Datei des Webservers:
user@host# cat /etc/thttpd/thttpd.conf
port=80
nochroot
user=www-data
logfile=/var/log/thttpd.log
throttles=/etc/thttpd/throttle.conf
dir=/var/www
cgipat=/cgi-bin/*
------------------------------------------------------
Dateirechte:
user@host# ls -lah cgi-bin
insgesamt 4,0K
drwxr-xr-x 2 root root 72 2007-07-10 14:50 .
drwxr-xr-x 4 root root 96 2007-07-10 14:46 ..
-rwxr-xr-x 1 root root 932 2007-07-10 14:50 test.pl
------------------------------------------------------
Verzeichnisrechte:
user@host# ls -lah
insgesamt 0
drwxr-xr-x 4 root root 96 2007-07-10 14:46 .
drwxr-xr-x 14 root root 336 2007-07-10 14:45 ..
drwxr-xr-x 2 root root 72 2007-07-10 14:50 cgi-bin
drwxr-xr-x 2 root root 48 2006-10-31 20:16 users
------------------------------------------------------
Perl-Version:
user@host# perl -v
This is perl, v5.8.8 built for i486-linux-gnu-thread-multi
Copyright 1987-2006, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
------------------------------------------------------
In der Hoffnung auf Erleuchtung aus der Community,
Stefan