mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
tests: use VIR_AUTOCLOSE
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
ca24cb1e9b
commit
e4756024ee
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user