Skip to contentSkip to conversation

report that QEMU process was killed by a signal

PATCH Superseded Gleb Natapov 2 participants 3 messages Mar 14, 2011

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 report that QEMU process was killed by a signal

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.

---
v1->v2:
- print message from a main loop instead of signal handler

os-posix.c +4 -3
index 38c29d1..36d937c 100644
@@ -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);
sysemu.h +2 -0
index 0a83ab9..fc7048a 100644
@@ -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, int pid);
+void qemu_kill_report(void);
 extern qemu_irq qemu_system_powerdown;
 void qemu_system_reset(void);
 
vl.c +18 -1
index 5e007a7..d14c42d 100644
@@ -1213,7 +1213,7 @@ 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, shutdown_pid;
 static int powerdown_requested;
 static int debug_requested;
 static int vmstop_requested;
@@ -1225,6 +1225,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 +1307,13 @@ void qemu_system_reset_request(void)
     qemu_notify_event();
 }
 
+void qemu_system_killed(int signal, int pid)
+{
+    shutdown_signal = signal;
+    shutdown_pid = pid;
+    qemu_system_shutdown_request();
+}
+
 void qemu_system_shutdown_request(void)
 {
     shutdown_requested = 1;
@@ -1441,6 +1457,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.

#1 lore raw
Quoted 3 lines · Gleb Natapov

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.

QEMU ;-)

Quoted 37 lines

---
 v1->v2:
 - print message from a main loop instead of signal handler

os-posix.c +4 -3
index 38c29d1..36d937c 100644
@@ -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);
sysemu.h +0 -0
index 0a83ab9..fc7048a 100644

sysemu.h void qemu_system_vmstop_request(int reason); · line 69

Quoted 4 lines
sysemu.h +1 -0
@@ -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, int pid);

pid_t pid

Quoted 12 lines
sysemu.h +1 -0
+void qemu_kill_report(void);
  extern qemu_irq qemu_system_powerdown;
  void qemu_system_reset(void);
 
vl.c +0 -0
index 5e007a7..d14c42d 100644
@@ -1213,7 +1213,7 @@ typedef struct QEMUResetEntry {

 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = QTAILQ_HEAD_INITIALIZER(reset_handlers);
 static int reset_requested;

vl.c typedef struct QEMUResetEntry { · line 1216

Quoted 2 lines
vl.c +1 -1
-static int shutdown_requested;
+static int shutdown_requested, shutdown_signal = -1, shutdown_pid;

static pid_t shutdown_pid;

vl.c int qemu_shutdown_requested(void) · line 1231

Quoted 11 lines

 static int powerdown_requested;
 static int debug_requested;
 static int vmstop_requested;

vl.c +4 -0
@@ -1225,6 +1225,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",

Are there any systems with 64 bit pid_t? Then a cast may be needed and/or format adjusted.

vl.c void qemu_system_reset_request(void) · line 1310

Quoted 13 lines
vl.c +6 -0
+                         shutdown_signal, shutdown_pid);
+        shutdown_signal = -1;
+    }
+}
+
  int qemu_reset_requested(void)
  {
     int r = reset_requested;
@@ -1298,6 +1307,13 @@ void qemu_system_reset_request(void)
     qemu_notify_event();
  }
 
+void qemu_system_killed(int signal, int pid)

pid_t pid

#2 lore raw
Quoted 7 lines · Blue Swirl
Quoted 3 lines · Gleb Natapov

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.

QEMU ;-)

Eah and second "killed" should be "killer". Why can't spell checker be smarter.

Quoted 35 lines
Quoted 35 lines

---
 v1->v2:
 - print message from a main loop instead of signal handler

os-posix.c +4 -3
index 38c29d1..36d937c 100644
@@ -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);
sysemu.h +0 -1
index 0a83ab9..fc7048a 100644
--- a/sysemu.h
Quoted 9 lines

sysemu.h void qemu_system_vmstop_request(int reason); · line 69

Quoted 6 lines

+++ b/sysemu.h

sysemu.h +1 -0
@@ -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, int pid);

pid_t pid

OK.

Quoted 24 lines
Quoted 12 lines
sysemu.h +1 -0
+void qemu_kill_report(void);
  extern qemu_irq qemu_system_powerdown;
  void qemu_system_reset(void);
 
vl.c +0 -0
index 5e007a7..d14c42d 100644
@@ -1213,7 +1213,7 @@ typedef struct QEMUResetEntry {

 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = QTAILQ_HEAD_INITIALIZER(reset_handlers);
 static int reset_requested;

vl.c typedef struct QEMUResetEntry { · line 1216

Quoted 2 lines
vl.c +1 -1
-static int shutdown_requested;
+static int shutdown_requested, shutdown_signal = -1, shutdown_pid;

static pid_t shutdown_pid;

Quoted 7 lines

 static int powerdown_requested;
 static int debug_requested;
 static int vmstop_requested;

vl.c +0 -0
@@ -1225,6 +1225,15 @@ int qemu_shutdown_requested(void)
     return r;
  }
 
Quoted 8 lines

vl.c int qemu_shutdown_requested(void) · line 1231

Quoted 4 lines
vl.c +4 -0
+void qemu_kill_report(void)
+{
+    if (shutdown_signal != -1) {
+        fprintf(stderr, "Got signal %d from pid %d\n",

Are there any systems with 64 bit pid_t? Then a cast may be needed and/or format adjusted.

Doubt there are any.

Quoted 12 lines
Quoted 12 lines
vl.c +5 -0
+                         shutdown_signal, shutdown_pid);
+        shutdown_signal = -1;
+    }
+}
+
  int qemu_reset_requested(void)
  {
     int r = reset_requested;
@@ -1298,6 +1307,13 @@ void qemu_system_reset_request(void)
     qemu_notify_event();
  }
 
Quoted 3 lines

vl.c void qemu_system_reset_request(void) · line 1310

Quoted 1 line
vl.c +1 -0
+void qemu_system_killed(int signal, int pid)

pid_t pid

--
Gleb.