[5055] Handle terminating signals (Gerd Hoffmann)
Revision: 5055
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5055 Author: aliguori Date: 2008-08-21 20:08:03 +0000 (Thu, 21 Aug 2008)
Log Message:
-----------
Handle terminating signals (Gerd Hoffmann)
This patch makes qemu handle signals better. It sets the request_shutdown flag, making the main_loop exit and qemu taking the usual exit route, with atexit handlers being called and so on, instead of qemu just being killed by the signal.
To avoid calling vm_start() from the signal handler main_loop() got an additional check so qemu_system_shutdown_request() works even when the vm is in stopped state.
Modified Paths:
--------------
trunk/curses.c
trunk/sdl.c
trunk/vl.c
Modified: trunk/curses.c
===================================================================
curses.c +0 -2
@@ -350,8 +350,6 @@atexit (curses_atexit);#ifndef _WIN32 -signal (SIGINT ,SIG_DFL ); -signal (SIGQUIT ,SIG_DFL );#if defined(SIGWINCH ) && defined(KEY_RESIZE )/* some curses implementations provide a handler, but we * want to be sure this is handled regardless of the library */
Modified: trunk/sdl.c
===================================================================
sdl.c +1 -8
@@ -476,10 +476,8 @@sdl_process_key (&ev->key);break ;case SDL_QUIT : -if (!no_quit) { +if (!no_quit)qemu_system_shutdown_request (); -vm_start ();/* In case we're paused */ - }break ;case SDL_MOUSEMOTION : if (gui_grab || kbd_mouse_is_absolute() ||
@@ -636,11 +634,6 @@fprintf (stderr,"Could not initialize SDL - exiting\n" );exit (1 ); } -#ifndef _WIN32 -/* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */ -signal (SIGINT ,SIG_DFL ); -signal (SIGQUIT ,SIG_DFL ); -#endif ds->dpy_update = sdl_update; ds->dpy_resize = sdl_resize;
Modified: trunk/vl.c
===================================================================
vl.c +27 -0
@@ -7621,6 +7621,8 @@ timeout =0 ; } }else { +if (shutdown_requested) +break ; timeout =10 ; }#ifdef CONFIG_PROFILER
@@ -8185,6 +8187,26 @@#define MAX_NET_CLIENTS 32 +#ifndef _WIN32 + +static void termsig_handler (int signal) +{ +qemu_system_shutdown_request (); +} + +void termsig_setup (void ) +{ +struct sigaction act; + +memset (&act,0 ,sizeof (act)); + act.sa_handler = termsig_handler; +sigaction (SIGINT , &act,NULL ); +sigaction (SIGHUP , &act,NULL ); +sigaction (SIGTERM , &act,NULL ); +} + +#endif +int main (int argc,char **argv) {#ifdef CONFIG_GDBSTUB
@@ -9073,6 +9095,11 @@#endif } +#ifndef _WIN32 +/* must be after terminal init, SDL library changes signal handlers */ +termsig_setup (); +#endif +/* Maintain compatibility with multiple stdio monitors */ if (!strcmp (monitor_device,"stdio" )) {for (i =0 ; i <MAX_SERIAL_PORTS ; i++) {
Quoted 21 lines · Anthony Liguori
Revision: 5055
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5055 Author: aliguori Date: 2008-08-21 20:08:03 +0000 (Thu, 21 Aug 2008)Log Message:
-----------
Handle terminating signals (Gerd Hoffmann)This patch makes qemu handle signals better. It sets the
request_shutdownflag, making themain_loopexit and qemu taking the usual exit route, with atexit handlers being called and so on, instead of qemu just being killed by the signal.To avoid calling
vm_start()from the signal handlermain_loop()got an additional check soqemu_system_shutdown_request()works even when the vm is in stopped state.Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Anthony Liguori <[email protected]>
...
vl.c line 7628
Quoted 13 lines
Modified:
trunk/vl.c
===================================================================vl.c +2
-0@@ -7621,6 +7621,8 @@ timeout =0 ; } }else { +if (shutdown_requested) +break ; timeout =10 ; }#ifdef CONFIG_PROFILER
Could we define the policy that no patch is merged which introduces new compiler warnings? Fix below remove the one caused by the hunk above, but it still leaves some doubts for the semi-informed reader because the "if (shutdown_requested)" block under vm_running also checks for no_shutdown. Please confirm that leaving it out here was by intention.
Jan
--------
Always return EXCP_INTERRUPT when leaving main_loop due to shutdown_requested.
--- vl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
vl.c +3 -1
@@ -7624,8 +7624,10 @@ static int main_loop(void) timeout =0 ; } }else { -if (shutdown_requested) +if (shutdown_requested) { + ret =EXCP_INTERRUPT ;break ; + } timeout =10 ; }#ifdef CONFIG_PROFILER
Hi,
Quoted 7 lines
Review
Quoted 4 lines
} else {(quoted diff) +2
-0+ if (shutdown_requested) + break; timeout = 10;Could we define the policy that no patch is merged which introduces new compiler warnings?
Just double-checked. I don't get a warning for some strange reason. Was wondered how a warning bypassed my attention.
You probably see "ret can be used uninitialized ...", right?
vl.c static int main_loop(void) · line 7630
Quoted 11 lines
vl.c +3
-1@@ -7624,8 +7624,10 @@ static int main_loop(void) timeout =0 ; } }else { -if (shutdown_requested) +if (shutdown_requested) { + ret =EXCP_INTERRUPT ;break ; + }
Fix looks fine to me.
cheers,
Gerd
Signature · 1 line
http://kraxel.fedorapeople.org/xenner/
Quoted 7 lines · Gerd Hoffmann
Hi,
Quoted 4 lines
Quoted 4 lines
} else {(quoted diff) +2
-0+ if (shutdown_requested) + break; timeout = 10;
Quoted 5 lines
Quoted 2 lines
Could we define the policy that no patch is merged which introduces new compiler warnings?
Just double-checked. I don't get a warning for some strange reason. Was wondered how a warning bypassed my attention.
I like colorgcc for this a lot (either distcc or icecream is said to support this as well). :)
Quoted 2 lines
You probably see "ret can be used uninitialized ...", right?
Yep. Are you compiling qemu with gcc-3.3 (here: 3.3.3 hammer, x86_64 host)?
Quoted 14 lines
vl.c static int main_loop(void) · line 7630
Quoted 12 lines
vl.c +3
-1@@ -7624,8 +7624,10 @@ static int main_loop(void) timeout =0 ; } }else { -if (shutdown_requested) +if (shutdown_requested) { + ret =EXCP_INTERRUPT ;break ; + }Fix looks fine to me.
So we don't need to bother about no_shutdown in this path?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Quoted 5 lines · Jan Kiszka
Quoted 2 lines
Just double-checked. I don't get a warning for some strange reason. Was wondered how a warning bypassed my attention.
I like colorgcc for this a lot (either distcc or icecream is said to support this as well). :)
emacs does this too, and it even beams the cursor to the line in question. Assuming there is a warning in the first place.
Quoted 3 lines
Quoted 1 line
You probably see "ret can be used uninitialized ...", right?
Yep. Are you compiling qemu with gcc-3.3 (here: 3.3.3 hammer,
x86_64host)?
compat-gcc-34 package here, --version says:
gcc34 (GCC) 3.4.6 20060404 (Red Hat 3.4.6-9)
Quoted 14 lines
Quoted 13 lines
vl.c static int main_loop(void) · line 7630
Quoted 12 lines
vl.c +3
-1@@ -7624,8 +7624,10 @@ static int main_loop(void) timeout =0 ; } }else { -if (shutdown_requested) +if (shutdown_requested) { + ret =EXCP_INTERRUPT ;break ; + }Fix looks fine to me.
Quoted 1 line
So we don't need to bother about
no_shutdownin this path?
I don't think so. The no_shutdown makes qemu stop the vm instead of exiting instantly, probably to allow analyzing the situation in case of a guest-triggered shutdown. There is no point in doing so in case the vm already is in stopped state.
cheers,
Gerd
Signature · 1 line
http://kraxel.fedorapeople.org/xenner/
Quoted 6 lines · Jan Kiszka
Could we define the policy that no patch is merged which introduces new compiler warnings? Fix below remove the one caused by the hunk above, but it still leaves some doubts for the semi-informed reader because the "if (
shutdown_requested)" block undervm_runningalso checks forno_shutdown. Please confirm that leaving it out here was by intention.
I do check for warnings. The version of GCC I'm using (3.4.6 20060404 (Red Hat 3.4.6-9)) does not complain about these things. We probably should add -Wall to the build and take the time to fix up all of the warnings that occur.
Regards,
Anthony Liguori
Quoted 31 lines
Jan
--------
Always return
EXCP_INTERRUPTwhen leavingmain_loopdue toshutdown_requested.Signed-off-by Jan Kiszka <[email protected]>--- vl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Index:
b/vl.c
===================================================================vl.c +3
-1@@ -7624,8 +7624,10 @@ static int main_loop(void) timeout =0 ; } }else { -if (shutdown_requested) +if (shutdown_requested) { + ret =EXCP_INTERRUPT ;break ; + } timeout =10 ; }#ifdef CONFIG_PROFILER
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Jan Kiszka
Could we define the policy that no patch is merged which introduces new compiler warnings? Fix below remove the one caused by the hunk above, but it still leaves some doubts for the semi-informed reader because the "if (
shutdown_requested)" block undervm_runningalso checks forno_shutdown. Please confirm that leaving it out here was by intention.
Quoted 4 lines
I do check for warnings. The version of GCC I'm using (3.4.6 20060404 (Red Hat 3.4.6-9)) does not complain about these things. We probably should add -Wall to the build and take the time to fix up all of the warnings that occur.
Makes /me wonder why 3.4 thinks there is no problem here (while this is obviously wrong).
Being lazy and SuSE-based (which only provides a 3.3.3 for such legacy use cases, IIRC), and also remembering vaguely that there used to be warnings about 3.4 /wrt qemu, I kept 3.3.3.
BTW, do you also check for 64-bit issues? My feeling is that this - at least - used to be a rare host platform for qemu contributors.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Quoted 12 lines · Gerd Hoffmann
Quoted 12 lines
Quoted 12 lines
vl.c static int main_loop(void) · line 7630
Quoted 11 lines
vl.c +3
-1@@ -7624,8 +7624,10 @@ static int main_loop(void) timeout =0 ; } }else { -if (shutdown_requested) +if (shutdown_requested) { + ret =EXCP_INTERRUPT ;break ; + }Fix looks fine to me.
Quoted 6 lines
Quoted 1 line
So we don't need to bother about
no_shutdownin this path?I don't think so. The
no_shutdownmakes qemu stop the vm instead of exiting instantly, probably to allow analyzing the situation in case of a guest-triggered shutdown. There is no point in doing so in case the vm already is in stopped state.
OK, makes sense.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Quoted 8 lines · Jan Kiszka
Quoted 5 lines · Anthony Liguori
I do check for warnings. The version of GCC I'm using (3.4.6 20060404 (Red Hat 3.4.6-9)) does not complain about these things. We probably should add -Wall to the build and take the time to fix up all of the warnings that occur.
Quoted 7 lines
Makes /me wonder why 3.4 thinks there is no problem here (while this is obviously wrong).
Being lazy and SuSE-based (which only provides a 3.3.3 for such legacy use cases, IIRC), and also remembering vaguely that there used to be warnings about 3.4 /wrt qemu, I kept 3.3.3.
Could just be that more warnings are enabled by default with your particular version of GCC.
Quoted 3 lines
BTW, do you also check for 64-bit issues? My feeling is that this - at least - used to be a rare host platform for qemu contributors.
I run a 64-bit host.
I run Fedora 9 x86_64. I have as many optional libraries installed as possible. I also have a mingw32 cross compiler setup that I use to test the windows build. The mingw32 compiler is gcc4 and throws an awful lot of warnings.
Regards,
Anthony Liguori
Quoted 3 lines
Jan
Quoted 63 lines · Jan Kiszka
Quoted 21 lines · Anthony Liguori
Revision: 5055
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5055 Author: aliguori Date: 2008-08-21 20:08:03 +0000 (Thu, 21 Aug 2008)Log Message:
-----------
Handle terminating signals (Gerd Hoffmann)This patch makes qemu handle signals better. It sets the
request_shutdownflag, making themain_loopexit and qemu taking the usual exit route, with atexit handlers being called and so on, instead of qemu just being killed by the signal.To avoid calling
vm_start()from the signal handlermain_loop()got an additional check soqemu_system_shutdown_request()works even when the vm is in stopped state.Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Anthony Liguori <[email protected]>...
vl.c line 7628
Quoted 13 lines
Modified:
trunk/vl.c
===================================================================vl.c +2
-0@@ -7621,6 +7621,8 @@ timeout =0 ; } }else { +if (shutdown_requested) +break ; timeout =10 ; }#ifdef CONFIG_PROFILER Could we define the policy that no patch is merged which introduces new compiler warnings? Fix below remove the one caused by the hunk above, but it still leaves some doubts for the semi-informed reader because the "if (
shutdown_requested)" block undervm_runningalso checks forno_shutdown. Please confirm that leaving it out here was by intention.Jan
--------
Always return
EXCP_INTERRUPTwhen leavingmain_loopdue toshutdown_requested.Signed-off-by Jan Kiszka <[email protected]>--- vl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Index:
b/vl.c
===================================================================vl.c +0
-0@@ -7624,8 +7624,10 @@ static int main_loop(void) timeout =0 ;
vl.c static int main_loop(void) · line 7633
Quoted 10 lines
vl.c +3
-1} }else { -if (shutdown_requested) +if (shutdown_requested) { + ret =EXCP_INTERRUPT ;break ; + } timeout =10 ; }#ifdef CONFIG_PROFILER
After discussing how this issue slipped in, I think it was forgotten to actually merge the fix... :->
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux