aboutsummaryrefslogtreecommitdiff
path: root/util/oslib-posix.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2020-08-18 12:00:59 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2020-09-30 19:11:36 +0200
commit9386a4a7150fe11690af1897cf28c206c54cde9c (patch)
tree72a0dc762a33cdf398b53cb4f36490759bf0ea13 /util/oslib-posix.c
parentec986777accd688c1b7159778c9cc729e54a87f4 (diff)
downloadqemu-9386a4a7150fe11690af1897cf28c206c54cde9c.zip
qemu-9386a4a7150fe11690af1897cf28c206c54cde9c.tar.gz
qemu-9386a4a7150fe11690af1897cf28c206c54cde9c.tar.bz2
oslib-posix: default exec_dir to bindir
If the exec_dir cannot be retrieved, just assume it's the installation directory that was specified at configure time. This makes it simpler to reason about what the callers will do if they get back an empty path. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util/oslib-posix.c')
-rw-r--r--util/oslib-posix.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 18531fc..1739930 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -358,15 +358,14 @@ void qemu_set_tty_echo(int fd, bool echo)
tcsetattr(fd, TCSANOW, &tty);
}
-static char exec_dir[PATH_MAX];
+static const char *exec_dir;
void qemu_init_exec_dir(const char *argv0)
{
- char *dir;
char *p = NULL;
char buf[PATH_MAX];
- if (exec_dir[0]) {
+ if (exec_dir) {
return;
}
@@ -425,20 +424,14 @@ void qemu_init_exec_dir(const char *argv0)
#endif
/* If we don't have any way of figuring out the actual executable
location then try argv[0]. */
- if (!p) {
- if (!argv0) {
- return;
- }
+ if (!p && argv0) {
p = realpath(argv0, buf);
- if (!p) {
- return;
- }
}
- dir = g_path_get_dirname(p);
-
- pstrcpy(exec_dir, sizeof(exec_dir), dir);
-
- g_free(dir);
+ if (p) {
+ exec_dir = g_path_get_dirname(p);
+ } else {
+ exec_dir = CONFIG_BINDIR;
+ }
}
const char *qemu_get_exec_dir(void)