Skip to contentSkip to conversation

sigfd: use pthread_sigmask

PATCH Applied Alexander Graf 6 participants 7 messages Jun 8, 2011 – Jun 10, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sigfd: use pthread_sigmask

Qemu uses signalfd to figure out, if a signal occured without the need to actually receive the signal. Instead, it can read from the fd to receive its news.

Now, we obviously don't always have signalfd around. Especially not on non-Linux systems. So what we do there is that we create a new thread, block that thread on all signals and simply call sigwait to wait for a signal we're interested in to occur.

This all sounds great, but what we're really doing is:

    sigset_t all;

    sigfillset(&all);
    sigprocmask(SIG_BLOCK, &all, NULL);

which - on Darwin - blocks all signals on the current _process_, not only on the current thread. To block signals on the thread, we can use pthread_sigmask().

This patch does that, assuming that my above analysis is correct, and thus renders Qemu useable on Darwin again.

---
 compatfd.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
compatfd.c +1 -1
index bd377c4..41586ce 100644
@@ -29,7 +29,7 @@ static void *sigwait_compat(void *opaque)
     sigset_t all;
 
     sigfillset(&all);
-    sigprocmask(SIG_BLOCK, &all, NULL);
+    pthread_sigmask(SIG_BLOCK, &all, NULL);
 
     while (1) {
         int sig;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 16 lines · Alexander Graf

Qemu uses signalfd to figure out, if a signal occured without the need to actually receive the signal. Instead, it can read from the fd to receive its news.

Now, we obviously don't always have signalfd around. Especially not on non-Linux systems. So what we do there is that we create a new thread, block that thread on all signals and simply call sigwait to wait for a signal we're interested in to occur.

This all sounds great, but what we're really doing is:

   sigset_t all;

   sigfillset(&all);
   sigprocmask(SIG_BLOCK, &all, NULL);

Quoted 6 lines

which - on Darwin - blocks all signals on the current _process_, not only on the current thread. To block signals on the thread, we can use pthread_sigmask().

This patch does that, assuming that my above analysis is correct, and thus renders Qemu useable on Darwin again.

I confirm that Qemu works much better on Darwin with this patch :)

Thanks!
Alexandre

Acked-by on v1 1/1
#2 lore raw
In reply to Alexander Graf
Quoted 20 lines · Alexander Graf

Qemu uses signalfd to figure out, if a signal occured without the need to actually receive the signal. Instead, it can read from the fd to receive its news.

Now, we obviously don't always have signalfd around. Especially not on non-Linux systems. So what we do there is that we create a new thread, block that thread on all signals and simply call sigwait to wait for a signal we're interested in to occur.

This all sounds great, but what we're really doing is:

     sigset_t all;

     sigfillset(&all);
     sigprocmask(SIG_BLOCK,&all, NULL);

which - on Darwin - blocks all signals on the current_process_, not only on the current thread. To block signals on the thread, we can use pthread_sigmask().

Quoted 8 lines

This patch does that, assuming that my above analysis is correct, and thus renders Qemu useable on Darwin again.

Paolo

Acked-by on v1 1/1
#3 lore raw
In reply to Alexander Graf
Quoted 37 lines · Alexander Graf

Qemu uses signalfd to figure out, if a signal occured without the need to actually receive the signal. Instead, it can read from the fd to receive its news.

Now, we obviously don't always have signalfd around. Especially not on non-Linux systems. So what we do there is that we create a new thread, block that thread on all signals and simply call sigwait to wait for a signal we're interested in to occur.

This all sounds great, but what we're really doing is:

    sigset_t all;

    sigfillset(&all);
    sigprocmask(SIG_BLOCK, &all, NULL);

which - on Darwin - blocks all signals on the current _process_, not only on the current thread. To block signals on the thread, we can use pthread_sigmask().

This patch does that, assuming that my above analysis is correct, and thus renders Qemu useable on Darwin again.

---
 compatfd.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
compatfd.c +0 -0
index bd377c4..41586ce 100644

compatfd.c static void *sigwait_compat(void *opaque) · line 35

Quoted 8 lines
compatfd.c +1 -1
@@ -29,7 +29,7 @@ static void *sigwait_compat(void *opaque)
     sigset_t all;
 
     sigfillset(&all);
