From 68d5617c3c4a8112c67da0f61335a3d958e91a54 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 5 Sep 2022 14:49:49 +0200 Subject: [PATCH] lxc: virLXCProcessReadLogOutput: Automatically close FD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch to 'VIR_AUTOCLOSE' to simplify cleanup. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/lxc/lxc_process.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index fe5cab3df6..39dcf53c67 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1076,8 +1076,7 @@ virLXCProcessReadLogOutput(virDomainObj *vm, char *buf, size_t buflen) { - int fd = -1; - int ret; + VIR_AUTOCLOSE fd = -1; if ((fd = open(logfile, O_RDONLY)) < 0) { virReportSystemError(errno, @@ -1090,17 +1089,10 @@ virLXCProcessReadLogOutput(virDomainObj *vm, virReportSystemError(errno, _("Unable to seek log file %s to %llu"), logfile, (unsigned long long)pos); - VIR_FORCE_CLOSE(fd); return -1; } - ret = virLXCProcessReadLogOutputData(vm, - fd, - buf, - buflen); - - VIR_FORCE_CLOSE(fd); - return ret; + return virLXCProcessReadLogOutputData(vm, fd, buf, buflen); }