From patchwork Sat May 18 04:31:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 244735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 26E842C00A2 for ; Sat, 18 May 2013 14:31:56 +1000 (EST) Received: from localhost ([::1]:56431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdYoE-0006Ry-Al for incoming@patchwork.ozlabs.org; Sat, 18 May 2013 00:31:54 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdYnT-0005jE-Sv for qemu-devel@nongnu.org; Sat, 18 May 2013 00:31:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UdYnQ-0002iB-GH for qemu-devel@nongnu.org; Sat, 18 May 2013 00:31:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43321) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdYnQ-0002hK-9U for qemu-devel@nongnu.org; Sat, 18 May 2013 00:31:04 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4I4TcL4009814 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 18 May 2013 00:29:38 -0400 Received: from lacos-laptop.usersys.redhat.com (vpn1-5-212.ams2.redhat.com [10.36.5.212]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r4I4TXCo014174; Sat, 18 May 2013 00:29:37 -0400 From: Laszlo Ersek To: mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org Date: Sat, 18 May 2013 06:31:49 +0200 Message-Id: <1368851513-20550-3-git-send-email-lersek@redhat.com> In-Reply-To: <1368851513-20550-1-git-send-email-lersek@redhat.com> References: <1368851513-20550-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/6] qga: determine default state dir and pidfile dynamically X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org No effective change on POSIX, but on Win32 the defaults come from the environment / session. Since commit 39097daf ("qemu-ga: use key-value store to avoid recycling fd handles after restart") we've relied on the state directory for the fd handles' key-value store. Even though we don't support the guest-file-* commands on win32 yet, the key-value store is written, and it's the first use of the state directory on win32. We should have a sensible default for its location. Signed-off-by: Laszlo Ersek --- qga/main.c | 32 ++++++++++++++++++++++++++------ 1 files changed, 26 insertions(+), 6 deletions(-) diff --git a/qga/main.c b/qga/main.c index 44a2836..f5f033d 100644 --- a/qga/main.c +++ b/qga/main.c @@ -45,16 +45,21 @@ #ifndef _WIN32 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0" +#define QGA_STATE_RELATIVE_DIR "run" #else #define QGA_VIRTIO_PATH_DEFAULT "\\\\.\\Global\\org.qemu.guest_agent.0" +#define QGA_STATE_RELATIVE_DIR "qemu-ga" #endif -#define QGA_STATEDIR_DEFAULT CONFIG_QEMU_LOCALSTATEDIR "/run" -#define QGA_PIDFILE_DEFAULT QGA_STATEDIR_DEFAULT "/qemu-ga.pid" #ifdef CONFIG_FSFREEZE #define QGA_FSFREEZE_HOOK_DEFAULT CONFIG_QEMU_CONFDIR "/fsfreeze-hook" #endif #define QGA_SENTINEL_BYTE 0xFF +static struct { + const char *state_dir; + const char *pidfile; +} dfl_pathnames; + typedef struct GAPersistentState { #define QGA_PSTATE_DEFAULT_FD_COUNTER 1000 int64_t fd_counter; @@ -106,6 +111,17 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data, VOID WINAPI service_main(DWORD argc, TCHAR *argv[]); #endif +static void +init_dfl_pathnames(void) +{ + g_assert(dfl_pathnames.state_dir == NULL); + g_assert(dfl_pathnames.pidfile == NULL); + dfl_pathnames.state_dir = qemu_get_local_state_pathname( + QGA_STATE_RELATIVE_DIR); + dfl_pathnames.pidfile = qemu_get_local_state_pathname( + QGA_STATE_RELATIVE_DIR G_DIR_SEPARATOR_S "qemu-ga.pid"); +} + static void quit_handler(int sig) { /* if we're frozen, don't exit unless we're absolutely forced to, @@ -198,11 +214,11 @@ static void usage(const char *cmd) " -h, --help display this help and exit\n" "\n" "Report bugs to \n" - , cmd, QEMU_VERSION, QGA_VIRTIO_PATH_DEFAULT, QGA_PIDFILE_DEFAULT, + , cmd, QEMU_VERSION, QGA_VIRTIO_PATH_DEFAULT, dfl_pathnames.pidfile, #ifdef CONFIG_FSFREEZE QGA_FSFREEZE_HOOK_DEFAULT, #endif - QGA_STATEDIR_DEFAULT); + dfl_pathnames.state_dir); } static const char *ga_log_level_str(GLogLevelFlags level) @@ -908,11 +924,11 @@ int main(int argc, char **argv) const char *sopt = "hVvdm:p:l:f:F::b:s:t:"; const char *method = NULL, *path = NULL; const char *log_filepath = NULL; - const char *pid_filepath = QGA_PIDFILE_DEFAULT; + const char *pid_filepath; #ifdef CONFIG_FSFREEZE const char *fsfreeze_hook = NULL; #endif - const char *state_dir = QGA_STATEDIR_DEFAULT; + const char *state_dir; #ifdef _WIN32 const char *service = NULL; #endif @@ -942,6 +958,10 @@ int main(int argc, char **argv) module_call_init(MODULE_INIT_QAPI); + init_dfl_pathnames(); + pid_filepath = dfl_pathnames.pidfile; + state_dir = dfl_pathnames.state_dir; + while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { switch (ch) { case 'm':