You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Robert S. Thau" <rs...@ai.mit.edu> on 1995/08/27 16:19:26 UTC

patch11.inc-cgi-pause

This eliminates the "pause after including CGI script" behavior observed
with certain scripts on certain systems, for which you get "SIGTERM/pause/
kill" routine before the script has a chance to die on its own.  The
same problem exists for <!--#exec cmd--> children, and is fixed for them
as well.

It works by not even trying to mop up these subprocesses until we are
wrapping up the connection, after we have sent the entire document ---
this is done by spawning the process off the per- connection resource
pool, rather than the per-request resource pool.  I also added code to
close the FILE *'s associated with communication with CGI scripts,
since an include page which otherwise includes a *lot* of CGI children
might otherwise run out of file descriptors.  (These were formerly
closed when the per-process resource pool was cleaned up; the
descriptor was already being closed for <!--#exec cmd=""--> children).

NB to reliably duplicate this bug, I had to write a CGI script that closes
stdout and then sleeps for a second, to guarantee inopportune timing.

diff -c ./mod_cgi.c ../mod_cgi.c
*** ./mod_cgi.c	Sun Aug 27 09:16:45 1995
--- ../mod_cgi.c	Sun Aug 27 09:35:01 1995
***************
*** 264,270 ****
      add_common_vars (r);
      cld.argv0 = argv0; cld.r = r; cld.nph = nph;
      
!     if (!spawn_child (r->pool, cgi_child, (void *)&cld,
  		      nph ? just_wait : kill_after_timeout,
  		      &script_out, nph ? NULL : &script_in)) {
          log_reason ("couldn't spawn child process", r->filename, r);
--- 264,270 ----
      add_common_vars (r);
      cld.argv0 = argv0; cld.r = r; cld.nph = nph;
      
!     if (!spawn_child (r->connection->pool, cgi_child, (void *)&cld,
  		      nph ? just_wait : kill_after_timeout,
  		      &script_out, nph ? NULL : &script_in)) {
          log_reason ("couldn't spawn child process", r->filename, r);
***************
*** 304,309 ****
--- 304,311 ----
  	kill_timeout (r);
      }
      
+     pfclose (r->connection->pool, script_out);
+     
      /* Handle script return... */
      
      if (script_in && !nph) {
***************
*** 337,342 ****
--- 339,345 ----
  	send_http_header(r);
          if(!r->header_only) send_fd (script_in, r);
  	kill_timeout (r);
+ 	pfclose (r->connection->pool, script_in);
      }
  
      return OK;			/* NOT r->status, even if it has changed. */
diff -c ./mod_include.c ../mod_include.c
*** ./mod_include.c	Sun Aug 27 09:16:45 1995
--- ../mod_include.c	Sun Aug 27 09:36:12 1995
***************
*** 470,476 ****
  
      arg.r = r; arg.s = s;
  
!     if (!spawn_child (r->pool, include_cmd_child, &arg,
  		      kill_after_timeout, NULL, &f))
          return -1;
      
--- 470,476 ----
  
      arg.r = r; arg.s = s;
  
!     if (!spawn_child (r->connection->pool, include_cmd_child, &arg,
  		      kill_after_timeout, NULL, &f))
          return -1;