On Mon, 24 Dec 2001, Stas Bekman wrote:

> On Tue, 4 Dec 2001, Doug MacEachern wrote:
>
> > On Wed, 5 Dec 2001, Stas Bekman wrote:
> >
> > > ok, but that catches only syntax errors. if we can catch the return
> > > status from system() we can catch all errors, causing the failure.
> >
> > that would be great.
>
> ok, here it is. Have no clue whether you can re-use this for win32.

prev patch was partially broken.

This one preserves the original value of SIGCHLD and uses SIGINT instead
of 15 in kill().

Index: Apache-Test/lib/Apache/TestServer.pm
===================================================================
RCS file: 
/home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.pm,v
retrieving revision 1.46
diff -u -r1.46 TestServer.pm
--- Apache-Test/lib/Apache/TestServer.pm        2001/12/20 17:30:54     1.46
+++ Apache-Test/lib/Apache/TestServer.pm        2001/12/23 19:42:34
@@ -402,6 +402,9 @@
     }

     print "$cmd\n";
+    my $child_pid;
+    my $child_in_pipe;
+    my $old_sig;

     if (Apache::TestConfig::WIN32) {
         #make sure only 1 process is started for win32
@@ -418,7 +421,18 @@
         $config->{win32obj} = $obj;
     }
     else {
-        system "$cmd &";
+        require POSIX;
+        $old_sig = $SIG{CHLD};
+        $SIG{CHLD} = sub {
+            while ((my $child = waitpid(-1, POSIX::WNOHANG())) > 0) {
+                my $status  = $? >> 8;
+                if ($status) {
+                    $self->failed_msg("\nserver has died with status $status");
+                    kill POSIX::SIGINT(), $$;
+                }
+            }
+        };
+        $child_pid = open $child_in_pipe, "|$cmd";
     }

     while ($old_pid and $old_pid == $self->pid) {
@@ -450,6 +464,10 @@
             last;
         }
     }
+
+    # now that the server has started don't abort the test run if it
+    # dies
+    $SIG{CHLD} = $old_sig || 'DEFAULT';

     if (my $pid = $self->pid) {
         print "server $self->{name} started\n";


_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/

Reply via email to