Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 760

kvm-83-270.el5_11.src.rpm

From 5d9e07b0e681dd92a243969cc80d5dfd6e712bae Mon Sep 17 00:00:00 2001
From: Gleb Natapov <gleb@redhat.com>
Date: Sun, 27 Mar 2011 11:24:39 -0300
Subject: [PATCH 1/2] report that QEMU process was killed by a signal

RH-Author: Gleb Natapov <gleb@redhat.com>
Message-id: <20110327112439.GD7766@redhat.com>
Patchwork-id: 20665
O-Subject: [PATCH RHEL5.7] report that QEMU process was killed by a signal
Bugzilla: 677614
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Markus Armbruster <armbru@redhat.com>

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 <gleb@redhat.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>

BZ: 677614
Upstream commit: f64622c401d4975a56b8559e16286231a1d2cfb8

Signed-off-by: Gleb Natapov <gleb@redhat.com>
--
			Gleb.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qemu/qemu-kvm.c |    4 +++-
 qemu/sysemu.h   |    2 ++
 qemu/vl.c       |   27 +++++++++++++++++++++++----
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
index 8d79065..a049bec 100644
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -594,8 +594,10 @@ int kvm_main_loop(void)
 
     while (1) {
         main_loop_wait(1000);
-        if (qemu_shutdown_requested())
+        if (qemu_shutdown_requested()) {
+            qemu_kill_report();
             break;
+        }
         else if (qemu_powerdown_requested())
             qemu_system_powerdown();
         else if (qemu_reset_requested())
diff --git a/qemu/sysemu.h b/qemu/sysemu.h
index 626d882..3484651 100644
--- a/qemu/sysemu.h
+++ b/qemu/sysemu.h
@@ -42,6 +42,8 @@ void qemu_system_powerdown_request(void);
 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);
 #if !defined(TARGET_SPARC) && !defined(TARGET_I386)
 // Please implement a power failure function to signal the OS
 #define qemu_system_powerdown() do{}while(0)
diff --git a/qemu/vl.c b/qemu/vl.c
index fdc6343..a6bfbf8 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -3883,7 +3883,8 @@ typedef struct QEMUResetEntry {
 
 static QEMUResetEntry *first_reset_entry;
 static int reset_requested;
-static int shutdown_requested;
+static int shutdown_requested, shutdown_signal = -1;
+static pid_t shutdown_pid;
 static int powerdown_requested;
 
 int qemu_shutdown_requested(void)
@@ -3893,6 +3894,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;
@@ -3947,6 +3957,13 @@ void qemu_system_reset_request(void)
     term_printf_async(REBOOT_ASYNC_EVENT, "GUEST: Got reboot request\n");
 }
 
+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)
 {
     term_printf_async(SHUTDOWN_ASYNC_EVENT, "GUEST: Got shutdown request\n");
@@ -5148,9 +5165,9 @@ static void *qemu_alloc_physram(unsigned long memory)
 
 #ifndef _WIN32
 
-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 termsig_setup(void)
@@ -5158,7 +5175,9 @@ static void termsig_setup(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);
-- 
1.7.3.2