Skip to contentSkip to conversation

Use clean shutdown request for ctrl-a x

PATCH In review Fabien Chouteau 4 participants 6 messages Jul 4, 2012 – Jul 10, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Use clean shutdown request for ctrl-a x

The goal is to make ctrl-a x to close Qemu in a clean way. The current exit(0) skips a lot of cleanup/close functions, for example in block drivers.

---
 qemu-char.c |    2 +-
 sysemu.h    |    1 +
 vl.c        |    5 +++++
 3 files changed, 7 insertions(+), 1 deletion(-)
qemu-char.c +1 -1
index c2aaaee..7732846 100644
@@ -353,7 +353,7 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch)
             {
                  const char *term =  "QEMU: Terminated\n\r";
                  chr->chr_write(chr,(uint8_t *)term,strlen(term));
-                 exit(0);
+                 qemu_system_force_shutdown();
                  break;
             }
         case 's':
sysemu.h +1 -0
index bc2c788..2b2c354 100644
@@ -50,6 +50,7 @@ void qemu_register_suspend_notifier(Notifier *notifier);
 void qemu_system_wakeup_request(WakeupReason reason);
 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
 void qemu_register_wakeup_notifier(Notifier *notifier);
+void qemu_system_force_shutdown(void);
 void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
 void qemu_system_debug_request(void);
vl.c +5 -0
index 1329c30..bd27583 100644
@@ -1477,6 +1477,11 @@ void qemu_system_killed(int signal, pid_t pid)
 {
     shutdown_signal = signal;
     shutdown_pid = pid;
+    qemu_system_force_shutdown();
+}
+
+void qemu_system_force_shutdown(void)
+{
     no_shutdown = 0;
     qemu_system_shutdown_request();
 }
Signature · 1 line
1.7.9.5
#1 lore raw

Any comment?

Quoted 53 lines · Fabien Chouteau

The goal is to make ctrl-a x to close Qemu in a clean way. The current exit(0) skips a lot of cleanup/close functions, for example in block drivers.

---
 qemu-char.c |    2 +-
 sysemu.h    |    1 +
 vl.c        |    5 +++++
 3 files changed, 7 insertions(+), 1 deletion(-)
qemu-char.c +1 -1
index c2aaaee..7732846 100644
@@ -353,7 +353,7 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch)
             {
                  const char *term =  "QEMU: Terminated\n\r";
                  chr->chr_write(chr,(uint8_t *)term,strlen(term));
-                 exit(0);
+                 qemu_system_force_shutdown();
                  break;
             }
         case 's':
sysemu.h +1 -0
index bc2c788..2b2c354 100644
@@ -50,6 +50,7 @@ void qemu_register_suspend_notifier(Notifier *notifier);
 void qemu_system_wakeup_request(WakeupReason reason);
 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
 void qemu_register_wakeup_notifier(Notifier *notifier);
+void qemu_system_force_shutdown(void);
 void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
 void qemu_system_debug_request(void);
vl.c +5 -0
index 1329c30..bd27583 100644
@@ -1477,6 +1477,11 @@ void qemu_system_killed(int signal, pid_t pid)
 {
     shutdown_signal = signal;
     shutdown_pid = pid;
+    qemu_system_force_shutdown();
+}
+
+void qemu_system_force_shutdown(void)
+{
     no_shutdown = 0;
     qemu_system_shutdown_request();
 }
Signature · 1 line
Fabien Chouteau
#2 lore raw

Il 09/07/2012 12:19, Fabien Chouteau ha scritto:

Quoted 1 line

Any comment?

Looks good to me. Blue, can you apply it while Anthony is on holiday?

Paolo

Quoted 56 lines · Fabien Chouteau
Quoted 53 lines

The goal is to make ctrl-a x to close Qemu in a clean way. The current exit(0) skips a lot of cleanup/close functions, for example in block drivers.

---
 qemu-char.c |    2 +-
 sysemu.h    |    1 +
 vl.c        |    5 +++++
 3 files changed, 7 insertions(+), 1 deletion(-)
qemu-char.c +1 -1
index c2aaaee..7732846 100644
@@ -353,7 +353,7 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch)
             {
                  const char *term =  "QEMU: Terminated\n\r";
                  chr->chr_write(chr,(uint8_t *)term,strlen(term));
-                 exit(0);
+                 qemu_system_force_shutdown();
                  break;
             }
         case 's':
sysemu.h +1 -0
index bc2c788..2b2c354 100644
@@ -50,6 +50,7 @@ void qemu_register_suspend_notifier(Notifier *notifier);
 void qemu_system_wakeup_request(WakeupReason reason);
 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
 void qemu_register_wakeup_notifier(Notifier *notifier);
+void qemu_system_force_shutdown(void);
 void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
 void qemu_system_debug_request(void);
vl.c +5 -0
index 1329c30..bd27583 100644
@@ -1477,6 +1477,11 @@ void qemu_system_killed(int signal, pid_t pid)
 {
     shutdown_signal = signal;
     shutdown_pid = pid;
+    qemu_system_force_shutdown();
+}
+
+void qemu_system_force_shutdown(void)
+{
     no_shutdown = 0;
     qemu_system_shutdown_request();
 }
#4 lore raw
In reply to Fabien Chouteau

Am 09.07.2012 12:19, schrieb Fabien Chouteau:

Quoted 14 lines

Any comment?

Quoted 11 lines · Fabien Chouteau

The goal is to make ctrl-a x to close Qemu in a clean way. The current exit(0) skips a lot of cleanup/close functions, for example in block drivers.

---
 qemu-char.c |    2 +-
 sysemu.h    |    1 +
 vl.c        |    5 +++++
 3 files changed, 7 insertions(+), 1 deletion(-)
Quoted 13 lines

qemu-char.c static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch) · line 359

Quoted 13 lines
qemu-char.c +1 -1
index c2aaaee..7732846 100644
@@ -353,7 +353,7 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch)
             {
                  const char *term =  "QEMU: Terminated\n\r";
                  chr->chr_write(chr,(uint8_t *)term,strlen(term));
-                 exit(0);
+                 qemu_system_force_shutdown();
                  break;
             }
         case 's':

FWIW there was a recent patch by Hervé that exposed further occurrences of exit(), probably all would need to be reviewed and fixed.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#5 lore raw
Quoted 15 lines · Andreas Färber

Am 09.07.2012 12:19, schrieb Fabien Chouteau:

Quoted 14 lines

Any comment?

Quoted 11 lines · Fabien Chouteau

The goal is to make ctrl-a x to close Qemu in a clean way. The current exit(0) skips a lot of cleanup/close functions, for example in block drivers.

---
 qemu-char.c |    2 +-
 sysemu.h    |    1 +
 vl.c        |    5 +++++
 3 files changed, 7 insertions(+), 1 deletion(-)
Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
qemu-char.c +0 -0
index c2aaaee..7732846 100644
@@ -353,7 +353,7 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch)
Quoted 8 lines

qemu-char.c static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch) · line 359

Quoted 8 lines
qemu-char.c +1 -1
             {
                  const char *term =  "QEMU: Terminated\n\r";
                  chr->chr_write(chr,(uint8_t *)term,strlen(term));
-                 exit(0);
+                 qemu_system_force_shutdown();
                  break;
             }
         case 's':

FWIW there was a recent patch by Hervé that exposed further occurrences of exit(), probably all would need to be reviewed and fixed.

There's a lot of exit() in Qemu (~660 with a quick grep), but it doesn't always make sense to change them all.

In my opinion this one is a clean user request to shutdown the system, as opposed to an error state that requires exit().

Signature · 1 line
Fabien Chouteau