[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 17/17] linux-user: Proper exit code for uncaught sig
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PATCH 17/17] linux-user: Proper exit code for uncaught signals |
Date: |
Tue, 31 Mar 2009 23:40:49 +0300 |
From: Riku Voipio <address@hidden>
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 <address@hidden>
---
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 fc37dc1..7504725 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
--
1.6.2.1
- [Qemu-devel] [PATCH 04/17] Implement sem* syscalls, (continued)
- [Qemu-devel] [PATCH 04/17] Implement sem* syscalls, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 02/17] Rewrite mmap_find_vma() to work fine on 64-bit hosts with 32-bit targets, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 15/17] linux-user: removed unnecessary MAX_SOCK_ADDR checks for socket syscalls, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 08/17] Added posix message queue syscalls except mq_notify, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 10/17] More strace formatting for posix message queues syscalls, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 09/17] Format mq_open strace arguments, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 11/17] Add support for passing contents of argv0, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 14/17] Revived GUEST_BASE support for usermode emulation targets., riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 16/17] Prefer glibc over direct syscalls, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 17/17] linux-user: Proper exit code for uncaught signals,
riku . voipio <=
- [Qemu-devel] [PATCH 07/17] shmat(): use mmap_find_vma to find free memory area, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 03/17] Fix and cleanup IPCOP_sem* ipc calls handling, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 12/17] linux-user: unix sockets - fix running dbus, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 06/17] Implement shm* syscalls, riku . voipio, 2009/03/31
- [Qemu-devel] [PATCH 13/17] Strace is now working again with GUEST_BASE support., riku . voipio, 2009/03/31
- Re: [Qemu-devel] [PATCH 00/17] linux-user patches in maemo, Paul Brook, 2009/03/31