main-loop.c: Handle SIGINT, SIGHUP and SIGTERM synchronously
PATCH 1/1 main-loop.c: Handle SIGINT, SIGHUP and SIGTERM synchronously
Add the termination signals SIGINT, SIGHUP and SIGTERM to the list of signals which we handle synchronously via a signalfd. This avoids a race condition where if we took the SIGTERM in the middle of qemu_shutdown_requested:
int r = shutdown_requested;
[SIGTERM here...]
shutdown_requested = 0;then the setting of the shutdown_requested flag by termsig_handler() would be lost and QEMU would fail to shut down. This was causing 'make check' to hang occasionally.
--- main-loop.c | 3 +++ 1 file changed, 3 insertions(+)
main-loop.c +3 -0
@@ -84,6 +84,9 @@ static int qemu_signal_init(void)sigaddset (&set,SIGIO );sigaddset (&set,SIGALRM );sigaddset (&set,SIGBUS ); +sigaddset (&set,SIGINT ); +sigaddset (&set,SIGHUP ); +sigaddset (&set,SIGTERM );pthread_sigmask (SIG_BLOCK , &set,NULL );sigdelset (&set,SIG_IPI );
Signature · 1 line
1.9.1
Il 25/09/2014 17:51, Peter Maydell ha scritto:
Quoted 24 lines
Add the termination signals SIGINT, SIGHUP and SIGTERM to the list of signals which we handle synchronously via a signalfd. This avoids a race condition where if we took the SIGTERM in the middle of
qemu_shutdown_requested:int r = shutdown_requested; [SIGTERM here...] shutdown_requested = 0;then the setting of the
shutdown_requestedflag bytermsig_handler()would be lost and QEMU would fail to shut down. This was causing 'make check' to hang occasionally.Signed-off-by Peter Maydell <[email protected]>--- main-loop.c | 3 +++ 1 file changed, 3 insertions(+)main-loop.c +0
-0
main-loop.c static int qemu_signal_init(void) · line 92
Quoted 9 lines
main-loop.c +3
-0@@ -84,6 +84,9 @@ static int qemu_signal_init(void)sigaddset (&set,SIGIO );sigaddset (&set,SIGALRM );sigaddset (&set,SIGBUS ); +sigaddset (&set,SIGINT ); +sigaddset (&set,SIGHUP ); +sigaddset (&set,SIGTERM );pthread_sigmask (SIG_BLOCK , &set,NULL );sigdelset (&set,SIG_IPI );
Paolo
Quoted 8 lines · Peter Maydell
Add the termination signals SIGINT, SIGHUP and SIGTERM to the list of signals which we handle synchronously via a signalfd. This avoids a race condition where if we took the SIGTERM in the middle of
qemu_shutdown_requested:int r = shutdown_requested; [SIGTERM here...] shutdown_requested = 0;
Quoted 6 lines
then the setting of the
shutdown_requestedflag bytermsig_handler()would be lost and QEMU would fail to shut down. This was causing 'make check' to hang occasionally.Signed-off-by Peter Maydell <[email protected]>
<snip>
I've been testing it with my latest Travis patches (- the make check once patch) and it seems a lot better now:
Signature · 1 line
Alex Bennée
Quoted 17 lines · Alex Bennée
Quoted 8 lines · Peter Maydell
Add the termination signals SIGINT, SIGHUP and SIGTERM to the list of signals which we handle synchronously via a signalfd. This avoids a race condition where if we took the SIGTERM in the middle of
qemu_shutdown_requested:int r = shutdown_requested; [SIGTERM here...] shutdown_requested = 0;Quoted 6 lines
then the setting of the
shutdown_requestedflag bytermsig_handler()would be lost and QEMU would fail to shut down. This was causing 'make check' to hang occasionally.Signed-off-by Peter Maydell <[email protected]>
Quoted 7 lines
<snip>
I've been testing it with my latest Travis patches (- the make check once patch) and it seems a lot better now:
Reviewed-by Alex Bennée <[email protected]>Tested-by Alex Bennée <[email protected]>
Thanks; applied to master.
-- PMM
Hi,
Quoted 11 lines
Subject: [Qemu-devel] [PATCH]
main-loop.c: Handle SIGINT, SIGHUP and SIGTERM synchronouslyAdd the termination signals SIGINT, SIGHUP and SIGTERM to the list of signals which we handle synchronously via a signalfd. This avoids a race condition where if we took the SIGTERM in the middle of
qemu_shutdown_requested:int r = shutdown_requested; [SIGTERM here...] shutdown_requested = 0;
Quoted 5 lines
then the setting of the
shutdown_requestedflag bytermsig_handler()would be lost and QEMU would fail to shut down. This was causing 'make check' to hang occasionally.Signed-off-by Peter Maydell <[email protected]>
I met a really upset thing after this patch, which I can't using gdb debug Qemu process well. I use gdb attaching a Qemu process, and press 'c' to continue executing. When I want to set a breakpoint for debugging, then press 'ctrl + c', the Qemu will exit, because the SIGINT signal is captured by Qemu now. :(
What's your opinion? Thanks.
Best regards,
-Gonglei
Quoted 22 lines
--- main-loop.c | 3 +++ 1 file changed, 3 insertions(+)main-loop.c +3
-1@@ -84,6 +84,9 @@ static int qemu_signal_init(void)sigaddset (&set,SIGIO );sigaddset (&set,SIGALRM );sigaddset (&set,SIGBUS ); +sigaddset (&set,SIGINT ); +sigaddset (&set,SIGHUP ); +sigaddset (&set,SIGTERM );pthread_sigmask (SIG_BLOCK , &set,NULL );sigdelset (&set,SIG_IPI ); --1.9.1
Quoted 17 lines · Gonglei
Hi,
Quoted 15 lines
Subject: [Qemu-devel] [PATCH]
main-loop.c: Handle SIGINT, SIGHUP and SIGTERM synchronouslyAdd the termination signals SIGINT, SIGHUP and SIGTERM to the list of signals which we handle synchronously via a signalfd. This avoids a race condition where if we took the SIGTERM in the middle of
qemu_shutdown_requested:int r = shutdown_requested; [SIGTERM here...] shutdown_requested = 0;then the setting of the
shutdown_requestedflag bytermsig_handler()would be lost and QEMU would fail to shut down. This was causing 'make check' to hang occasionally.
Quoted 8 lines
Quoted 1 line
Signed-off-by Peter Maydell <[email protected]>I met a really upset thing after this patch, which I can't using gdb debug Qemu process well. I use gdb attaching a Qemu process, and press 'c' to continue executing. When I want to set a breakpoint for debugging, then press 'ctrl + c', the Qemu will exit, because the SIGINT signal is captured by Qemu now. :(
What's your opinion? Thanks.
Confirmed, you cannot interrupt a running qemu from gdb anymore.
I think this patch has to be reverted and the original issue fixed by making qemu_shutdown_requested signal-safe. Should be simple, just convert shutdown_requested into a counter. Need not be atomic, all happens over the main thread anyway.
Jan