From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=52027 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzDTD-0000GY-QJ for qemu-devel@nongnu.org; Mon, 14 Mar 2011 15:30:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzDT7-0005O8-KC for qemu-devel@nongnu.org; Mon, 14 Mar 2011 15:30:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13584) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzDT7-0005Nw-AX for qemu-devel@nongnu.org; Mon, 14 Mar 2011 15:30:17 -0400 Date: Mon, 14 Mar 2011 21:30:14 +0200 From: Gleb Natapov Subject: Re: [Qemu-devel] [PATCHv2] report that QEMU process was killed by a signal Message-ID: <20110314193014.GD15825@redhat.com> References: <20110314134459.GR10151@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel@nongnu.org On Mon, Mar 14, 2011 at 09:20:43PM +0200, Blue Swirl wrote: > On Mon, Mar 14, 2011 at 3:44 PM, Gleb Natapov wrote: > > Currently when rogue script kills QEMU process (using TERM/INT/HUP > > signal) it looks indistinguishable from system shutdown. Lets report > > that QMEU was killed and leave some clues about the killed identity. >=20 > QEMU ;-) >=20 Eah and second "killed" should be "killer". Why can't spell checker be smar= ter. > > > > Signed-off-by: Gleb Natapov > > --- > > =9Av1->v2: > > =9A- print message from a main loop instead of signal handler > > > > diff --git a/os-posix.c b/os-posix.c > > index 38c29d1..36d937c 100644 > > --- a/os-posix.c > > +++ b/os-posix.c > > @@ -61,9 +61,9 @@ void os_setup_early_signal_handling(void) > > =9A =9A sigaction(SIGPIPE, &act, NULL); > > =9A} > > > > -static void termsig_handler(int signal) > > +static void termsig_handler(int signal, siginfo_t *info, void *c) > > =9A{ > > - =9A =9Aqemu_system_shutdown_request(); > > + =9A =9Aqemu_system_killed(info->si_signo, info->si_pid); > > =9A} > > > > =9Astatic void sigchld_handler(int signal) > > @@ -76,7 +76,8 @@ void os_setup_signal_handling(void) > > =9A =9A struct sigaction act; > > > > =9A =9A memset(&act, 0, sizeof(act)); > > - =9A =9Aact.sa_handler =3D termsig_handler; > > + =9A =9Aact.sa_sigaction =3D termsig_handler; > > + =9A =9Aact.sa_flags =3D SA_SIGINFO; > > =9A =9A sigaction(SIGINT, =9A&act, NULL); > > =9A =9A sigaction(SIGHUP, =9A&act, NULL); > > =9A =9A sigaction(SIGTERM, &act, NULL); > > diff --git a/sysemu.h b/sysemu.h > > index 0a83ab9..fc7048a 100644 > > --- a/sysemu.h > > +++ b/sysemu.h > > @@ -66,6 +66,8 @@ void qemu_system_vmstop_request(int reason); > > =9Aint qemu_shutdown_requested(void); > > =9Aint qemu_reset_requested(void); > > =9Aint qemu_powerdown_requested(void); > > +void qemu_system_killed(int signal, int pid); >=20 > pid_t pid >=20 OK. > > +void qemu_kill_report(void); > > =9Aextern qemu_irq qemu_system_powerdown; > > =9Avoid qemu_system_reset(void); > > > > diff --git a/vl.c b/vl.c > > index 5e007a7..d14c42d 100644 > > --- a/vl.c > > +++ b/vl.c > > @@ -1213,7 +1213,7 @@ typedef struct QEMUResetEntry { > > =9Astatic QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =3D > > =9A =9A QTAILQ_HEAD_INITIALIZER(reset_handlers); > > =9Astatic int reset_requested; > > -static int shutdown_requested; > > +static int shutdown_requested, shutdown_signal =3D -1, shutdown_pid; >=20 > static pid_t shutdown_pid; >=20 > > =9Astatic int powerdown_requested; > > =9Astatic int debug_requested; > > =9Astatic int vmstop_requested; > > @@ -1225,6 +1225,15 @@ int qemu_shutdown_requested(void) > > =9A =9A return r; > > =9A} > > > > +void qemu_kill_report(void) > > +{ > > + =9A =9Aif (shutdown_signal !=3D -1) { > > + =9A =9A =9A =9Afprintf(stderr, "Got signal %d from pid %d\n", >=20 > Are there any systems with 64 bit pid_t? Then a cast may be needed > and/or format adjusted. >=20 Doubt there are any. > > + =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A shutdown_signal, shut= down_pid); > > + =9A =9A =9A =9Ashutdown_signal =3D -1; > > + =9A =9A} > > +} > > + > > =9Aint qemu_reset_requested(void) > > =9A{ > > =9A =9A int r =3D reset_requested; > > @@ -1298,6 +1307,13 @@ void qemu_system_reset_request(void) > > =9A =9A qemu_notify_event(); > > =9A} > > > > +void qemu_system_killed(int signal, int pid) >=20 > pid_t pid -- Gleb.