With g_mkstemp_full, there is no need to distinguish between
mkostemp and mkostemps (no suffix vs. a suffix of a fixed length),
because the GLib function looks for the XXXXXX pattern everywhere
in the string.
Use S_IRUSR | S_IWUSR for the permissions and do not pass O_RDWR
in flags since it's implied.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/qemu/qemu_driver.c | 8 ++++----
src/storage/storage_driver.c | 2 +-
src/storage/storage_util.c | 2 +-
src/util/virlog.c | 8 +-------
src/vbox/vbox_common.c | 4 ++--
tests/virfiletest.c | 2 +-
tools/vsh.c | 4 ++--
7 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 159a6dc464..a9364dc7e3 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4024,8 +4024,8 @@ qemuDomainScreenshot(virDomainPtr dom,
if (!(tmp = g_strdup_printf("%s/qemu.screendump.XXXXXX",
cfg->cacheDir)))
goto endjob;
- if ((tmp_fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
- virReportSystemError(errno, _("mkostemp(\"%s\") failed"),
tmp);
+ if ((tmp_fd = g_mkstemp_full(tmp, O_CLOEXEC, S_IRUSR | S_IWUSR)) == -1) {
+ virReportSystemError(errno, _("g_mkstemp(\"%s\") failed"),
tmp);
goto endjob;
}
unlink_tmp = true;
@@ -11963,9 +11963,9 @@ qemuDomainMemoryPeek(virDomainPtr dom,
goto endjob;
/* Create a temporary filename. */
- if ((fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
+ if ((fd = g_mkstemp_full(tmp, O_CLOEXEC, S_IRUSR | S_IWUSR)) == -1) {
virReportSystemError(errno,
- _("mkostemp(\"%s\") failed"), tmp);
+ _("g_mkstemp(\"%s\") failed"), tmp);
goto endjob;
}
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 04e4abcd6a..d8355d3c3c 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2825,7 +2825,7 @@ virStoragePoolObjFindPoolByUUID(const unsigned char *uuid)
*
* Generate a name for a temporary file using the driver stateDir
* as a path, the pool name, and the volume name to be used as input
- * for a mkostemp
+ * for mkstemp
*
* Returns a string pointer on success, NULL on failure
*/
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index f91c2c64ee..8cc308e12d 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -1216,7 +1216,7 @@ storageBackendCreateQemuImgSecretPath(virStoragePoolObjPtr pool,
if (!(secretPath = virStoragePoolObjBuildTempFilePath(pool, vol)))
goto cleanup;
- if ((fd = mkostemp(secretPath, O_CLOEXEC)) < 0) {
+ if ((fd = g_mkstemp_full(secretPath, O_CLOEXEC, S_IRUSR | S_IWUSR)) < 0) {
virReportSystemError(errno, "%s",
_("failed to open secret file for write"));
goto error;
diff --git a/src/util/virlog.c b/src/util/virlog.c
index b3460d85fe..dcb287f146 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -996,13 +996,7 @@ virLogOutputToJournald(virLogSourcePtr source,
* and pass an FD to the journal
*/
- /* NB: mkostemp is not declared async signal safe by
- * POSIX, but this is Linux only code and the GLibc
- * impl is safe enough, only using open() and inline
- * asm to read a timestamp (falling back to gettimeofday
- * on some arches
- */
- if ((buffd = mkostemp(path, O_CLOEXEC|O_RDWR)) < 0)
+ if ((buffd = g_mkstemp_full(path, O_CLOEXEC, S_IRUSR | S_IWUSR)) < 0)
return;
if (unlink(path) < 0)
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 0bd47e3ddb..043c26b9f6 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -7385,8 +7385,8 @@ vboxDomainScreenshot(virDomainPtr dom,
tmp = g_strdup_printf("%s/vbox.screendump.XXXXXX", cacheDir);
- if ((tmp_fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
- virReportSystemError(errno, _("mkostemp(\"%s\") failed"),
tmp);
+ if ((tmp_fd = g_mkstemp_full(tmp, O_CLOEXEC, S_IRUSR | S_IWUSR)) == -1) {
+ virReportSystemError(errno, _("g_mkstemp(\"%s\") failed"),
tmp);
VIR_FREE(tmp);
VBOX_RELEASE(machine);
return NULL;
diff --git a/tests/virfiletest.c b/tests/virfiletest.c
index c7d5f6abeb..193c5bedd4 100644
--- a/tests/virfiletest.c
+++ b/tests/virfiletest.c
@@ -133,7 +133,7 @@ makeSparseFile(const off_t offsets[],
off_t len = 0;
size_t i;
- if ((fd = mkostemp(path, O_CLOEXEC|O_RDWR)) < 0)
+ if ((fd = g_mkstemp_full(path, O_CLOEXEC, S_IRUSR | S_IWUSR)) < 0)
goto error;
if (unlink(path) < 0)
diff --git a/tools/vsh.c b/tools/vsh.c
index 000cf6a009..e851303e69 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2400,9 +2400,9 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc)
tmpdir = getenv("TMPDIR");
if (!tmpdir) tmpdir = "/tmp";
ret = g_strdup_printf("%s/virshXXXXXX.xml", tmpdir);
- fd = mkostemps(ret, 4, O_CLOEXEC);
+ fd = g_mkstemp_full(ret, O_CLOEXEC, S_IRUSR | S_IWUSR);
if (fd == -1) {
- vshError(ctl, _("mkostemps: failed to create temporary file: %s"),
+ vshError(ctl, _("g_mkstemp: failed to create temporary file: %s"),
virStrerror(errno, ebuf, sizeof(ebuf)));
VIR_FREE(ret);
return NULL;
--
2.21.0