httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject [PATCH] from uunet: the rest
Date Fri, 22 Aug 1997 17:17:53 GMT
Here's the remainder of the patches from uunet ... these need a bit more
work.

I agree with the desire to get child_status from dying CGIs but I don't
like having to do it with a global.  Maybe there's another way. 

Printing errno numbers is mostly useless.  save_errno is a good thing. 

The -o option below we won't need if we go with my suggestion for closing
stdin/out/err at detach() time.

SCRIPT_FILENAME ... well, uunet probably does this to avoid people writing
CGIs that use it.  Dunno. 

Dean

Thu Aug 14 12:01:28 1997  David J. MacKenzie  <djm@va.pubnix.com>

	* alloc.c, mod_cgi.c: Save the child status in a global variable.
	* http_protocol.c [!NEED_WAITPID]: Use it in the server error
	message and log, to help debug CGI programs.

	* mod_cgi.c: Give the reason (errno string) for child process
	spawn failure.
	* mod_cgi.c, mod_include.c: Remove the numeric errno from the
	error string. 
	
	* http_main.c (main): Add a -o option to not keep the standard file
	descriptors open, to work around a Kerberos rsh bug.
	
	* util_script.c: Don't set SCRIPT_FILENAME.  It's not used by
	anything, and NCSA doesn't set it.

Index: src/alloc.c
--- alloc.c	1997/07/08 21:08:30	1.1
+++ alloc.c	1997/07/08 21:22:42	1.2
@@ -1073,6 +1073,9 @@
   return pid;
 }
 
+/* Checked in send_error_response().  */
+int child_status = 0;
+
 static void free_proc_chain (struct process_chain *procs)
 {
   /* Dispose of the subprocesses we've spawned off in the course of
@@ -1082,7 +1085,6 @@
 
   struct process_chain *p;
   int need_timeout = 0;
-  int status;
 
   if (procs == NULL) return;	/* No work.  Whew! */
 
@@ -1096,7 +1098,7 @@
 #ifndef NEED_WAITPID
   /* Pick up all defunct processes */
   for (p = procs; p; p = p->next) {
-    if (waitpid (p->pid, (int *) 0, WNOHANG) > 0) {
+    if (waitpid (p->pid, &child_status, WNOHANG) > 0) {
       p->kill_how = kill_never;
     }
   }
@@ -1127,7 +1129,7 @@
       kill (p->pid, SIGKILL);
 
     if (p->kill_how != kill_never)
-      waitpid (p->pid, &status, 0);
+      waitpid (p->pid, &child_status, 0);
   }
 }
 
