[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 46/92] vl: relocate paths to data directories
From: |
Paolo Bonzini |
Subject: |
[PULL 46/92] vl: relocate paths to data directories |
Date: |
Thu, 24 Sep 2020 05:22:28 -0400 |
As an additional advantage, the logic is now unified between
POSIX and Win32 systems.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/qemu-common.h | 1 -
include/sysemu/sysemu.h | 2 +-
os-posix.c | 20 --------------------
os-win32.c | 11 -----------
softmmu/vl.c | 40 ++++++++++++++++++++++++++++------------
tests/qtest/fuzz/fuzz.c | 5 +++--
6 files changed, 32 insertions(+), 47 deletions(-)
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 9cfd62669b..a9b11f59c4 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -131,7 +131,6 @@ char *qemu_find_file(int type, const char *name);
/* OS specific functions */
void os_setup_early_signal_handling(void);
-char *os_find_datadir(void);
int os_parse_cmd_args(int index, const char *optarg);
/*
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 4b6a5c459c..817ff4cf75 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -14,7 +14,7 @@ extern const char *qemu_name;
extern QemuUUID qemu_uuid;
extern bool qemu_uuid_set;
-void qemu_add_data_dir(const char *path);
+void qemu_add_data_dir(char *path);
void qemu_add_exit_notifier(Notifier *notify);
void qemu_remove_exit_notifier(Notifier *notify);
diff --git a/os-posix.c b/os-posix.c
index 36e344c544..1de2839554 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -80,26 +80,6 @@ void os_setup_signal_handling(void)
sigaction(SIGTERM, &act, NULL);
}
-/*
- * Find a likely location for support files using the location of the binary.
- * When running from the build tree this will be "$bindir/pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR.
- *
- * The caller must use g_free() to free the returned data when it is
- * no longer required.
- */
-char *os_find_datadir(void)
-{
- g_autofree char *dir = NULL;
-
- dir = g_build_filename(qemu_get_exec_dir(), "pc-bios", NULL);
- if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
- return g_steal_pointer(&dir);
- }
-
- return g_strdup(CONFIG_QEMU_DATADIR);
-}
-
void os_set_proc_name(const char *s)
{
#if defined(PR_SET_NAME)
diff --git a/os-win32.c b/os-win32.c
index eb8501b9e5..fd1137bab1 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -57,17 +57,6 @@ void os_setup_early_signal_handling(void)
atexit(os_undo_timer_resolution);
}
-/*
- * Look for support files in the same directory as the executable.
- *
- * The caller must use g_free() to free the returned data when it is
- * no longer required.
- */
-char *os_find_datadir(void)
-{
- return g_strdup(qemu_get_exec_dir());
-}
-
void os_set_line_buffering(void)
{
setbuf(stdout, NULL);
diff --git a/softmmu/vl.c b/softmmu/vl.c
index f7b103467c..c872657e60 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2005,7 +2005,7 @@ char *qemu_find_file(int type, const char *name)
return NULL;
}
-void qemu_add_data_dir(const char *path)
+void qemu_add_data_dir(char *path)
{
int i;
@@ -2017,10 +2017,11 @@ void qemu_add_data_dir(const char *path)
}
for (i = 0; i < data_dir_idx; i++) {
if (strcmp(data_dir[i], path) == 0) {
- return; /* duplicate */
+ g_free(path); /* duplicate */
+ return;
}
}
- data_dir[data_dir_idx++] = g_strdup(path);
+ data_dir[data_dir_idx++] = path;
}
static inline bool nonempty_str(const char *str)
@@ -2829,6 +2830,26 @@ static void create_default_memdev(MachineState *ms,
const char *path)
&error_fatal);
}
+/*
+ * Find a likely location for support files using the location of the binary.
+ * When running from the build tree this will be "$bindir/pc-bios".
+ * Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated).
+ *
+ * The caller must use g_free() to free the returned data when it is
+ * no longer required.
+ */
+static char *find_datadir(void)
+{
+ g_autofree char *dir = NULL;
+
+ dir = g_build_filename(qemu_get_exec_dir(), "pc-bios", NULL);
+ if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+ return g_steal_pointer(&dir);
+ }
+
+ return get_relocated_path(CONFIG_QEMU_DATADIR);
+}
+
void qemu_init(int argc, char **argv, char **envp)
{
int i;
@@ -2862,7 +2883,7 @@ void qemu_init(int argc, char **argv, char **envp)
Error *main_loop_err = NULL;
Error *err = NULL;
bool list_data_dirs = false;
- char *dir, **dirs;
+ char **dirs;
const char *mem_path = NULL;
bool have_custom_ram_size;
BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
@@ -3195,7 +3216,7 @@ void qemu_init(int argc, char **argv, char **envp)
if (is_help_option(optarg)) {
list_data_dirs = true;
} else {
- qemu_add_data_dir(optarg);
+ qemu_add_data_dir(g_strdup(optarg));
}
break;
case QEMU_OPTION_bios:
@@ -3927,17 +3948,12 @@ void qemu_init(int argc, char **argv, char **envp)
/* add configured firmware directories */
dirs = g_strsplit(CONFIG_QEMU_FIRMWAREPATH, G_SEARCHPATH_SEPARATOR_S, 0);
for (i = 0; dirs[i] != NULL; i++) {
- qemu_add_data_dir(dirs[i]);
+ qemu_add_data_dir(get_relocated_path(dirs[i]));
}
g_strfreev(dirs);
/* try to find datadir relative to the executable path */
- dir = os_find_datadir();
- qemu_add_data_dir(dir);
- g_free(dir);
-
- /* add the datadir specified when building */
- qemu_add_data_dir(CONFIG_QEMU_DATADIR);
+ qemu_add_data_dir(find_datadir());
/* -L help lists the data directories and exits. */
if (list_data_dirs) {
diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c
index c4dc5fa629..d926c490c5 100644
--- a/tests/qtest/fuzz/fuzz.c
+++ b/tests/qtest/fuzz/fuzz.c
@@ -170,8 +170,9 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char
***envp)
datadir = g_build_filename(bindir, "pc-bios", NULL);
if (g_file_test(datadir, G_FILE_TEST_IS_DIR)) {
qemu_add_data_dir(datadir);
- }
- g_free(datadir);
+ } else {
+ g_free(datadir);
+ }
} else if (*argc > 1) { /* The target is specified as an argument */
target_name = (*argv)[1];
if (!strstr(target_name, "--fuzz-target=")) {
--
2.26.2
- [PULL 33/92] configure: fix --meson=/path/to/meson, (continued)
- [PULL 33/92] configure: fix --meson=/path/to/meson, Paolo Bonzini, 2020/09/24
- [PULL 32/92] configure: move malloc_trim/tcmalloc/jemalloc to meson, Paolo Bonzini, 2020/09/24
- [PULL 26/92] hw: megasas: return -1 when 'megasas_map_sgl' fails, Paolo Bonzini, 2020/09/24
- [PULL 35/92] configure: do not limit Hypervisor.framework test to Darwin, Paolo Bonzini, 2020/09/24
- [PULL 24/92] hw/char/serial-{isa, pci}: Alias QDEV properties from generic serial object, Paolo Bonzini, 2020/09/24
- [PULL 41/92] oslib-posix: default exec_dir to bindir, Paolo Bonzini, 2020/09/24
- [PULL 36/92] meson: qtest: set "depends" correctly, Paolo Bonzini, 2020/09/24
- [PULL 38/92] meson: report accelerator support, Paolo Bonzini, 2020/09/24
- [PULL 37/92] mtest2make: add support for introspected test dependencies, Paolo Bonzini, 2020/09/24
- [PULL 39/92] oslib: do not call g_strdup from qemu_get_exec_dir, Paolo Bonzini, 2020/09/24
- [PULL 46/92] vl: relocate paths to data directories,
Paolo Bonzini <=
- [PULL 34/92] configure: move cocoa option to Meson, Paolo Bonzini, 2020/09/24
- [PULL 40/92] fuzz: use qemu_get_exec_dir, Paolo Bonzini, 2020/09/24
- [PULL 42/92] cutils: introduce get_relocated_path, Paolo Bonzini, 2020/09/24
- [PULL 44/92] module: relocate path to modules, Paolo Bonzini, 2020/09/24
- [PULL 51/92] configure: use a platform-neutral prefix, Paolo Bonzini, 2020/09/24
- [PULL 50/92] ui: relocate paths to icons and translations, Paolo Bonzini, 2020/09/24
- [PULL 48/92] qemu-bridge-helper: relocate path to default ACL, Paolo Bonzini, 2020/09/24
- [PULL 52/92] hw/i386/q35: Remove unreachable Xen code on Q35 machine, Paolo Bonzini, 2020/09/24
- [PULL 43/92] oslib-posix: relocate path to /var, Paolo Bonzini, 2020/09/24
- [PULL 47/92] vl: relocate path to configuration file, Paolo Bonzini, 2020/09/24