diff mbox series

[v3,07/20] mcdstub: quitting QEMU via mcd command added

Message ID 20231107130323.4126-8-nicolas.eder@lauterbach.com (mailing list archive)
State New, archived
Headers show
Series first version of mcdstub | expand

Commit Message

nicolas.eder@lauterbach.com Nov. 7, 2023, 1:03 p.m. UTC
---
 include/mcdstub/mcdstub.h |  9 +++++++++
 mcdstub/mcdstub.c         | 15 +++++++++++++++
 2 files changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/include/mcdstub/mcdstub.h b/include/mcdstub/mcdstub.h
index c7e34673a6..c3e9c7e9dc 100644
--- a/include/mcdstub/mcdstub.h
+++ b/include/mcdstub/mcdstub.h
@@ -356,6 +356,15 @@  int mcd_handle_packet(const char *line_buf);
  */
 void mcd_put_strbuf(void);
 
+/**
+ * mcd_exit() - Terminates QEMU.
+ *
+ * If the mcdserver_state has not been initialized the function exits before
+ * terminating QEMU. Terminting is done with the qemu_chr_fe_deinit function.
+ * @code: An exitcode, which can be used in the future.
+ */
+void mcd_exit(int code);
+
 /**
  * run_cmd_parser() - Prepares the mcdserver_state before executing TCP packet
  * functions.
diff --git a/mcdstub/mcdstub.c b/mcdstub/mcdstub.c
index d2f6df04c0..858e79632b 100644
--- a/mcdstub/mcdstub.c
+++ b/mcdstub/mcdstub.c
@@ -340,6 +340,11 @@  int mcd_handle_packet(const char *line_buf)
             cmd_parser = &open_server_cmd_desc;
         }
         break;
+    case TCP_CHAR_KILLQEMU:
+        /* kill qemu completely */
+        error_report("QEMU: Terminated via MCDstub");
+        mcd_exit(0);
+        exit(0);
     case TCP_CHAR_CLOSE_SERVER:
         {
             static MCDCmdParseEntry close_server_cmd_desc = {
@@ -492,6 +497,16 @@  int process_string_cmd(void *user_ctx, const char *data,
     return -1;
 }
 
+void mcd_exit(int code)
+{
+    /* terminate qemu */
+    if (!mcdserver_state.init) {
+        return;
+    }
+
+    qemu_chr_fe_deinit(&mcdserver_system_state.chr, true);
+}
+
 void mcd_chr_event(void *opaque, QEMUChrEvent event)
 {
     int i;