Index: src/http_main.c
--- http_main.c	1997/07/08 21:08:30	1.1
+++ http_main.c	1997/07/10 18:11:25	1.3
@@ -2335,6 +2335,7 @@
 main(int argc, char *argv[])
 {
     int c;
+    int close_descs = 0;
 
 #ifdef AUX
     (void)set42sig();
@@ -2360,7 +2361,7 @@
     strncpy (server_confname, SERVER_CONFIG_FILE, sizeof(server_root)-1);
     server_confname[sizeof(server_confname)-1] = '\0';
 
-    while((c = getopt(argc,argv,"Xd:f:vhl")) != -1) {
+    while((c = getopt(argc,argv,"Xd:f:vhlo")) != -1) {
         switch(c) {
           case 'd':
             strncpy (server_root, optarg, sizeof(server_root)-1);
@@ -2382,6 +2383,9 @@
 	  case 'X':
 	    ++one_process;	/* Weird debugging mode. */
 	    break;
+	  case 'o':
+	    close_descs = 1;
+	    break;
           case '?':
             usage(argv[0]);
         }
@@ -2400,6 +2404,12 @@
     
     if(standalone) {
         clear_pool (pconf);	/* standalone_main rereads... */
+	if (close_descs) {
+	  /* Allow restarting apache using Kerberos rsh: don't hold open its file descriptors. 
*/
+	  freopen("/dev/null", "r", stdin);
+	  freopen("/dev/null", "w", stdout);
+	  freopen("/dev/null", "w+", stderr);
+	}
         standalone_main(argc, argv);
     }
     else {
Index: src/http_protocol.c
--- http_protocol.c	1997/07/08 21:08:30	1.1
+++ http_protocol.c	1997/07/08 21:22:44	1.2
@@ -1641,6 +1641,17 @@
     return bflush(r->connection->client);
 }
 
+#ifndef NEED_WAITPID
+const char *
+strsig(int n)
+{
+  if (n >= 0 && n < NSIG)
+    return sys_siglist[n];
+  else
+    return "Unknown signal";
+}
+#endif /* NEED_WAITPID */
+
 /* We should have named this send_canned_response, since it is used for any
  * response that can be generated by the server from the request record.
  * This includes all 204 (no content), 3xx (redirect), 4xx (client error),
@@ -1654,6 +1665,9 @@
     int idx = index_of_response (status);
     char *custom_response;
     char *location = pstrdup(r->pool, table_get(r->headers_out, "Location"));
+#ifndef NEED_WAITPID
+    extern int child_status;
+#endif
 
     /* We need to special-case the handling of 204 and 304 responses,
      * since they have specific HTTP requirements and do not include a
@@ -1888,6 +1902,24 @@
 	    bputs(" and inform them of the time the error occurred,\n", fd);
 	    bputs("and anything you might have done that may have\n", fd);
 	    bputs("caused the error.<P>\n", fd);
+
+#ifndef NEED_WAITPID
+	    if (child_status == 0)
+	      waitpid(-1, &child_status, WNOHANG);
+
+	    if (WIFSIGNALED(child_status)) {
+	      log_printf(r->server, 
+			 "CGI or SSI script run from %s received signal %s.",
+			 r->filename, strsig(WTERMSIG(child_status)));
+	      fflush (r->server->error_log); /* Help debugging.  */
+
+	      bputs("CGI or SSI script run from ", fd);
+	      bputs(r->filename, fd);
+	      bputs(" received signal ", fd);
+	      bputs(strsig(WTERMSIG(child_status)), fd);
+	      bputs(".<P>\n", fd);
+	    }
+#endif
 	    break;
 	}
 
Index: src/mod_cgi.c
--- mod_cgi.c	1997/07/08 21:08:30	1.1
+++ mod_cgi.c	1997/08/14 15:55:18	1.4
@@ -333,14 +334,15 @@
      */
     
     ap_snprintf(err_string, sizeof(err_string),
-	    "exec of %s failed, reason: %s (errno = %d)\n", 
-            r->filename, strerror(errno), errno);
+	    "exec of %s failed: %s\n", 
+            r->filename, strerror(errno));
     write(2, err_string, strlen(err_string));
     exit(0);
 }
 
 int cgi_handler (request_rec *r)
 {
+    extern int child_status;
     int retval, nph, dbpos = 0;
     char *argv0, *dbuf = NULL;
     FILE *script_out, *script_in, *script_err;
@@ -421,7 +424,12 @@
 			   &script_out, nph ? NULL : &script_in,
 	    		   &script_err))) {
 #endif
-        log_reason ("couldn't spawn child process", r->filename, r);
+	int save_errno = errno;
+	char *errbuf = (char *)palloc(r->main ? r->main->pool : r->pool, 
+				      strlen(strerror(save_errno)) + 80);
+	sprintf(errbuf, "couldn't spawn child process: %s",
+	  strerror(save_errno));
+	log_reason(errbuf, r->filename, r);
         return SERVER_ERROR;
     }
 
@@ -542,7 +550,7 @@
             bputs(argsbuffer, r->connection->client);
         }
 #else
-	waitpid(child_pid, (int*)0, 0);
+	waitpid(child_pid, &child_status, 0);
 #endif
     }    
 
Index: src/mod_include.c
--- mod_include.c	1997/07/08 21:08:31	1.1
+++ mod_include.c	1997/07/08 21:22:47	1.2
@@ -652,8 +657,8 @@
     fprintf (dbg, "Exec failed\n");
 #endif    
     ap_snprintf(err_string, sizeof(err_string),
-	"httpd: exec of %s failed, reason: %s (errno = %d)\n",
-	SHELL_PATH, strerror(errno), errno);
+	"httpd: exec of %s failed: %s\n",
+	SHELL_PATH, strerror(errno));
     write (2, err_string, strlen(err_string));
     exit(0);
 }
Index: src/util_script.c
--- util_script.c	1997/07/08 21:08:31	1.1
+++ util_script.c	1997/07/08 21:22:48	1.2
@@ -199,8 +199,9 @@
     table_set (e, "REMOTE_ADDR", c->remote_ip);
     table_set (e, "DOCUMENT_ROOT", document_root(r)); /* Apache */
     table_set (e, "SERVER_ADMIN", s->server_admin); /* Apache */
+#if 0
     table_set (e, "SCRIPT_FILENAME", r->filename); /* Apache */
-    
+#endif
     ap_snprintf(port, sizeof(port), "%d", ntohs(c->remote_addr.sin_port));
     table_set (e, "REMOTE_PORT", port);            /* Apache */
 




Mime
View raw message