]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Use VIR_AUTOCLOSE more
authorMichal Privoznik <mprivozn@redhat.com>
Sun, 26 Sep 2021 10:54:10 +0000 (12:54 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 6 Oct 2021 07:28:19 +0000 (09:28 +0200)
There are few places where we can replace explicit
VIR_FORCE_CLOSE() with VIR_AUTOCLOSE annotation.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
tools/virsh-domain.c
tools/virsh-volume.c
tools/vsh.c

index db3f1b41c1fe79a913ed859593957be5ace306a1..dbddefb4a511c2dace03f063600ec83030672ca7 100644 (file)
@@ -5539,7 +5539,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
     g_autoptr(virshDomain) dom = NULL;
     const char *name = NULL;
     char *file = NULL;
-    int fd = -1;
+    VIR_AUTOCLOSE fd = -1;
     g_autoptr(virshStream) st = NULL;
     unsigned int screen = 0;
     unsigned int flags = 0; /* currently unused */
@@ -5610,7 +5610,6 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
         unlink(file);
     if (generated)
         VIR_FREE(file);
-    VIR_FORCE_CLOSE(fd);
     VIR_FREE(mime);
     return ret;
 }
index 70b6eac687baf6501df0f4e5f29122a7b4c92501..4c8e841701b382858bd60eff3e7e5fc79857eabe 100644 (file)
@@ -655,7 +655,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
     const char *file = NULL;
     g_autoptr(virshStorageVol) vol = NULL;
     bool ret = false;
-    int fd = -1;
+    VIR_AUTOCLOSE fd = -1;
     g_autoptr(virshStream) st = NULL;
     const char *name = NULL;
     unsigned long long offset = 0, length = 0;
@@ -731,7 +731,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
     ret = true;
 
  cleanup:
-    VIR_FORCE_CLOSE(fd);
     return ret;
 }
 
@@ -773,7 +772,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
     const char *file = NULL;
     g_autoptr(virshStorageVol) vol = NULL;
     bool ret = false;
-    int fd = -1;
+    VIR_AUTOCLOSE fd = -1;
     g_autoptr(virshStream) st = NULL;
     const char *name = NULL;
     unsigned long long offset = 0, length = 0;
@@ -846,7 +845,6 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
     ret = true;
 
  cleanup:
-    VIR_FORCE_CLOSE(fd);
     if (!ret && created)
         unlink(file);
     return ret;
index 7b77acad340d9bd9f6762684d6d757d00d2b9d4a..ecb591fb63ffd99f921e5bfbdaab9950bf7aaba7 100644 (file)
@@ -2388,7 +2388,7 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc)
 {
     g_autofree char *ret = NULL;
     const char *tmpdir;
-    int fd;
+    VIR_AUTOCLOSE fd = -1;
 
     tmpdir = getenv("TMPDIR");
     if (!tmpdir) tmpdir = "/tmp";
@@ -2403,7 +2403,6 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc)
     if (safewrite(fd, doc, strlen(doc)) == -1) {
         vshError(ctl, _("write: %s: failed to write to temporary file: %s"),
                  ret, g_strerror(errno));
-        VIR_FORCE_CLOSE(fd);
         unlink(ret);
         return NULL;
     }