diff mbox

[PATCHv3] report that QEMU process was killed by a signal

Message ID 20110330190433.GE7741@redhat.com
State New
Headers show

Commit Message

Gleb Natapov March 30, 2011, 7:04 p.m. UTC
On Wed, Mar 30, 2011 at 07:53:41PM +0100, Peter Maydell wrote:
> On 30 March 2011 19:43, Gleb Natapov <gleb@redhat.com> wrote:
> > On Wed, Mar 30, 2011 at 07:39:31PM +0100, Peter Maydell wrote:
> >> Unfortunately this patch causes qemu to segfault when killed
> >> via ^C (at least on my Ubuntu maverick system). This is because
> >> it registers a signal handler with sigaction, but then later
> >> the SDL library is initialised and it reinstalls our handler
> >> with plain old signal:
> >>
> >>         ohandler = signal(SIGINT, SDL_HandleSIG);
> >>         if ( ohandler != SIG_DFL )
> >>                 signal(SIGINT, ohandler);
> >>
> > I fixed this in SDL upstream.
> 
> Cool, but we can't rely on the SDL we're linked against being
> a bugfixed version.
> 
> >> This is clearly buggy but on the other hand SDL is pretty widely
> >> deployed and it's the default QEMU video output method, so I think
> >> we need to work around it :-(
> >>
> >> The most straightforward fix is to get the signal number from
> >> argument one and not to bother printing the PID that killed us.
> >>
> > For debugging purposes pid is useful. We cam register signal handler
> > after SDL is initialized though (if waiting for SDL update is not an
> > option).
> 
> I'm not convinced about the utility of printing the pid, personally.
> Most programs get along fine without printing anything when
> they receive a terminal signal. However you're right that it should
Well qemu is a bit of special case. It is long running process that
takes huge amount of memory and, as suchm it becomes a target of various
monitoring script which, when configured incorrectly, start killing
perfectly valid guests. In addition killing of the guest looks exactly
like guest shutdown to management software because we call shutdow_request
in the signal handler.

> be straightforward enough to move the signal init. In fact it
> looks like this got broken somewhere along the line, the
> call to os_setup_signal_handling() is already preceded with a comment:
> 
>     /* must be after terminal init, SDL library changes signal handlers */
>     os_setup_signal_handling();
> 
> ...we just aren't actually after the terminal init any more :-(
> 
Exactly. This should do the trick (not tested).



--
			Gleb.

Comments

Peter Maydell March 30, 2011, 8:51 p.m. UTC | #1
2011/3/30 Gleb Natapov <gleb@redhat.com>:
> On Wed, Mar 30, 2011 at 07:53:41PM +0100, Peter Maydell wrote:
>> I'm not convinced about the utility of printing the pid, personally.
>> Most programs get along fine without printing anything when
>> they receive a terminal signal.

> Well qemu is a bit of special case. It is long running process that
> takes huge amount of memory and, as suchm it becomes a target of various
> monitoring script which, when configured incorrectly, start killing
> perfectly valid guests. In addition killing of the guest looks exactly
> like guest shutdown to management software because we call shutdow_request
> in the signal handler.

That sounds like a flaw in the communication protocol between
qemu and the management software, which would be better fixed
by having qemu communicate the reason for exit directly (ie
not just by printing to stderr), surely?

> Exactly. This should do the trick (not tested).

Looks good, and a test shows I don't get the segfault any more.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

although I guess you'll want to submit it with a sensible git
commit message :-)

-- PMM
Gleb Natapov March 31, 2011, 9:04 a.m. UTC | #2
On Wed, Mar 30, 2011 at 09:51:29PM +0100, Peter Maydell wrote:
> 2011/3/30 Gleb Natapov <gleb@redhat.com>:
> > On Wed, Mar 30, 2011 at 07:53:41PM +0100, Peter Maydell wrote:
> >> I'm not convinced about the utility of printing the pid, personally.
> >> Most programs get along fine without printing anything when
> >> they receive a terminal signal.
> 
> > Well qemu is a bit of special case. It is long running process that
> > takes huge amount of memory and, as suchm it becomes a target of various
> > monitoring script which, when configured incorrectly, start killing
> > perfectly valid guests. In addition killing of the guest looks exactly
> > like guest shutdown to management software because we call shutdow_request
> > in the signal handler.
> 
> That sounds like a flaw in the communication protocol between
> qemu and the management software, which would be better fixed
> by having qemu communicate the reason for exit directly (ie
> not just by printing to stderr), surely?
> 
Yes, but this is more complex and changes QMP protocol.

> > Exactly. This should do the trick (not tested).
> 
> Looks good, and a test shows I don't get the segfault any more.
> 
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> 
> although I guess you'll want to submit it with a sensible git
> commit message :-)
> 
Will do.

--
			Gleb.
diff mbox

Patch

diff --git a/vl.c b/vl.c
index 192a240..93aaccf 100644
--- a/vl.c
+++ b/vl.c
@@ -3148,9 +3148,6 @@  int main(int argc, char **argv, char **envp)
 
     cpu_synchronize_all_post_init();
 
-    /* must be after terminal init, SDL library changes signal handlers */
-    os_setup_signal_handling();
-
     set_numa_modes();
 
     current_machine = machine;
@@ -3206,6 +3203,9 @@  int main(int argc, char **argv, char **envp)
         break;
     }
 
+    /* must be after terminal init, SDL library changes signal handlers */
+    os_setup_signal_handling();
+
 #ifdef CONFIG_VNC
     /* init remote displays */
     if (vnc_display) {