From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L5fGY-0001N6-TM for qemu-devel@nongnu.org; Thu, 27 Nov 2008 06:42:38 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L5fGX-0001LQ-GS for qemu-devel@nongnu.org; Thu, 27 Nov 2008 06:42:38 -0500 Received: from [199.232.76.173] (port=56396 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5fGX-0001L7-7G for qemu-devel@nongnu.org; Thu, 27 Nov 2008 06:42:37 -0500 Received: from relay01.mx.bawue.net ([193.7.176.67]:59909) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L5fGW-0005hn-KE for qemu-devel@nongnu.org; Thu, 27 Nov 2008 06:42:36 -0500 Date: Thu, 27 Nov 2008 12:42:33 +0100 From: Thiemo Seufer Subject: Re: [Qemu-devel] [PATCH] linux-user: Proper exit code for uncaught signals Message-ID: <20081127114233.GC15592@networkno.de> References: <20081123213724.GA15889@kos.to> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20081123213724.GA15889@kos.to> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Riku Voipio Cc: qemu-devel@nongnu.org Riku Voipio wrote: > 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 So, who holds the copyright (and deserves the credit)? Thiemo > Signed-off-by: Riku Voipio > --- > linux-user/signal.c | 37 +++++++++++++++++++++++++------------ > 1 files changed, 25 insertions(+), 12 deletions(-) > > diff --git a/linux-user/signal.c b/linux-user/signal.c > index e0f6aaf..dac9933 100644 > --- a/linux-user/signal.c > +++ b/linux-user/signal.c > @@ -24,6 +24,7 @@ > #include > #include > #include > +#include > #include > > #include "qemu.h" > @@ -328,21 +329,33 @@ static inline void free_sigqueue(CPUState *env, struct sigqueue *q) > static void __attribute((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 > - _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 > -- > 1.5.6.5 > > > -- > "rm -rf" only sounds scary if you don't have backups >