You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dean Gaudet <dg...@arctic.org> on 1997/11/04 08:15:47 UTC

[PATCH] RAISE_SIGSTOP

Frequently when I'm debugging things involving subprocesses I have to
recompile apache to stick in raise(SIGSTOP)s in the appropriate place so
that I can attach to a subprocess after a fork().  This patch adds a
conditional define DEBUG_SIGSTOP, which enables a command line parameter
"-Z N", where N is a bit field indicating after which fork()s apache
should raise(SIGSTOP).  The bits are defined in httpd.h. 

It doesn't have to go into 1.3, it's just more useful debugging stuff. 

Dean

Index: main/alloc.c
===================================================================
RCS file: /export/home/cvs/apachen/src/main/alloc.c,v
retrieving revision 1.56
diff -u -r1.56 alloc.c
--- alloc.c	1997/11/01 21:13:20	1.56
+++ alloc.c	1997/11/04 07:10:18
@@ -1361,6 +1361,7 @@
 
     if (!pid) {
 	/* Child process */
+	RAISE_SIGSTOP(SPAWN_CHILD);
 
 	if (pipe_out) {
 	    close(out_fds[0]);
Index: main/http_log.c
===================================================================
RCS file: /export/home/cvs/apachen/src/main/http_log.c,v
retrieving revision 1.42
diff -u -r1.42 http_log.c
--- http_log.c	1997/10/27 19:09:43	1.42
+++ http_log.c	1997/11/04 07:10:19
@@ -413,6 +413,7 @@
 	/* XXX: need to check what open fds the logger is actually passed,
 	 * XXX: and CGIs for that matter ... cleanup_for_exec *should*
 	 * XXX: close all the relevant stuff, but hey, it could be broken. */
+	RAISE_SIGSTOP(PIPED_LOG_SPAWN);
 	/* we're now in the child */
 	close (STDIN_FILENO);
 	dup2 (pl->fds[0], STDIN_FILENO);
Index: main/http_main.c
===================================================================
RCS file: /export/home/cvs/apachen/src/main/http_main.c,v
retrieving revision 1.243
diff -u -r1.243 http_main.c
--- http_main.c	1997/11/03 10:11:42	1.243
+++ http_main.c	1997/11/04 07:10:19
@@ -223,6 +223,10 @@
 
 int one_process = 0;
 
+#ifdef DEBUG_SIGSTOP
+int raise_sigstop_flags;
+#endif
+
 #ifndef NO_OTHER_CHILD
 /* used to maintain list of children which aren't part of the scoreboard */
 typedef struct other_child_rec other_child_rec;
@@ -2100,6 +2104,7 @@
 	fprintf(stderr, "httpd: unable to fork new process\n");
 	exit(1);
     }
+    RAISE_SIGSTOP(DETACH);
 #endif
 #ifndef NO_SETSID
     if ((pgrp = setsid()) == -1) {
@@ -2939,6 +2944,7 @@
     }
 
     if (!pid) {
+	RAISE_SIGSTOP(MAKE_CHILD);
 	/* Disable the restart signal handlers and enable the just_die stuff.
 	 * Note that since restart() just notes that a restart has been
 	 * requested there's no race condition here.
@@ -3380,7 +3386,7 @@
 
     setup_prelinked_modules();
 
-    while ((c = getopt(argc, argv, "Xd:f:vhl")) != -1) {
+    while ((c = getopt(argc, argv, "Xd:f:vhlZ:")) != -1) {
 	switch (c) {
 	case 'd':
 	    strncpy(server_root, optarg, sizeof(server_root) - 1);
@@ -3402,6 +3408,11 @@
 	case 'X':
 	    ++one_process;	/* Weird debugging mode. */
 	    break;
+#ifdef DEBUG_SIGSTOP
+	case 'Z':
+	    raise_sigstop_flags = atoi(optarg);
+	    break;
+#endif
 	case '?':
 	    usage(argv[0]);
 	}
Index: main/httpd.h
===================================================================
RCS file: /export/home/cvs/apachen/src/main/httpd.h,v
retrieving revision 1.165
diff -u -r1.165 httpd.h
--- httpd.h	1997/10/26 21:57:13	1.165
+++ httpd.h	1997/11/04 07:10:19
@@ -903,3 +903,23 @@
 #if !defined (MULTITHREAD) && (defined (HAVE_MMAP) || defined (HAVE_SHMGET))
 #define OPTIMIZE_TIMEOUTS
 #endif
+
+/* A set of flags which indicate places where the server should raise(SIGSTOP).
+ * This is useful for debugging, because you can then attach to that process
+ * with gdb and continue.  This is important in cases where one_process
+ * debugging isn't possible.
+ */
+#define SIGSTOP_DETACH			1
+#define SIGSTOP_MAKE_CHILD		2
+#define SIGSTOP_SPAWN_CHILD		4
+#define SIGSTOP_PIPED_LOG_SPAWN		8
+#define SIGSTOP_CGI_CHILD		16
+
+#ifdef DEBUG_SIGSTOP
+extern int raise_sigstop_flags;
+#define RAISE_SIGSTOP(x)	do { \
+	if (raise_sigstop_flags & SIGSTOP_##x) raise(SIGSTOP);\
+    } while (0)
+#else
+#define RAISE_SIGSTOP(x)       ((void)0)
+#endif
Index: modules/standard/mod_cgi.c
===================================================================
RCS file: /export/home/cvs/apachen/src/modules/standard/mod_cgi.c,v
retrieving revision 1.62
diff -u -r1.62 mod_cgi.c
--- mod_cgi.c	1997/10/25 22:35:18	1.62
+++ mod_cgi.c	1997/11/04 07:10:20
@@ -294,6 +294,7 @@
 
     char **env;
 
+    RAISE_SIGSTOP(CGI_CHILD);
 #ifdef DEBUG_CGI
     fprintf(dbg, "Attempting to exec %s as %sCGI child (argv0 = %s)\n",
 	    r->filename, nph ? "NPH " : "", argv0);



Re: [PATCH] RAISE_SIGSTOP

Posted by Martin Kraemer <Ma...@mch.sni.de>.
+1, but I think it should not officially documented...

    Martin
-- 
| S I E M E N S |  <Ma...@mch.sni.de>  |      Siemens Nixdorf
| ------------- |   Voice: +49-89-636-46021     |  Informationssysteme AG
| N I X D O R F |   FAX:   +49-89-636-44994     |   81730 Munich, Germany
~~~~~~~~~~~~~~~~My opinions only, of course; pgp key available on request