-    sigprocmask(SIG_BLOCK, &all, NULL);
+    pthread_sigmask(SIG_BLOCK, &all, NULL);
 
     while (1) {
         int sig;

Makes a lot of sense. And it also effects pre-signalfd Linux (<2.6.27).

#4 lore raw
In reply to Alexander Graf

Am 09.06.2011 um 00:55 schrieb Alexander Graf:

Quoted 20 lines

Qemu uses signalfd to figure out, if a signal occured without the need to actually receive the signal. Instead, it can read from the fd to receive its news.

Now, we obviously don't always have signalfd around. Especially not on non-Linux systems. So what we do there is that we create a new thread, block that thread on all signals and simply call sigwait to wait for a signal we're interested in to occur.

This all sounds great, but what we're really doing is:

   sigset_t all;

   sigfillset(&all);
   sigprocmask(SIG_BLOCK, &all, NULL);

which - on Darwin - blocks all signals on the current _process_, not only on the current thread. To block signals on the thread, we can use pthread_sigmask().

Quoted 8 lines

This patch does that, assuming that my above analysis is correct, and thus renders Qemu useable on Darwin again.

According to POSIX:2008, the use of sigprocmask() is only well-defined for a single-threaded process.

This patch fixed the default configuration (without --enable-io-thread) for me.

Thanks,
Andreas

Quoted 19 lines

---
compatfd.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
compatfd.c +1 -1
index bd377c4..41586ce 100644
@@ -29,7 +29,7 @@ static void *sigwait_compat(void *opaque)
    sigset_t all;
 
    sigfillset(&all);
-    sigprocmask(SIG_BLOCK, &all, NULL);
+    pthread_sigmask(SIG_BLOCK, &all, NULL);
 
    while (1) {
        int sig;
Signature · 1 line
1.7.1
#5 lore raw

Am 09.06.2011 um 14:36 schrieb Andreas Färber:

Quoted 25 lines

Am 09.06.2011 um 00:55 schrieb Alexander Graf:

Quoted 23 lines

Qemu uses signalfd to figure out, if a signal occured without the need to actually receive the signal. Instead, it can read from the fd to receive its news.

Now, we obviously don't always have signalfd around. Especially not on non-Linux systems. So what we do there is that we create a new thread, block that thread on all signals and simply call sigwait to wait for a signal we're interested in to occur.

This all sounds great, but what we're really doing is:

sigset_t all;

  sigfillset(&all);
  sigprocmask(SIG_BLOCK, &all, NULL);

which - on Darwin - blocks all signals on the current _process_, not only on the current thread. To block signals on the thread, we can use pthread_sigmask().

This patch does that, assuming that my above analysis is correct, and thus renders Qemu useable on Darwin again.

Quoted 7 lines
Quoted 5 lines

According to POSIX:2008, the use of sigprocmask() is only well-defined for a single-threaded process.

And of course I forgot:

Quoted 26 lines

This patch fixed the default configuration (without --enable-io-thread) for me.

Thanks,
Andreas

Quoted 19 lines

---
compatfd.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
compatfd.c +1 -1
index bd377c4..41586ce 100644
@@ -29,7 +29,7 @@ static void *sigwait_compat(void *opaque)
   sigset_t all;
 
   sigfillset(&all);
-    sigprocmask(SIG_BLOCK, &all, NULL);
+    pthread_sigmask(SIG_BLOCK, &all, NULL);
 
   while (1) {
       int sig;
Signature · 1 line
1.7.1
#6 lore raw
In reply to Alexander Graf
Quoted 16 lines · Alexander Graf

Qemu uses signalfd to figure out, if a signal occured without the need to actually receive the signal. Instead, it can read from the fd to receive its news.

Now, we obviously don't always have signalfd around. Especially not on non-Linux systems. So what we do there is that we create a new thread, block that thread on all signals and simply call sigwait to wait for a signal we're interested in to occur.

This all sounds great, but what we're really doing is:

    sigset_t all;

    sigfillset(&all);
    sigprocmask(SIG_BLOCK, &all, NULL);
Quoted 6 lines

which - on Darwin - blocks all signals on the current _process_, not only on the current thread. To block signals on the thread, we can use pthread_sigmask().

This patch does that, assuming that my above analysis is correct, and thus renders Qemu useable on Darwin again.

Applied, thanks all.

Cheers

Quoted 25 lines
---
 compatfd.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
compatfd.c +1 -1
index bd377c4..41586ce 100644
@@ -29,7 +29,7 @@ static void *sigwait_compat(void *opaque)
     sigset_t all;
 
     sigfillset(&all);
-    sigprocmask(SIG_BLOCK, &all, NULL);
+    pthread_sigmask(SIG_BLOCK, &all, NULL);
 
     while (1) {
         int sig;
Signature · 1 line
1.7.1