From 3290c4aac5b97bb1e3b2b28d94669f2c611ce84a Mon Sep 17 00:00:00 2001 From: Anthony Liguori Date: Wed, 17 Mar 2010 17:37:03 -0500 Subject: [PATCH] Introduce a default qmp session Basically, -qmp unix:%{home}/.qemu/qmp/%{uuid}.sock,server,nowait %{uuid} will be -uuid if it's specified, otherwise, if libuuid is available, we generate a uuid. If it's not available, we don't create one. Signed-off-by: Anthony Liguori --- vl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/vl.c b/vl.c index e14f45eaee..5c62d97d6a 100644 --- a/vl.c +++ b/vl.c @@ -93,6 +93,10 @@ extern int madvise(caddr_t, size_t, int); #include #endif +#if defined(CONFIG_UUID) +#include +#endif + #ifdef _WIN32 #include #endif @@ -3733,6 +3737,51 @@ static const QEMUOption *lookup_opt(int argc, char **argv, return popt; } +static void qmp_add_default(void) +{ + char buffer[4096]; + const char *home; + static uint8_t null_uuid[16]; + uint8_t uuid[16]; + + home = getenv("HOME"); + if (!home) { + return; + } + + if (memcmp(qemu_uuid, null_uuid, sizeof(null_uuid)) == 0) { +#if defined(CONFIG_UUID) + uuid_generate(uuid); +#else + return; +#endif + } else { + memcpy(uuid, qemu_uuid, sizeof(qemu_uuid)); + } + + snprintf(buffer, sizeof(buffer), "%s/.qemu", home); + if (mkdir(buffer, 0755) == -1 && errno != EEXIST) { + fprintf(stderr, "could not open default QMP port\n"); + return; + } + + snprintf(buffer, sizeof(buffer), "%s/.qemu/qmp", home); + if (mkdir(buffer, 0755) == -1 && errno != EEXIST) { + fprintf(stderr, "could not open default QMP port\n"); + return; + } + + snprintf(buffer, sizeof(buffer), + "unix:%s/.qemu/qmp/" UUID_FMT ".sock,server,nowait", + home, + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], uuid[6], uuid[7], + uuid[8], uuid[9], uuid[10], uuid[11], + uuid[12], uuid[13], uuid[14], uuid[15]); + + monitor_parse(buffer, "control"); +} + int main(int argc, char **argv, char **envp) { const char *gdbstub_dev = NULL; @@ -4659,6 +4708,9 @@ int main(int argc, char **argv, char **envp) if (default_virtcon) add_device_config(DEV_VIRTCON, "vc:80Cx24C"); } + if (default_qmp) { + qmp_add_default(); + } if (default_vga) vga_interface_type = VGA_CIRRUS; -- 2.11.4.GIT