]> xenbits.xensource.com Git - libvirt.git/commitdiff
Use g_mkstemp_full instead of mkostemp(s)
authorJán Tomko <jtomko@redhat.com>
Wed, 13 Nov 2019 21:30:26 +0000 (22:30 +0100)
committerJán Tomko <jtomko@redhat.com>
Thu, 14 Nov 2019 18:02:31 +0000 (19:02 +0100)
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@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_driver.c
src/storage/storage_driver.c
src/storage/storage_util.c
src/util/virlog.c
src/vbox/vbox_common.c
tests/virfiletest.c
tools/vsh.c

index b648386ac93abca96403f0949a4483066d51be93..bb75fe5807d5518e7e586bab197178d71b8c32b3 100644 (file)
@@ -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;
@@ -11970,9 +11970,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;
     }
 
index 04e4abcd6a587a42f9cc94bd628ed4bce866aac9..d8355d3c3cf4d2a4bca604e89e02865c783e5da4 100644 (file)
@@ -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
  */
index 9ba9bb2a57db8bc3a6cb86ce85a7b9bd78af1d86..7c17d395096bd35d62496ad22273909537880d86 100644 (file)
@@ -1215,7 +1215,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;
index 47e77e63b7fd3cf49ae039d5642c344ffcaaf95d..05052e9d09768a8ae7e3f88a882a6ffaee90b1f5 100644 (file)
@@ -992,13 +992,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)
index 0bd47e3ddb89edb922a3e3f0ddd3b5923dd28208..043c26b9f67875635386e37b38d16b49228c683b 100644 (file)
@@ -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;
index c7d5f6abeba40ba5d9faded3178454930b178407..193c5bedd4840f08ee32a60f8b284b4d66372991 100644 (file)
@@ -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)
index 000cf6a009b43386cc98b8cb00d2329bf3edf4dd..d4a16acc03a52d09fd3916e096f3063176187e72 100644 (file)
@@ -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_full: failed to create temporary file: %s"),
                  virStrerror(errno, ebuf, sizeof(ebuf)));
         VIR_FREE(ret);
         return NULL;