qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: damien.hedde@greensocs.com, berrange@redhat.com,
	mark.burton@greensocs.com, armbru@redhat.com, f4bug@amsat.org,
	mirela.grujic@greensocs.com
Subject: [RFC PATCH 3/3] introduce qemu-qmp-*
Date: Tue,  8 Feb 2022 09:44:58 -0500	[thread overview]
Message-ID: <20220208144458.1079634-4-pbonzini@redhat.com> (raw)
In-Reply-To: <20220208144458.1079634-1-pbonzini@redhat.com>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 meson.build                 |  16 +++--
 softmmu/{vl.c => climain.c} |   2 +-
 softmmu/meson.build         |   1 -
 softmmu/qmpmain.c           | 120 ++++++++++++++++++++++++++++++++++++
 4 files changed, 133 insertions(+), 6 deletions(-)
 rename softmmu/{vl.c => climain.c} (99%)
 create mode 100644 softmmu/qmpmain.c

diff --git a/meson.build b/meson.build
index 5f43355071..eed85d3d1a 100644
--- a/meson.build
+++ b/meson.build
@@ -3003,14 +3003,21 @@ foreach target : target_dirs
     execs = [{
       'name': 'qemu-system-' + target_name,
       'win_subsystem': 'console',
-      'sources': files('softmmu/main.c'),
+      'sources': [files('softmmu/climain.c', 'softmmu/main.c')],
       'dependencies': []
     }]
-    if targetos == 'windows' and (sdl.found() or gtk.found())
+    if targetos != 'windows'
+      execs += [{
+        'name': 'qemu-qmp-' + target_name,
+        'win_subsystem': 'console',
+        'sources': [files('softmmu/qmpmain.c', 'softmmu/main.c')],
+        'dependencies': []
+      }]
+    elif sdl.found() or gtk.found()
       execs += [{
         'name': 'qemu-system-' + target_name + 'w',
         'win_subsystem': 'windows',
-        'sources': files('softmmu/main.c'),
+        'sources': [files('softmmu/climain.c', 'softmmu/main.c')],
         'dependencies': []
       }]
     endif
@@ -3019,7 +3026,7 @@ foreach target : target_dirs
       execs += [{
         'name': 'qemu-fuzz-' + target_name,
         'win_subsystem': 'console',
-        'sources': specific_fuzz.sources(),
+        'sources': [files('softmmu/climain.c'), specific_fuzz.sources()],
         'dependencies': specific_fuzz.dependencies(),
       }]
     endif
