[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/3] osdep: Add qemu_mkdir_with_parents()
From: |
Peter Xu |
Subject: |
[PATCH 1/3] osdep: Add qemu_mkdir_with_parents() |
Date: |
Mon, 16 Dec 2024 11:14:11 -0500 |
QEMU uses g_mkdir_with_parents() a lot, especially in the case where the
failure case is ignored so an abort is expected when happened.
Provide a helper qemu_mkdir_with_parents() to do that, and use it in the
two cases in qga/. To be used in more places later.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
include/qemu/osdep.h | 7 +++++++
qga/commands-posix-ssh.c | 8 ++------
util/osdep.c | 6 ++++++
3 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index fdff07fd99..dc67fb2e5e 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -828,6 +828,13 @@ static inline int platform_does_not_support_system(const
char *command)
}
#endif /* !HAVE_SYSTEM_FUNCTION */
+/**
+ * qemu_mkdir_with_parents:
+ *
+ * Create directories with parents. Abort on failures.
+ */
+void qemu_mkdir_with_parents(const char *dir, int mode);
+
#ifdef __cplusplus
}
#endif
diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c
index 246171d323..a39abcbaa5 100644
--- a/qga/commands-posix-ssh.c
+++ b/qga/commands-posix-ssh.c
@@ -18,7 +18,6 @@ static struct passwd *
test_get_passwd_entry(const gchar *user_name, GError **error)
{
struct passwd *p;
- int ret;
if (!user_name || g_strcmp0(user_name, g_get_user_name())) {
g_set_error(error, G_UNIX_ERROR, 0, "Invalid user name");
@@ -30,8 +29,7 @@ test_get_passwd_entry(const gchar *user_name, GError **error)
p->pw_uid = geteuid();
p->pw_gid = getegid();
- ret = g_mkdir_with_parents(p->pw_dir, 0700);
- g_assert(ret == 0);
+ qemu_mkdir_with_parents(p->pw_dir, 0700);
return p;
}
@@ -263,11 +261,9 @@ test_authorized_keys_set(const char *contents)
{
g_autoptr(GError) err = NULL;
g_autofree char *path = NULL;
- int ret;
path = g_build_filename(g_get_home_dir(), ".ssh", NULL);
- ret = g_mkdir_with_parents(path, 0700);
- g_assert(ret == 0);
+ qemu_mkdir_with_parents(path, 0700);
g_free(path);
path = test_get_authorized_keys_path();
diff --git a/util/osdep.c b/util/osdep.c
index 770369831b..3a724c1814 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -613,3 +613,9 @@ int qemu_fdatasync(int fd)
return fsync(fd);
#endif
}
+
+void qemu_mkdir_with_parents(const char *dir, int mode)
+{
+ int ret = g_mkdir_with_parents(dir, 0700);
+ g_assert(ret == 0);
+}
--
2.47.0
[PATCH 2/3] tests: Use qemu_mkdir_with_parents() for all test code, Peter Xu, 2024/12/16
[PATCH 3/3] tests/migration: Drop arch_[source|target], Peter Xu, 2024/12/16