[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/16] qga: use qemu_open_cloexec() for safe_open_or_create()
From: |
marcandre . lureau |
Subject: |
[PATCH 09/16] qga: use qemu_open_cloexec() for safe_open_or_create() |
Date: |
Wed, 4 May 2022 21:30:18 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
The function takes care of setting CLOEXEC, and reporting error.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
qga/commands-posix.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 98d481a58485..974bcbee7e97 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -370,21 +370,16 @@ safe_open_or_create(const char *path, const char *mode,
Error **errp)
* open() is decisive and its third argument is ignored, and the second
* open() and the fchmod() are never called.
*/
- fd = open(path, oflag | ((oflag & O_CREAT) ? O_EXCL : 0), 0);
+ fd = qemu_open_cloexec(path, oflag | ((oflag & O_CREAT) ? O_EXCL : 0), 0,
errp);
if (fd == -1 && errno == EEXIST) {
+ g_clear_pointer(errp, error_free);
oflag &= ~(unsigned)O_CREAT;
- fd = open(path, oflag);
+ fd = qemu_open_cloexec(path, oflag, 0, errp);
}
if (fd == -1) {
- error_setg_errno(errp, errno,
- "failed to open file '%s' "
- "(mode: '%s')",
- path, mode);
goto end;
}
- qemu_set_cloexec(fd);
-
if ((oflag & O_CREAT) && fchmod(fd, DEFAULT_NEW_FILE_MODE) == -1) {
error_setg_errno(errp, errno,
"failed to set permission "
--
2.36.0.44.g0f828332d5ac
- Re: [PATCH 02/16] util/win32: simplify qemu_get_local_state_dir(), (continued)
- [PATCH 03/16] tests: make libqmp buildable for win32, marcandre . lureau, 2022/05/04
- [PATCH 04/16] compiler.h: add QEMU_{BEGIN, END}_IGNORE_INITIALIZER_OVERRIDES, marcandre . lureau, 2022/05/04
- [PATCH 05/16] qobject/json-lexer: disable -Winitializer-overrides warnings, marcandre . lureau, 2022/05/04
- [PATCH 06/16] include: adjust header guards after renaming, marcandre . lureau, 2022/05/04
- [PATCH 07/16] qga: flatten safe_open_or_create(), marcandre . lureau, 2022/05/04
- [PATCH 09/16] qga: use qemu_open_cloexec() for safe_open_or_create(),
marcandre . lureau <=
- [PATCH 08/16] osdep: export qemu_open_cloexec(), marcandre . lureau, 2022/05/04
- [PATCH 10/16] qapi/error: add g_autoptr(Error) support, marcandre . lureau, 2022/05/04
- [PATCH 11/16] qga: replace qemu_open_old() with qemu_open_cloexec(), marcandre . lureau, 2022/05/04
- [PATCH 12/16] test/qga: use G_TEST_DIR to locate os-release test file, marcandre . lureau, 2022/05/04
- [PATCH 13/16] qga/wixl: prefer variables over environment, marcandre . lureau, 2022/05/04
- [PATCH 14/16] qga/wixl: require Mingw_bin, marcandre . lureau, 2022/05/04
- [PATCH 15/16] qga/wixl: simplify some pre-processing, marcandre . lureau, 2022/05/04
- [PATCH 16/16] qga/wixl: replace QEMU_GA_MSI_MINGW_BIN_PATH with glib bindir, marcandre . lureau, 2022/05/04
- Re: [PATCH 00/16] Misc cleanups, Paolo Bonzini, 2022/05/05