From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J2XXT-0001lw-RO for qemu-devel@nongnu.org; Wed, 12 Dec 2007 14:46:39 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J2XXP-0001jG-Bg for qemu-devel@nongnu.org; Wed, 12 Dec 2007 14:46:39 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J2XXO-0001iu-T4 for qemu-devel@nongnu.org; Wed, 12 Dec 2007 14:46:34 -0500 Received: from owa.c2.net ([207.235.78.2] helo=email.c2.net) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1J2XXN-0007oN-DN for qemu-devel@nongnu.org; Wed, 12 Dec 2007 14:46:34 -0500 From: Thayne Harbaugh Content-Type: multipart/mixed; boundary="=-kvyLwSPgxv7leN5Hnm6f" Date: Wed, 12 Dec 2007 12:37:38 -0700 Message-Id: <1197488258.2947.126.camel@phantasm.home.enterpriseandprosperity.com> Mime-Version: 1.0 Subject: [Qemu-devel] [BUG][PATCH] signal termination (48_signal_terminate.patch) Reply-To: thayne@c2.net, qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --=-kvyLwSPgxv7leN5Hnm6f Content-Type: text/plain Content-Transfer-Encoding: 7bit Qemu doesn't exit with the proper code when dieing from an uncaught signal. Exit codes for uncaught signals are -. Unfortunately the kernel filters values from exit() and _exit(). A solution is to actually die from an uncaught signal. This patch detects an uncaught signal, installs the default handler, and then sends itself the signal and waits for it. It depends on the previous 48_signal_xlate.patch that I sent. --=-kvyLwSPgxv7leN5Hnm6f Content-Disposition: attachment; filename=48_signal_terminate.patch Content-Type: text/x-patch; name=48_signal_terminate.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit Index: qemu/linux-user/signal.c =================================================================== --- qemu.orig/linux-user/signal.c 2007-12-12 11:17:26.000000000 -0700 +++ qemu/linux-user/signal.c 2007-12-12 11:26:42.000000000 -0700 @@ -330,20 +330,31 @@ { int host_sig; host_sig = target_to_host_signal(target_sig); + struct sigaction act; fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n", target_sig, strsignal(host_sig)); -#if 1 - _exit(-host_sig); -#else - { - struct sigaction act; - sigemptyset(&act.sa_mask); - act.sa_flags = SA_SIGINFO; - act.sa_sigaction = SIG_DFL; - sigaction(SIGABRT, &act, NULL); - abort(); - } -#endif + + /* The proper exit code for dieing from an uncaught signal is + * -. The kernel doesn't allow exit() or _exit() to pass + * a negative value. To get the proper exit code we need to + * actually die from an uncaught signal. Here the default signal + * handler is installed, we send ourself a signal and we wait for + * it to arrive. */ + sigfillset(&act.sa_mask); + act.sa_handler = SIG_DFL; + sigaction(host_sig, &act, NULL); + + /* For some reason raise(host_sig) doesn't send the signal when + * statically linked on x86-64. */ + kill(getpid(), host_sig); + + /* Make sure the signal isn't masked (just reuse the mask inside + of act) */ + sigdelset(&act.sa_mask, host_sig); + sigsuspend(&act.sa_mask); + + /* unreachable */ + assert(0); } /* queue a target signal so that it will be sent to the virtual CPU as --=-kvyLwSPgxv7leN5Hnm6f--