qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 2/2] Signals: rework initial signal setup


From: Alexandre Raymond
Subject: [Qemu-devel] [RFC PATCH 2/2] Signals: rework initial signal setup
Date: Wed, 20 Jul 2011 01:01:30 -0400

-Restructure the signal setup by creating two groups:
  * blocked_set, which contains signals that are ignored by QEMU or caught
                 directly by a specific thread (e.g.: SIG_IPI).
  * handled_set, which contains signals handled synchronously via signalfd.

Signed-off-by: Alexandre Raymond <address@hidden>
---
 cpus.c |   41 +++++++++++++++++++++++------------------
 1 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/cpus.c b/cpus.c
index f466d95..565676a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -388,40 +388,45 @@ static void sigfd_handler(void *opaque)
 static int qemu_signal_init(void)
 {
     int sigfd;
-    sigset_t set;
+    /*
+     * - blocked_set contains signals that are handled directly by a specific
+     *   thread such as SIG_IPI, which is caught directly by the cpu thread.
+     * - handled_set contains signals that are handled synchronously via the
+     *   signal thread.
+     */
+    sigset_t blocked_set;
+    sigset_t handled_set;
 
-#ifdef CONFIG_IOTHREAD
+    sigemptyset(&blocked_set);
+    sigemptyset(&handled_set);
 
+    /* SIGUSR2 used by posix-aio-compat.c */
+    sigaddset(&handled_set, SIGUSR2);
+    sigaddset(&handled_set, SIGBUS);
+#ifdef CONFIG_IOTHREAD
     /*
      * SIG_IPI must be blocked in the main thread and must not be caught
      * by sigwait() in the signal thread. Otherwise, the cpu thread will
      * not catch it reliably.
      */
-    sigemptyset(&set);
-    sigaddset(&set, SIG_IPI);
-    pthread_sigmask(SIG_BLOCK, &set, NULL);
+    sigaddset(&blocked_set, SIG_IPI);
 
-    sigemptyset(&set);
-    sigaddset(&set, SIGUSR2);
-    sigaddset(&set, SIGIO);
-    sigaddset(&set, SIGALRM);
-    sigaddset(&set, SIGBUS);
+    sigaddset(&handled_set, SIGIO);
+    sigaddset(&handled_set, SIGALRM);
 #else
-    sigemptyset(&set);
-    sigaddset(&set, SIGUSR2);
-    sigaddset(&set, SIGBUS);
     if (kvm_enabled()) {
         /*
          * We need to process timer signals synchronously to avoid a race
          * between exit_request check and KVM vcpu entry.
          */
-        sigaddset(&set, SIGIO);
-        sigaddset(&set, SIGALRM);
+        sigaddset(&handled_set, SIGIO);
+        sigaddset(&handled_set, SIGALRM);
     }
 #endif
-    pthread_sigmask(SIG_BLOCK, &set, NULL);
+    pthread_sigmask(SIG_BLOCK, &blocked_set, NULL);
+    pthread_sigmask(SIG_BLOCK, &handled_set, NULL);
 
-    sigfd = qemu_signalfd(&set);
+    sigfd = qemu_signalfd(&handled_set);
     if (sigfd == -1) {
         fprintf(stderr, "failed to create signalfd\n");
         return -errno;
-- 
1.7.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]