sigfd: use pthread_sigmask
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
@@ -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
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
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 usepthread_sigmask().
Quoted 8 lines
This patch does that, assuming that my above analysis is correct, and thus renders Qemu useable on Darwin again.
Reported-by Andreas Färber<[email protected]>CC Paolo Bonzini<[email protected]>CC Jan Kiszka<[email protected]>CC Anthony Liguori<[email protected]>Signed-off-by Alexander Graf<[email protected]>
Paolo
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.
Reported-by Andreas Färber <[email protected]>CC Paolo Bonzini <[email protected]>CC Jan Kiszka <[email protected]>CC Anthony Liguori <[email protected]>Signed-off-by Alexander Graf <[email protected]>--- compatfd.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)compatfd.c +0
-0
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).
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.
Reported-by Andreas Färber <[email protected]>CC Paolo Bonzini <[email protected]>CC Jan Kiszka <[email protected]>CC Anthony Liguori <[email protected]>Signed-off-by Alexander Graf <[email protected]>
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@@ -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
Andreas Färber
Acked-byAm 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_tall;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
Reported-by Andreas Färber <[email protected]>CC Paolo Bonzini <[email protected]>CC Jan Kiszka <[email protected]>CC Anthony Liguori <[email protected]>Signed-off-by Alexander Graf <[email protected]>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,
AndreasQuoted 19 lines
---
compatfd.c| 2 +-1 files changed, 1 insertions(+), 1 deletions(-)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;Signature · 1 line
1.7.1
Edgar E. Iglesias
AppliedQuoted 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
Reported-by Andreas Färber <[email protected]>CC Paolo Bonzini <[email protected]>CC Jan Kiszka <[email protected]>CC Anthony Liguori <[email protected]>Signed-off-by Alexander Graf <[email protected]>--- compatfd.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)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;Signature · 1 line
1.7.1