]> xenbits.xensource.com Git - libvirt.git/commitdiff
lxc: virLXCProcessReadLogOutput: Automatically close FD
authorPeter Krempa <pkrempa@redhat.com>
Mon, 5 Sep 2022 12:49:49 +0000 (14:49 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 9 Sep 2022 14:11:06 +0000 (16:11 +0200)
Switch to 'VIR_AUTOCLOSE' to simplify cleanup.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/lxc/lxc_process.c

index fe5cab3df6980c739f3d980efa82093f0562d18b..39dcf53c67c7016ddd94203162990f47f8924a51 100644 (file)
@@ -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);
 }