diff options
author | aurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-04-15 16:18:38 +0000 |
---|---|---|
committer | aurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-04-15 16:18:38 +0000 |
commit | 603e4fd7b1e034f79181a53df9719818f80ba364 (patch) | |
tree | 3e1f011d9dfed361b8df1c972963c52382beee31 /linux-user | |
parent | 3b3f24add09f8ab720860d4840f9755c102121b5 (diff) |
linux-user: proper exit code for uncaught signals
The proper exit code for dieing from an uncaught signal is -<signal>.
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 <riku.voipio@iki.fi>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7119 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'linux-user')
-rw-r--r-- | 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 fc37dc11ff..75047251bb 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -25,6 +25,7 @@ #include <unistd.h> #include <signal.h> #include <errno.h> +#include <assert.h> #include <sys/ucontext.h> #include "qemu.h" @@ -352,22 +353,34 @@ static inline void free_sigqueue(CPUState *env, struct sigqueue *q) 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 + * -<signal>. 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 |