[libvirt PATCH 15/24] tests: use VIR_AUTOCLOSE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 tests/fdstreamtest.c        | 6 ++----
 tests/scsihosttest.c        | 3 +--
 tests/virfiletest.c         | 6 ++----
 tests/virnettlshelpers.c    | 4 +---
 tests/virpcimock.c          | 4 +---
 tests/virrotatingfiletest.c | 4 +---
 6 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c
index 182c853b33..96519e91c2 100644
--- a/tests/fdstreamtest.c
+++ b/tests/fdstreamtest.c
@@ -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)
diff --git a/tests/scsihosttest.c b/tests/scsihosttest.c
index 336b3cc496..aeb91da691 100644
--- a/tests/scsihosttest.c
+++ b/tests/scsihosttest.c
@@ -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;
 }
 
diff --git a/tests/virfiletest.c b/tests/virfiletest.c
index 019c230cea..a6e722b4d2 100644
--- a/tests/virfiletest.c
+++ b/tests/virfiletest.c
@@ -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;
 }
 
diff --git a/tests/virnettlshelpers.c b/tests/virnettlshelpers.c
index 905e633e60..c9e2b372bb 100644
--- a/tests/virnettlshelpers.c
+++ b/tests/virnettlshelpers.c
@@ -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);
 }
 
 
diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index ead810d412..d4d43aac51 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -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
diff --git a/tests/virrotatingfiletest.c b/tests/virrotatingfiletest.c
index 87699936cb..ede65848ea 100644
--- a/tests/virrotatingfiletest.c
+++ b/tests/virrotatingfiletest.c
@@ -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;
 }
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux