From: Thayne Harbaugh <thayne@c2.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [BUG][PATCH] signal termination (48_signal_terminate.patch)
Date: Wed, 12 Dec 2007 12:37:38 -0700 [thread overview]
Message-ID: <1197488258.2947.126.camel@phantasm.home.enterpriseandprosperity.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 430 bytes --]
Qemu doesn't exit with the proper code when dieing from an uncaught
signal. Exit codes for uncaught signals are -<signum>. 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.
[-- Attachment #2: 48_signal_terminate.patch --]
[-- Type: text/x-patch, Size: 1627 bytes --]
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
+ * -<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 target signal so that it will be sent to the virtual CPU as
reply other threads:[~2007-12-12 19:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1197488258.2947.126.camel@phantasm.home.enterpriseandprosperity.com \
--to=thayne@c2.net \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).