]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: use VIR_AUTOCLOSE
authorJán Tomko <jtomko@redhat.com>
Sat, 4 Sep 2021 18:45:22 +0000 (20:45 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 9 Sep 2021 16:06:13 +0000 (18:06 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
tests/fdstreamtest.c
tests/scsihosttest.c
tests/virfiletest.c
tests/virnettlshelpers.c
tests/virpcimock.c
tests/virrotatingfiletest.c

index 182c853b332fc063c35f8f2cf8ce1cee6865644e..96519e91c28ddd115d055c6902f2db956d2b7e90 100644 (file)
@@ -38,7 +38,7 @@ VIR_LOG_INIT("tests.fdstreamtest");
 
 static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
 {
-    int fd = -1;
+    VIR_AUTOCLOSE fd = -1;
     g_autofree char *file = NULL;
     int ret = -1;
     g_autofree char *pattern = NULL;
@@ -144,7 +144,6 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
  cleanup:
     if (st)
         virStreamFree(st);
-    VIR_FORCE_CLOSE(fd);
     if (file != NULL)
         unlink(file);
     if (conn)
@@ -165,7 +164,7 @@ static int testFDStreamReadNonblock(const void *data)
 
 static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
 {
-    int fd = -1;
+    VIR_AUTOCLOSE fd = -1;
     g_autofree char *file = NULL;
     int ret = -1;
     g_autofree char *pattern = NULL;
@@ -284,7 +283,6 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
  cleanup:
     if (st)
         virStreamFree(st);
-    VIR_FORCE_CLOSE(fd);
     if (file != NULL)
         unlink(file);
     if (conn)
index 336b3cc4964c294675c60e7582ff7e7623256be0..aeb91da691cbdc954d73af809a6aa4d242ef296b 100644 (file)
@@ -71,7 +71,7 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
     g_autofree char *link_path = NULL;
     char *spot;
     int ret = -1;
-    int fd = -1;
+    VIR_AUTOCLOSE fd = -1;
 
     unique_id_path = g_strdup_printf("%s/devices/pci0000:00/%s/unique_id",
                                      fakesysfsdir, devicepath);
@@ -136,7 +136,6 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
     ret = 0;
 
  cleanup:
-    VIR_FORCE_CLOSE(fd);
     return ret;
 }
 
index 019c230cea6cc6147298a30cf43589d7665e8323..a6e722b4d2889ca586a5b5969e682893d5644097 100644 (file)
@@ -194,7 +194,7 @@ holesSupported(void)
 {
     off_t offsets[] = {EXTENT, EXTENT, EXTENT, -1};
     off_t tmp;
-    int fd;
+    VIR_AUTOCLOSE fd = -1;
     bool ret = false;
 
     if ((fd = makeSparseFile(offsets, true)) < 0)
@@ -229,7 +229,6 @@ holesSupported(void)
 
     ret = true;
  cleanup:
-    VIR_FORCE_CLOSE(fd);
     return ret;
 }
 
@@ -261,7 +260,7 @@ static int
 testFileInData(const void *opaque)
 {
     const struct testFileInData *data = opaque;
-    int fd = -1;
+    VIR_AUTOCLOSE fd = -1;
     int ret = -1;
     size_t i;
 
@@ -303,7 +302,6 @@ testFileInData(const void *opaque)
     ret = 0;
 
  cleanup:
-    VIR_FORCE_CLOSE(fd);
     return ret;
 }
 
index 905e633e6088e56826e0acbb2f5f5154355ea8b2..c9e2b372bb8c4ea42a645197b0f370ddccfb1bc4 100644 (file)
@@ -396,7 +396,7 @@ void testTLSWriteCertChain(const char *filename,
                            size_t ncerts)
 {
     size_t i;
-    int fd;
+    VIR_AUTOCLOSE fd = -1;
     int err;
     static char buffer[1024*1024];
     size_t size;
@@ -420,8 +420,6 @@ void testTLSWriteCertChain(const char *filename,
             abort();
         }
     }
-
-    VIR_FORCE_CLOSE(fd);
 }
 
 
index ead810d412e915b4b86e42321fc2389db03d9875..d4d43aac51ce40fd8c1493bef0202b72e1e2c11b 100644 (file)
@@ -177,7 +177,7 @@ make_file(const char *path,
           const char *value,
           ssize_t len)
 {
-    int fd = -1;
+    VIR_AUTOCLOSE fd = -1;
     g_autofree char *filepath = NULL;
     if (value && len == -1)
         len = strlen(value);
@@ -189,8 +189,6 @@ make_file(const char *path,
 
     if (value && safewrite(fd, value, len) != len)
         ABORT("Unable to write: %s", filepath);
-
-    VIR_FORCE_CLOSE(fd);
 }
 
 static void
index 87699936cb9d1f1614bddb1017cb5304b680f52a..ede65848ea541d6b5e69fc5665b91dd7554fdfcb 100644 (file)
@@ -125,7 +125,7 @@ static int testRotatingFileInitOne(const char *filename,
         unlink(filename);
     } else {
         char buf[1024];
-        int fd;
+        VIR_AUTOCLOSE fd = -1;
 
         VIR_DEBUG("Creating %s size %zu", filename, (size_t)size);
 
@@ -142,12 +142,10 @@ static int testRotatingFileInitOne(const char *filename,
 
             if (safewrite(fd, buf, towrite) != towrite) {
                 fprintf(stderr, "Cannot write to %s\n", filename);
-                VIR_FORCE_CLOSE(fd);
                 return -1;
             }
             size -= towrite;
         }
-        VIR_FORCE_CLOSE(fd);
     }
     return 0;
 }