You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-cvs@httpd.apache.org by st...@apache.org on 2002/01/04 05:48:58 UTC
cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestServer.pm
stas 02/01/03 20:48:58
Modified: perl-framework/Apache-Test/lib/Apache TestServer.pm
Log:
- use explicit fork for spawning httpd, now works with 1.3 and 2.0
Revision Changes Path
1.48 +10 -1 httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.pm
Index: TestServer.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.pm,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- TestServer.pm 31 Dec 2001 10:58:22 -0000 1.47
+++ TestServer.pm 4 Jan 2002 04:48:58 -0000 1.48
@@ -433,7 +433,16 @@
}
}
};
- $child_pid = open $child_in_pipe, "|$cmd";
+
+ defined(my $pid = fork) or die "Can't fork: $!";
+ unless ($pid) { # child
+ my $status = system "$cmd";
+ if ($status) {
+ $status = $? >> 8;
+ #error "httpd didn't start! $status";
+ }
+ CORE::exit $status;
+ }
}
while ($old_pid and $old_pid == $self->pid) {
Re: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache
TestServer.pm
Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 7 Jan 2002, Stas Bekman wrote:
> better move it to the top, in case it needs to be used earlier.
not sure what you mean by earlier? i don't see any problems with the way
it is, $parent_pid will be set before any of the subroutines are called.
Re: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestServer.pm
Posted by Stas Bekman <st...@stason.org>.
Doug MacEachern wrote:
> On Mon, 7 Jan 2002, Stas Bekman wrote:
>
>
>>I needed it TestRun, whereas the fork was happening in TestServer. So it
>>was definitely easier to do it locally.
>>
>
> are you saying the following patch would not work?
+1
better move it to the top, in case it needs to be used earlier.
_____________________________________________________________________
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: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache
TestServer.pm
Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 7 Jan 2002, Stas Bekman wrote:
> I needed it TestRun, whereas the fork was happening in TestServer. So it
> was definitely easier to do it locally.
are you saying the following patch would not work?
Index: Apache-Test/lib/Apache/TestRun.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm,v
retrieving revision 1.82
diff -u -r1.82 TestRun.pm
--- Apache-Test/lib/Apache/TestRun.pm 6 Jan 2002 07:08:05 -0000 1.82
+++ Apache-Test/lib/Apache/TestRun.pm 6 Jan 2002 18:45:46 -0000
@@ -248,6 +248,9 @@
$opts->{'run-tests'} ||= @$tests;
}
+my $parent_pid = $$;
+sub is_parent { $$ == $parent_pid }
+
my $caught_sig_int = 0;
sub install_sighandlers {
@@ -276,9 +279,8 @@
#must eval "" to "install" this END block, otherwise it will
#always run, a subclass might not want that
- eval 'my $parent_pid = $$;
- END {
- return unless $$ == $parent_pid; # because of fork
+ eval 'END {
+ return unless is_parent(); # because of fork
local $?; # preserve the exit status
eval {
Apache::TestRun->new(test_config =>
Re: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestServer.pm
Posted by Stas Bekman <st...@stason.org>.
Doug MacEachern wrote:
> On Sun, 6 Jan 2002, Stas Bekman wrote:
>
>
>>I've done with this:
>>
>>
>>- eval 'END {
>>+ eval 'my $parent_pid = $$;
>>+ END {
>>+ return unless $$ == $parent_pid; # because of fork
>>
>
> ok. i thought is_parent() could be useful elsewhere, but i guess we could
> worry about that later if needed.
I needed it TestRun, whereas the fork was happening in TestServer. So it
was definitely easier to do it locally.
_____________________________________________________________________
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: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache
TestServer.pm
Posted by Doug MacEachern <do...@covalent.net>.
On Sun, 6 Jan 2002, Stas Bekman wrote:
> I've done with this:
>
>
> - eval 'END {
> + eval 'my $parent_pid = $$;
> + END {
> + return unless $$ == $parent_pid; # because of fork
ok. i thought is_parent() could be useful elsewhere, but i guess we could
worry about that later if needed.
Re: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestServer.pm
Posted by Stas Bekman <st...@stason.org>.
Doug MacEachern wrote:
> On Fri, 4 Jan 2002, Stas Bekman wrote:
>
>
>>Any idea how to disable the END blocks inheritance in the forked child?
>>
>
> my $Pid = $$;
>
> sub is_parent {
> $$ == $Pid;
> }
>
> my $pid = fork;
>
> exit unless $pid;
>
> END {
> print "END pid=$$\n";
> return unless is_parent();
> print "stuff\n";
> }
>
> prints:
> END pid=2687
> END pid=2688
> stuff
>
> without 'return unless is_parent()' prints 'stuff' twice.
nice :) I was thinking there is some magic way to tell Perl not to run END block.
I've done with this:
- eval 'END {
+ eval 'my $parent_pid = $$;
+ END {
+ return unless $$ == $parent_pid; # because of fork
local $?; # preserve the exit status
--
_____________________________________________________________________
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: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache
TestServer.pm
Posted by Doug MacEachern <do...@covalent.net>.
On Fri, 4 Jan 2002, Stas Bekman wrote:
> Any idea how to disable the END blocks inheritance in the forked child?
my $Pid = $$;
sub is_parent {
$$ == $Pid;
}
my $pid = fork;
exit unless $pid;
END {
print "END pid=$$\n";
return unless is_parent();
print "stuff\n";
}
prints:
END pid=2687
END pid=2688
stuff
without 'return unless is_parent()' prints 'stuff' twice.
Re: cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestServer.pm
Posted by Stas Bekman <st...@stason.org>.
stas@apache.org wrote:
> stas 02/01/03 20:48:58
>
> Modified: perl-framework/Apache-Test/lib/Apache TestServer.pm
> Log:
> - use explicit fork for spawning httpd, now works with 1.3 and 2.0
>
> Revision Changes Path
> 1.48 +10 -1 httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.pm
The only trouble this fix has introduced is that now the forked child
inherits END blocks from the parent and runs them on exit. So you get
the output of the core_scan in the middle of the parent print.
As I said earlier httpd-2.0 restarts itself in a way that:
system "httpd ...";
returns immediately, no matter whether the startup was successful or
not. But 1.3 doesn't return at all, unless the startup wasn't
successful. So this fork is needed only for 1.3
Any idea how to disable the END blocks inheritance in the forked child?
I guess we could silence it, by closing STD*. but in the future we may
have other END blocks which can be undesired to be run in the forked
sub-process.
> Index: TestServer.pm
> ===================================================================
> RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.pm,v
> retrieving revision 1.47
> retrieving revision 1.48
> diff -u -r1.47 -r1.48
> --- TestServer.pm 31 Dec 2001 10:58:22 -0000 1.47
> +++ TestServer.pm 4 Jan 2002 04:48:58 -0000 1.48
> @@ -433,7 +433,16 @@
> }
> }
> };
> - $child_pid = open $child_in_pipe, "|$cmd";
> +
> + defined(my $pid = fork) or die "Can't fork: $!";
> + unless ($pid) { # child
> + my $status = system "$cmd";
> + if ($status) {
> + $status = $? >> 8;
> + #error "httpd didn't start! $status";
> + }
> + CORE::exit $status;
> + }
> }
>
> while ($old_pid and $old_pid == $self->pid) {
_____________________________________________________________________
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/