From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=54491 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q35kX-00032Q-1t for qemu-devel@nongnu.org; Fri, 25 Mar 2011 08:04:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q35kV-0005kl-MP for qemu-devel@nongnu.org; Fri, 25 Mar 2011 08:04:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58269) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q35kV-0005kV-Cc for qemu-devel@nongnu.org; Fri, 25 Mar 2011 08:04:15 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2PC4E10010681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 25 Mar 2011 08:04:14 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2PC4DSH012390 for ; Fri, 25 Mar 2011 08:04:14 -0400 Date: Fri, 25 Mar 2011 14:04:13 +0200 From: Gleb Natapov Subject: Re: [Qemu-devel] [PATCHv3] report that QEMU process was killed by a signal Message-ID: <20110325120413.GF14544@redhat.com> References: <20110315115604.GY10151@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110315115604.GY10151@redhat.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Ping? On Tue, Mar 15, 2011 at 01:56:04PM +0200, Gleb Natapov wrote: > Currently when rogue script kills QEMU process (using TERM/INT/HUP > signal) it looks indistinguishable from system shutdown. Lets report > that QEMU was killed and leave some clues about the killer identity. > > Signed-off-by: Gleb Natapov > --- > v1->v2: > - print message from a main loop instead of signal handler > v2->v3 > - use pid_t to store pid instead of int > > 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) > sigaction(SIGPIPE, &act, NULL); > } > > -static void termsig_handler(int signal) > +static void termsig_handler(int signal, siginfo_t *info, void *c) > { > - qemu_system_shutdown_request(); > + qemu_system_killed(info->si_signo, info->si_pid); > } > > static void sigchld_handler(int signal) > @@ -76,7 +76,8 @@ void os_setup_signal_handling(void) > struct sigaction act; > > memset(&act, 0, sizeof(act)); > - act.sa_handler = termsig_handler; > + act.sa_sigaction = termsig_handler; > + act.sa_flags = SA_SIGINFO; > sigaction(SIGINT, &act, NULL); > sigaction(SIGHUP, &act, NULL); > sigaction(SIGTERM, &act, NULL); > diff --git a/sysemu.h b/sysemu.h > index 0a83ab9..f868500 100644 > --- a/sysemu.h > +++ b/sysemu.h > @@ -66,6 +66,8 @@ void qemu_system_vmstop_request(int reason); > int qemu_shutdown_requested(void); > int qemu_reset_requested(void); > int qemu_powerdown_requested(void); > +void qemu_system_killed(int signal, pid_t pid); > +void qemu_kill_report(void); > extern qemu_irq qemu_system_powerdown; > void qemu_system_reset(void); > > diff --git a/vl.c b/vl.c > index 5e007a7..000c845 100644 > --- a/vl.c > +++ b/vl.c > @@ -1213,7 +1213,8 @@ typedef struct QEMUResetEntry { > static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = > QTAILQ_HEAD_INITIALIZER(reset_handlers); > static int reset_requested; > -static int shutdown_requested; > +static int shutdown_requested, shutdown_signal = -1; > +static pid_t shutdown_pid; > static int powerdown_requested; > static int debug_requested; > static int vmstop_requested; > @@ -1225,6 +1226,15 @@ int qemu_shutdown_requested(void) > return r; > } > > +void qemu_kill_report(void) > +{ > + if (shutdown_signal != -1) { > + fprintf(stderr, "Got signal %d from pid %d\n", > + shutdown_signal, shutdown_pid); > + shutdown_signal = -1; > + } > +} > + > int qemu_reset_requested(void) > { > int r = reset_requested; > @@ -1298,6 +1308,13 @@ void qemu_system_reset_request(void) > qemu_notify_event(); > } > > +void qemu_system_killed(int signal, pid_t pid) > +{ > + shutdown_signal = signal; > + shutdown_pid = pid; > + qemu_system_shutdown_request(); > +} > + > void qemu_system_shutdown_request(void) > { > shutdown_requested = 1; > @@ -1441,6 +1458,7 @@ static void main_loop(void) > vm_stop(VMSTOP_DEBUG); > } > if (qemu_shutdown_requested()) { > + qemu_kill_report(); > monitor_protocol_event(QEVENT_SHUTDOWN, NULL); > if (no_shutdown) { > vm_stop(VMSTOP_SHUTDOWN); > -- > Gleb. -- Gleb.