You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@httpd.apache.org by Stas Bekman <st...@stason.org> on 2001/12/23 20:10:22 UTC

[patch] catch server dies early (was Re: perl-framework: mod_dav but not mod_dav?)

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.

hmm, probably I should use POSIX::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:05:48
@@ -402,6 +402,8 @@
     }

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

     if (Apache::TestConfig::WIN32) {
         #make sure only 1 process is started for win32
@@ -418,7 +420,17 @@
         $config->{win32obj} = $obj;
     }
     else {
-        system "$cmd &";
+        require POSIX;
+        $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 15, $$;
+                }
+            }
+        };
+        $child_pid = open $child_in_pipe, "|$cmd";
     }

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

     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:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Re: [patch] catch server dies early (was Re: perl-framework: mod_dav but not mod_dav?)

Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 24 Dec 2001, Stas Bekman wrote:
 
> This one preserves the original value of SIGCHLD and uses SIGINT instead
> of 15 in kill().

SIGINT or SIGTERM ??  either way, go with 'kill SIGFOO => $$' so it'll be
easier to get rid of POSIX.pm in the near future.


Re: [patch] catch server dies early (was Re: perl-framework: mod_dav but not mod_dav?)

Posted by Stas Bekman <st...@stason.org>.
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:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Re: [patch] catch server dies early (was Re: perl-framework: mod_dav but not mod_dav?)

Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 24 Dec 2001, Stas Bekman wrote:
 
> ok, here it is. Have no clue whether you can re-use this for win32.

+1.  i'm sure it can't be used for win32, but hopefully Win32::Process
does the right thing.
 
> hmm, probably I should use POSIX::SIGINT() instead of 15 in kill.

shame we have to pull in the POSIX.pm baggage just for WNOHANG.  for kill,
you can just use the signame with the builtin: kill SIGTERM => $$