From apwww@hyperreal.org Wed Oct 8 18:49:29 1997 Received: (from apwww@localhost) by hyperreal.org (8.8.5/8.8.5) id SAA21920; Wed, 8 Oct 1997 18:49:29 -0700 (PDT) Message-Id: <199710090149.SAA21920@hyperreal.org> Date: Wed, 8 Oct 1997 18:49:29 -0700 (PDT) From: Garry Shtern Reply-To: shterng@akula.com To: apbugs@hyperreal.org Subject: forking in cgi produces duplicate invocation of the script X-Send-Pr-Version: 3.2 >Number: 1213 >Category: general >Synopsis: forking in cgi produces duplicate invocation of the script >Confidential: no >Severity: serious >Priority: medium >Responsible: apache >State: closed >Class: sw-bug >Submitter-Id: apache >Arrival-Date: Thu Oct 9 03:50:02 PDT 1997 >Last-Modified: Tue Oct 14 15:40:00 PDT 1997 >Originator: shterng@akula.com >Organization: apache >Release: 1.2.4 >Environment: Linux vader 2.0.31 #12 Tue Sep 30 01:46:24 EDT 1997 i686 >Description: If I try forking within a cgi (perl script), the output displayed from the script indicates that the cgi was executed twice. However, removing the forking solves the problem. Down/Upgraded the perl. Problem still persists. Script works fine from a command prompt. >How-To-Repeat: write a little perl script that forks and have child perform a task such as email back a user, and parent display an html. The output will indicate that the script was invoked twice. Beware NS4 crashes in this case >Fix: >Audit-Trail: State-Changed-From-To: open-closed State-Changed-By: marc State-Changed-When: Thu Oct 9 06:33:38 PDT 1997 State-Changed-Why: This is a bug in your script. Please read all the big notices posted before submitting a PR; this has nothing to do with Apache. Somewhere your script has a bug in it. It may not be flushing output before forking, it may not be properly closing stdout in the child. Post to comp.infosystems.www.authoring.cgi and perhaps someone can help you. We don't have time to help everyone write their CGIs. From: Garry Shtern To: Marc Slemko Cc: Apache bugs database Subject: Re: general/1213 Date: Thu, 09 Oct 1997 16:06:57 -0400 At 01:53 PM 10/9/97 -0600, Marc Slemko wrote: >You are not flushing the IO buffers before forking, so they end up being >flushed by the parent and the child. > >Add a "$| = 1;" to the start and perl will automatically flush them after >each output, or you can manually flush them before forking in some way >that I forget right now. > That worked.. Thanks a lot... Sorry for the trouble.... Garry Shtern shterng@akula.com Chief Network Administrator http://www.akula.com Akula Communications Corp. tel. (212) 292-8892 From: Marc Slemko To: Garry Shtern Cc: Apache bugs database Subject: Re: general/1213 Date: Thu, 9 Oct 1997 13:53:03 -0600 (MDT) On Thu, 9 Oct 1997, Garry Shtern wrote: > On 9 Oct 1997 marc@taz.hyperreal.org wrote: > > > Synopsis: forking in cgi produces duplicate invocation of the script > > > > State-Changed-From-To: open-closed > > State-Changed-By: marc > > State-Changed-When: Thu Oct 9 06:33:38 PDT 1997 > > State-Changed-Why: > > This is a bug in your script. Please read all the big notices posted before > > submitting a PR; this has nothing to do with Apache. > > > > Somewhere your script has a bug in it. It may not be flushing output > > before forking, it may not be properly closing stdout in the child. > > Post to comp.infosystems.www.authoring.cgi and perhaps someone can help > > you. We don't have time to help everyone write their CGIs. > > > > I thought so too.. However, check this out... go to > http://www.akula.com/cgi-bin/test.pl?df=test > > and see what you get.. this is the script: > > #!/usr/bin/perl > use CGI; > $query = new CGI; > print $query->header; > > $pid=fork; > if ($pid) { > $value = $query->param('df'); > print "$value"; > exit; } -Garry So? Your script is broken. You are not flushing the IO buffers before forking, so they end up being flushed by the parent and the child. Add a "$| = 1;" to the start and perl will automatically flush them after each output, or you can manually flush them before forking in some way that I forget right now. >Unformatted: