thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-qga-determine-default-state-dir-and-pidfile-dynamica.patch

218e99
From 211077f1cceb5f814d0750b183ff19995b37c6d3 Mon Sep 17 00:00:00 2001
218e99
From: Laszlo Ersek <lersek@redhat.com>
218e99
Date: Wed, 31 Jul 2013 14:03:23 +0200
218e99
Subject: [PATCH 02/28] qga: determine default state dir and pidfile dynamically
218e99
218e99
RH-Author: Laszlo Ersek <lersek@redhat.com>
218e99
Message-id: <1375279407-13573-3-git-send-email-lersek@redhat.com>
218e99
Patchwork-id: 52861
218e99
O-Subject: [RHEL-7 qemu-kvm PATCH 2/6] qga: determine default state dir and pidfile dynamically
218e99
Bugzilla: 964304
218e99
RH-Acked-by: Michal Novotny <minovotn@redhat.com>
218e99
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
218e99
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
218e99
No effective change on POSIX, but on Win32 the defaults come from the
218e99
environment / session.
218e99
218e99
Since commit 39097daf ("qemu-ga: use key-value store to avoid recycling fd
218e99
handles after restart") we've relied on the state directory for the fd
218e99
handles' key-value store. Even though we don't support the guest-file-*
218e99
commands on win32 yet, the key-value store is written, and it's the first
218e99
use of the state directory on win32. We should have a sensible default for
218e99
its location.
218e99
218e99
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
218e99
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
218e99
(cherry picked from commit c394ecb7bf55b7234f852b9c8518aefb5d0943fa)
218e99
---
218e99
 qga/main.c |   32 ++++++++++++++++++++++++++------
218e99
 1 files changed, 26 insertions(+), 6 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 qga/main.c |   32 ++++++++++++++++++++++++++------
218e99
 1 files changed, 26 insertions(+), 6 deletions(-)
218e99
218e99
diff --git a/qga/main.c b/qga/main.c
218e99
index c2ba5d9..050b968 100644
218e99
--- a/qga/main.c
218e99
+++ b/qga/main.c
218e99
@@ -45,16 +45,21 @@
218e99
 
218e99
 #ifndef _WIN32
218e99
 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
218e99
+#define QGA_STATE_RELATIVE_DIR  "run"
218e99
 #else
218e99
 #define QGA_VIRTIO_PATH_DEFAULT "\\\\.\\Global\\org.qemu.guest_agent.0"
218e99
+#define QGA_STATE_RELATIVE_DIR  "qemu-ga"
218e99
 #endif
218e99
-#define QGA_STATEDIR_DEFAULT CONFIG_QEMU_LOCALSTATEDIR "/run"
218e99
-#define QGA_PIDFILE_DEFAULT QGA_STATEDIR_DEFAULT "/qemu-ga.pid"
218e99
 #ifdef CONFIG_FSFREEZE
218e99
 #define QGA_FSFREEZE_HOOK_DEFAULT CONFIG_QEMU_CONFDIR "/fsfreeze-hook"
218e99
 #endif
218e99
 #define QGA_SENTINEL_BYTE 0xFF
218e99
 
218e99
+static struct {
218e99
+    const char *state_dir;
218e99
+    const char *pidfile;
218e99
+} dfl_pathnames;
218e99
+
218e99
 typedef struct GAPersistentState {
218e99
 #define QGA_PSTATE_DEFAULT_FD_COUNTER 1000
218e99
     int64_t fd_counter;
218e99
@@ -106,6 +111,17 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data,
218e99
 VOID WINAPI service_main(DWORD argc, TCHAR *argv[]);
218e99
 #endif
218e99
 
218e99
+static void
218e99
+init_dfl_pathnames(void)
218e99
+{
218e99
+    g_assert(dfl_pathnames.state_dir == NULL);
218e99
+    g_assert(dfl_pathnames.pidfile == NULL);
218e99
+    dfl_pathnames.state_dir = qemu_get_local_state_pathname(
218e99
+      QGA_STATE_RELATIVE_DIR);
218e99
+    dfl_pathnames.pidfile   = qemu_get_local_state_pathname(
218e99
+      QGA_STATE_RELATIVE_DIR G_DIR_SEPARATOR_S "qemu-ga.pid");
218e99
+}
218e99
+
218e99
 static void quit_handler(int sig)
218e99
 {
218e99
     /* if we're frozen, don't exit unless we're absolutely forced to,
218e99
@@ -198,11 +214,11 @@ static void usage(const char *cmd)
218e99
 "  -h, --help        display this help and exit\n"
218e99
 "\n"
218e99
 "Report bugs to <mdroth@linux.vnet.ibm.com>\n"
218e99
-    , cmd, QEMU_VERSION, QGA_VIRTIO_PATH_DEFAULT, QGA_PIDFILE_DEFAULT,
218e99
+    , cmd, QEMU_VERSION, QGA_VIRTIO_PATH_DEFAULT, dfl_pathnames.pidfile,
218e99
 #ifdef CONFIG_FSFREEZE
218e99
     QGA_FSFREEZE_HOOK_DEFAULT,
218e99
 #endif
218e99
-    QGA_STATEDIR_DEFAULT);
218e99
+    dfl_pathnames.state_dir);
218e99
 }
218e99
 
218e99
 static const char *ga_log_level_str(GLogLevelFlags level)
218e99
@@ -908,11 +924,11 @@ int main(int argc, char **argv)
218e99
     const char *sopt = "hVvdm:p:l:f:F::b:s:t:";
218e99
     const char *method = NULL, *path = NULL;
218e99
     const char *log_filepath = NULL;
218e99
-    const char *pid_filepath = QGA_PIDFILE_DEFAULT;
218e99
+    const char *pid_filepath;
218e99
 #ifdef CONFIG_FSFREEZE
218e99
     const char *fsfreeze_hook = NULL;
218e99
 #endif
218e99
-    const char *state_dir = QGA_STATEDIR_DEFAULT;
218e99
+    const char *state_dir;
218e99
 #ifdef _WIN32
218e99
     const char *service = NULL;
218e99
 #endif
218e99
@@ -942,6 +958,10 @@ int main(int argc, char **argv)
218e99
 
218e99
     module_call_init(MODULE_INIT_QAPI);
218e99
 
218e99
+    init_dfl_pathnames();
218e99
+    pid_filepath = dfl_pathnames.pidfile;
218e99
+    state_dir = dfl_pathnames.state_dir;
218e99
+
218e99
     while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
218e99
         switch (ch) {
218e99
         case 'm':
218e99
-- 
218e99
1.7.1
218e99