@@ -3040,6 +3047,7 @@ foreach target : target_dirs
     emulator = executable(exe_name, exe['sources'],
                install: true,
                c_args: c_args,
+               include_directories: target_inc,
                dependencies: arch_deps + deps + exe['dependencies'],
                objects: lib.extract_all_objects(recursive: true),
                link_language: link_language,
diff --git a/softmmu/vl.c b/softmmu/climain.c
similarity index 99%
rename from softmmu/vl.c
rename to softmmu/climain.c
index 5e1b35ba48..0489850415 100644
--- a/softmmu/vl.c
+++ b/softmmu/climain.c
@@ -1,5 +1,5 @@
 /*
- * QEMU System Emulator
+ * QEMU System Emulator command-line interface
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
  *
diff --git a/softmmu/meson.build b/softmmu/meson.build
index d8e03018ab..d53673f8d2 100644
--- a/softmmu/meson.build
+++ b/softmmu/meson.build
@@ -12,7 +12,6 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files(
   'memory.c',
   'memory_mapping.c',
   'qtest.c',
-  'vl.c',
   'cpu-timers.c',
   'runstate-action.c',
 )])
diff --git a/softmmu/qmpmain.c b/softmmu/qmpmain.c
new file mode 100644
index 0000000000..d976736ed9
--- /dev/null
+++ b/softmmu/qmpmain.c
@@ -0,0 +1,120 @@
+/*
+ * QEMU System Emulator machine interface
+ *
+ * Copyright (c) 2020 Red Hat, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/rcu.h"
+#include "qemu-common.h"
+#include "chardev/char.h"
+#include "monitor/monitor.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-misc.h"
+#include "qapi/qapi-commands-ui.h"
+#include "qapi/qapi-types-sockets.h"
+#include "qemu/systemd.h"
+#include "sysemu/cpu-timers.h"
+#include "sysemu/sysemu.h"
+#include "ui/console.h"
+#include "hw/qdev-core.h"
+
+static void open_socket_and_monitor(void)
+{
+    int nfds = check_socket_activation();
+    Chardev *chardev;
+    if (nfds > 1) {
+        error_report("QEMU only supports listening on one socket");
+        exit(1);
+    }
+    if (!nfds) {
+        ChardevBackend backend = {
+            .type = CHARDEV_BACKEND_KIND_STDIO,
+            .u.stdio.data = &(ChardevStdio) {
+                .has_signal = true,
+                .signal = false
+            }
+        };
+        chardev = qemu_chardev_new("#qmp0", TYPE_CHARDEV_STDIO, &backend, NULL, &error_fatal);
+    } else {
+        ChardevBackend backend = {
+           .type = CHARDEV_BACKEND_KIND_SOCKET,
+           .u.socket.data = &(ChardevSocket) {
+               .addr = &(SocketAddressLegacy) {
+                   .type = SOCKET_ADDRESS_TYPE_FD,
+                   .u.fd.data = &(String){
+                       .str = (char *) stringify(FIRST_SOCKET_ACTIVATION_FD)
+                   }
+               }
+           }
+        };
+        chardev = qemu_chardev_new("#qmp0", TYPE_CHARDEV_SOCKET, &backend, NULL, &error_fatal);
+    }
+    monitor_init_qmp(chardev, true, &error_fatal);
+}
+
+bool defaults_enabled(void)
+{
+    return false;
+}
+
+DisplayOptions *qmp_query_display_options(Error **errp)
+{
+    error_setg(errp, "You're running too fast!");
+    return NULL;
+}
+
+Chardev *serial_hd(int i)
+{
+    return NULL;
+}
+
+void qmp_x_exit_preconfig(Error **errp)
+{
+    error_setg(errp, "You're running too fast!");
+}
+
+void qemu_init(int argc, char **argv, char **envp)
+{
+    error_init(argv[0]);
+    qemu_init_exec_dir(argv[0]);
+
+    qemu_init_subsystems();
+
+    /* Missing: parse -name, -sandbox, -trace, -L */
+
+    /*
+     * Clear error location left behind by the loop.
+     * Best done right after the loop.  Do not insert code here!
+     */
+    loc_set_none();
+
+    /* Missing: process -name, -sandbox, -trace, -L */
+
+    rcu_disable_atfork();
+    qemu_init_main_loop(&error_fatal);
+    cpu_timers_init();
+    open_socket_and_monitor();
+
+    /* Missing: replay_configure, configure_rtc */
+
+    /* machine-set:
+     *    qemu_create_machine();
+     *    qemu_apply_machine_options();
+     *    phase_advance(PHASE_MACHINE_CREATED);
+     *
+     * accel-set:
+     *    configure_accelerators(argv[0]);
+     *    phase_advance(PHASE_ACCEL_CREATED);
+     *    machine type deprecation
+     *    migration_object_init();
+     *    cpu_type...
+     *    accel_setup_post(current_machine);
+     *    machine_run_board_init(current_machine, errp);
+     */
+
+    init_displaystate();
+    os_setup_signal_handling();
+}
-- 
2.31.1



      parent reply	other threads:[~2022-02-08 17:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-08 14:44 [RFC PATCH 0/3] introduce QMP-only binaries Paolo Bonzini
2022-02-08 14:44 ` [RFC PATCH 1/3] migration: allow calling migration_shutdown without a prior initialization Paolo Bonzini
2022-02-08 14:44 ` [RFC PATCH 2/3] net: initialize global variables early Paolo Bonzini
2022-02-08 14:47   ` Philippe Mathieu-Daudé via
2022-02-08 14:44 ` Paolo Bonzini [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220208144458.1079634-4-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=damien.hedde@greensocs.com \
    --cc=f4bug@amsat.org \
    --cc=mark.burton@greensocs.com \
    --cc=mirela.grujic@greensocs.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).