<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -497,7 +497,7 @@ private:
 	void shutdownServer() {
 		TRACE_POINT();
 		this_thread::disable_syscall_interruption dsi;
-		int ret;
+		int ret, status;
 		time_t begin;
 		bool done = false;
 		
@@ -516,21 +516,34 @@ private:
 			 * Some Apache modules fork(), but don't close file descriptors.
 			 * mod_wsgi is one such example. Because of that, closing serverSocket
 			 * won't always cause the ApplicationPool server to exit. So we send it a
+			 * signal. This must be the same as the oxt/system_calls.hpp interruption
 			 * signal.
 			 */
 			syscalls::kill(serverPid, SIGINT);
 			
-			ret = syscalls::waitpid(serverPid, NULL, WNOHANG);
+			ret = syscalls::waitpid(serverPid, &amp;status, WNOHANG);
 			done = ret &gt; 0 || ret == -1;
 			if (!done) {
 				syscalls::usleep(100000);
 			}
 		}
 		if (done) {
-			P_TRACE(2, &quot;ApplicationPoolServerExecutable exited.&quot;);
+			if (ret &gt; 0) {
+				if (WIFEXITED(status)) {
+					P_TRACE(2, &quot;ApplicationPoolServerExecutable exited with exit status &quot; &lt;&lt;
+						WEXITSTATUS(status) &lt;&lt; &quot;.&quot;);
+				} else if (WIFSIGNALED(status)) {
+					P_TRACE(2, &quot;ApplicationPoolServerExecutable exited because of signal &quot; &lt;&lt;
+						WTERMSIG(status) &lt;&lt; &quot;.&quot;);
+				} else {
+					P_TRACE(2, &quot;ApplicationPoolServerExecutable exited for an unknown reason.&quot;);
+				}
+			} else {
+				P_TRACE(2, &quot;ApplicationPoolServerExecutable exited.&quot;);
+			}
 		} else {
 			P_DEBUG(&quot;ApplicationPoolServerExecutable not exited in time. Killing it...&quot;);
-			syscalls::kill(serverPid, SIGTERM);
+			syscalls::kill(serverPid, SIGKILL);
 			syscalls::waitpid(serverPid, NULL, 0);
 		}
 		</diff>
      <filename>ext/apache2/ApplicationPoolServer.h</filename>
    </modified>
    <modified>
      <diff>@@ -196,29 +196,22 @@ private:
 	}
 	
 	static void fatalSignalHandler(int signum) {
-		static void (* const defaultHandler)(int) = SIG_DFL;
-		static bool calledBefore = false;
+		char message[1024];
 		
-		if (calledBefore) {
-			// If we're here then it means that this signal
-			// handler crashed, and we weren't even able to
-			// call write() or system()! Abort immediately:
-			defaultHandler(signum);
-		} else {
-			calledBefore = true;
-			write(STDERR_FILENO,
-				&quot;*** ERROR: ApplicationPoolServerExecutable received a &quot;
-				&quot;fatal signal. Running gdb to obtain the backtrace:\n\n&quot;,
-				sizeof(&quot;*** ERROR: ApplicationPoolServerExecutable received a &quot;
-				       &quot;fatal signal. Running gdb to obtain the backtrace:\n\n&quot;) - 1
-			);
-			write(STDERR_FILENO, &quot;----------------- Begin gdb output -----------------\n&quot;,
-				sizeof(&quot;----------------- Begin gdb output -----------------\n&quot;) - 1);
-			system(gdbBacktraceGenerationCommandStr);
-			write(STDERR_FILENO, &quot;----------------- End gdb output -----------------\n&quot;,
-				sizeof(&quot;----------------- End gdb output -----------------\n&quot;) - 1);
-			defaultHandler(signum);
-		}
+		snprintf(message, sizeof(message) - 1,
+			&quot;*** ERROR: ApplicationPoolServerExecutable received fatal signal &quot;
+			&quot;%d. Running gdb to obtain the backtrace:\n\n&quot;,
+			signum);
+		message[sizeof(message) - 1] = '\0';
+		write(STDERR_FILENO, message, strlen(message));
+		write(STDERR_FILENO, &quot;----------------- Begin gdb output -----------------\n&quot;,
+			sizeof(&quot;----------------- Begin gdb output -----------------\n&quot;) - 1);
+		system(gdbBacktraceGenerationCommandStr);
+		write(STDERR_FILENO, &quot;----------------- End gdb output -----------------\n&quot;,
+			sizeof(&quot;----------------- End gdb output -----------------\n&quot;) - 1);
+		
+		// Invoke default signal handler.
+		kill(getpid(), signum);
 	}
 	
 	void setupSignalHandlers() {
@@ -251,12 +244,17 @@ private:
 			
 			// Install the signal handlers.
 			action.sa_handler = fatalSignalHandler;
-			action.sa_flags   = 0;
+			action.sa_flags   = SA_RESETHAND;
 			sigemptyset(&amp;action.sa_mask);
-			sigaction(SIGSEGV, &amp;action, NULL);
+			sigaction(SIGQUIT, &amp;action, NULL);
+			sigaction(SIGILL,  &amp;action, NULL);
 			sigaction(SIGABRT, &amp;action, NULL);
-			sigaction(SIGILL, &amp;action, NULL);
-			sigaction(SIGFPE, &amp;action, NULL);
+			sigaction(SIGFPE,  &amp;action, NULL);
+			sigaction(SIGBUS,  &amp;action, NULL);
+			sigaction(SIGSEGV, &amp;action, NULL);
+			sigaction(SIGALRM, &amp;action, NULL);
+			sigaction(SIGUSR1, &amp;action, NULL);
+			sigaction(SIGUSR2, &amp;action, NULL);
 		}
 	}
 
@@ -274,6 +272,8 @@ public:
 		this-&gt;serverSocket = serverSocket;
 		this-&gt;statusReportFIFO = statusReportFIFO;
 		this-&gt;user = user;
+		
+		P_TRACE(2, &quot;ApplicationPoolServerExecutable initialized (PID &quot; &lt;&lt; getpid() &lt;&lt; &quot;)&quot;);
 	}
 	
 	~Server() {</diff>
      <filename>ext/apache2/ApplicationPoolServerExecutable.cpp</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>dabfdaf9c63911966d7e1f7f224bf71add82d1a9</id>
    </parent>
  </parents>
  <author>
    <name>Hongli Lai (Phusion)</name>
    <email>hongli@phusion.nl</email>
  </author>
  <url>http://github.com/FooBarWidget/passenger/commit/63951b1897010de31062f5a487e0ae568ec4de89</url>
  <id>63951b1897010de31062f5a487e0ae568ec4de89</id>
  <committed-date>2009-03-30T05:10:55-07:00</committed-date>
  <authored-date>2009-03-30T05:10:55-07:00</authored-date>
  <message>Improve fatal error handling.</message>
  <tree>c78fe200f59ea6f81f7b99c4370eca101a5d1f89</tree>
  <committer>
    <name>Hongli Lai (Phusion)</name>
    <email>hongli@phusion.nl</email>
  </committer>
</commit>
