From: Peter Krempa Date: Mon, 5 Sep 2022 12:49:49 +0000 (+0200) Subject: lxc: virLXCProcessReadLogOutput: Automatically close FD X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=68d5617c3c4a8112c67da0f61335a3d958e91a54;p=libvirt.git lxc: virLXCProcessReadLogOutput: Automatically close FD Switch to 'VIR_AUTOCLOSE' to simplify cleanup. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- 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); }