|
|
218e99 |
From eb8c85b01be23beabb2b61e8b32a7e20ca0fea17 Mon Sep 17 00:00:00 2001
|
|
|
218e99 |
From: Laszlo Ersek <lersek@redhat.com>
|
|
|
218e99 |
Date: Wed, 31 Jul 2013 14:03:22 +0200
|
|
|
218e99 |
Subject: [PATCH 01/28] osdep: add qemu_get_local_state_pathname()
|
|
|
218e99 |
|
|
|
218e99 |
RH-Author: Laszlo Ersek <lersek@redhat.com>
|
|
|
218e99 |
Message-id: <1375279407-13573-2-git-send-email-lersek@redhat.com>
|
|
|
218e99 |
Patchwork-id: 52863
|
|
|
218e99 |
O-Subject: [RHEL-7 qemu-kvm PATCH 1/6] osdep: add qemu_get_local_state_pathname()
|
|
|
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 |
This function returns ${prefix}/var/RELATIVE_PATHNAME on POSIX-y systems,
|
|
|
218e99 |
and <CSIDL_COMMON_APPDATA>/RELATIVE_PATHNAME on Win32.
|
|
|
218e99 |
|
|
|
218e99 |
http://msdn.microsoft.com/en-us/library/bb762494.aspx
|
|
|
218e99 |
|
|
|
218e99 |
[...] This folder is used for application data that is not user
|
|
|
218e99 |
specific. For example, an application can store a spell-check
|
|
|
218e99 |
dictionary, a database of clip art, or a log file in the
|
|
|
218e99 |
CSIDL_COMMON_APPDATA folder. [...]
|
|
|
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 e2ea3515a9d2d747f91dadf361afcbeb57a71500)
|
|
|
218e99 |
---
|
|
|
218e99 |
include/qemu/osdep.h | 11 +++++++++++
|
|
|
218e99 |
util/oslib-posix.c | 9 +++++++++
|
|
|
218e99 |
util/oslib-win32.c | 22 ++++++++++++++++++++++
|
|
|
218e99 |
3 files changed, 42 insertions(+), 0 deletions(-)
|
|
|
218e99 |
|
|
|
218e99 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
218e99 |
---
|
|
|
218e99 |
include/qemu/osdep.h | 11 +++++++++++
|
|
|
218e99 |
util/oslib-posix.c | 9 +++++++++
|
|
|
218e99 |
util/oslib-win32.c | 22 ++++++++++++++++++++++
|
|
|
218e99 |
3 files changed, 42 insertions(+), 0 deletions(-)
|
|
|
218e99 |
|
|
|
218e99 |
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
|
|
|
218e99 |
index 57d7b1f..26136f1 100644
|
|
|
218e99 |
--- a/include/qemu/osdep.h
|
|
|
218e99 |
+++ b/include/qemu/osdep.h
|
|
|
218e99 |
@@ -204,4 +204,15 @@ const char *qemu_get_version(void);
|
|
|
218e99 |
void fips_set_state(bool requested);
|
|
|
218e99 |
bool fips_get_state(void);
|
|
|
218e99 |
|
|
|
218e99 |
+/* Return a dynamically allocated pathname denoting a file or directory that is
|
|
|
218e99 |
+ * appropriate for storing local state.
|
|
|
218e99 |
+ *
|
|
|
218e99 |
+ * @relative_pathname need not start with a directory separator; one will be
|
|
|
218e99 |
+ * added automatically.
|
|
|
218e99 |
+ *
|
|
|
218e99 |
+ * The caller is responsible for releasing the value returned with g_free()
|
|
|
218e99 |
+ * after use.
|
|
|
218e99 |
+ */
|
|
|
218e99 |
+char *qemu_get_local_state_pathname(const char *relative_pathname);
|
|
|
218e99 |
+
|
|
|
218e99 |
#endif
|
|
|
218e99 |
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
|
|
|
218e99 |
index 631a1de..3dc8b1b 100644
|
|
|
218e99 |
--- a/util/oslib-posix.c
|
|
|
218e99 |
+++ b/util/oslib-posix.c
|
|
|
218e99 |
@@ -47,6 +47,8 @@ extern int daemon(int, int);
|
|
|
218e99 |
# define QEMU_VMALLOC_ALIGN getpagesize()
|
|
|
218e99 |
#endif
|
|
|
218e99 |
|
|
|
218e99 |
+#include <glib/gprintf.h>
|
|
|
218e99 |
+
|
|
|
218e99 |
#include "config-host.h"
|
|
|
218e99 |
#include "sysemu/sysemu.h"
|
|
|
218e99 |
#include "trace.h"
|
|
|
218e99 |
@@ -232,3 +234,10 @@ int qemu_utimens(const char *path, const struct timespec *times)
|
|
|
218e99 |
|
|
|
218e99 |
return utimes(path, &tv[0]);
|
|
|
218e99 |
}
|
|
|
218e99 |
+
|
|
|
218e99 |
+char *
|
|
|
218e99 |
+qemu_get_local_state_pathname(const char *relative_pathname)
|
|
|
218e99 |
+{
|
|
|
218e99 |
+ return g_strdup_printf("%s/%s", CONFIG_QEMU_LOCALSTATEDIR,
|
|
|
218e99 |
+ relative_pathname);
|
|
|
218e99 |
+}
|
|
|
218e99 |
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
|
|
|
218e99 |
index df2ecbd..961fbf5 100644
|
|
|
218e99 |
--- a/util/oslib-win32.c
|
|
|
218e99 |
+++ b/util/oslib-win32.c
|
|
|
218e99 |
@@ -26,12 +26,17 @@
|
|
|
218e99 |
* THE SOFTWARE.
|
|
|
218e99 |
*/
|
|
|
218e99 |
#include <windows.h>
|
|
|
218e99 |
+#include <glib.h>
|
|
|
218e99 |
+#include <stdlib.h>
|
|
|
218e99 |
#include "config-host.h"
|
|
|
218e99 |
#include "sysemu/sysemu.h"
|
|
|
218e99 |
#include "qemu/main-loop.h"
|
|
|
218e99 |
#include "trace.h"
|
|
|
218e99 |
#include "qemu/sockets.h"
|
|
|
218e99 |
|
|
|
218e99 |
+/* this must come after including "trace.h" */
|
|
|
218e99 |
+#include <shlobj.h>
|
|
|
218e99 |
+
|
|
|
218e99 |
void *qemu_oom_check(void *ptr)
|
|
|
218e99 |
{
|
|
|
218e99 |
if (ptr == NULL) {
|
|
|
218e99 |
@@ -160,3 +165,20 @@ int qemu_get_thread_id(void)
|
|
|
218e99 |
{
|
|
|
218e99 |
return GetCurrentThreadId();
|
|
|
218e99 |
}
|
|
|
218e99 |
+
|
|
|
218e99 |
+char *
|
|
|
218e99 |
+qemu_get_local_state_pathname(const char *relative_pathname)
|
|
|
218e99 |
+{
|
|
|
218e99 |
+ HRESULT result;
|
|
|
218e99 |
+ char base_path[MAX_PATH+1] = "";
|
|
|
218e99 |
+
|
|
|
218e99 |
+ result = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL,
|
|
|
218e99 |
+ /* SHGFP_TYPE_CURRENT */ 0, base_path);
|
|
|
218e99 |
+ if (result != S_OK) {
|
|
|
218e99 |
+ /* misconfigured environment */
|
|
|
218e99 |
+ g_critical("CSIDL_COMMON_APPDATA unavailable: %ld", (long)result);
|
|
|
218e99 |
+ abort();
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", base_path,
|
|
|
218e99 |
+ relative_pathname);
|
|
|
218e99 |
+}
|
|
|
218e99 |
--
|
|
|
218e99 |
1.7.1
|
|
|
218e99 |
|