From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lu7ow-0004I5-Ij for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:18:42 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lu7ov-0004HP-O1 for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:18:41 -0400 Received: from [199.232.76.173] (port=51325 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lu7ou-0004HH-QG for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:18:40 -0400 Received: from savannah.gnu.org ([199.232.41.3]:38772 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lu7ou-0004KZ-AL for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:18:40 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Lu7ot-0000Ia-2b for qemu-devel@nongnu.org; Wed, 15 Apr 2009 16:18:39 +0000 Received: from aurel32 by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1Lu7os-0000IW-Me for qemu-devel@nongnu.org; Wed, 15 Apr 2009 16:18:38 +0000 MIME-Version: 1.0 Errors-To: aurel32 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Aurelien Jarno Message-Id: Date: Wed, 15 Apr 2009 16:18:38 +0000 Subject: [Qemu-devel] [7119] linux-user: proper exit code for uncaught signals Reply-To: 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 Revision: 7119 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7119 Author: aurel32 Date: 2009-04-15 16:18:38 +0000 (Wed, 15 Apr 2009) Log Message: ----------- linux-user: proper exit code for uncaught signals 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. A default signal handler is installed, we send ourself a signal and we wait for it to arrive. Patch originates from Scratchbox Signed-off-by: Riku Voipio Signed-off-by: Aurelien Jarno Modified Paths: -------------- trunk/linux-user/signal.c Modified: trunk/linux-user/signal.c =================================================================== --- trunk/linux-user/signal.c 2009-04-15 16:12:13 UTC (rev 7118) +++ trunk/linux-user/signal.c 2009-04-15 16:18:38 UTC (rev 7119) @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "qemu.h" @@ -352,22 +353,34 @@ static void QEMU_NORETURN force_sig(int sig) { int host_sig; + struct sigaction act; host_sig = target_to_host_signal(sig); fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n", sig, strsignal(host_sig)); -#if 1 gdb_signalled(thread_env, sig); - _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 signal so that it will be send to the virtual CPU as soon