]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virfdstream: Use VIR_AUTOCLOSE()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 7 Jul 2020 12:39:22 +0000 (14:39 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 20 Aug 2020 12:02:33 +0000 (14:02 +0200)
Again, instead of closing FDs explicitly, we can automatically
close them when they go out of their respective scopes.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/util/virfdstream.c

index c85dee05c350c54f9b1432fa7f1dba14195744e9..b1a2bb71b4bbd6c85d5a2e25f89d5a9550bfdfe2 100644 (file)
@@ -571,9 +571,9 @@ virFDStreamThread(void *opaque)
     virStreamPtr st = data->st;
     size_t length = data->length;
     bool sparse = data->sparse;
-    int fdin = data->fdin;
+    VIR_AUTOCLOSE fdin = data->fdin;
     char *fdinname = data->fdinname;
-    int fdout = data->fdout;
+    VIR_AUTOCLOSE fdout = data->fdout;
     char *fdoutname = data->fdoutname;
     virFDStreamDataPtr fdst = st->privateData;
     bool doRead = fdst->threadDoRead;
@@ -633,8 +633,6 @@ virFDStreamThread(void *opaque)
     virObjectUnref(fdst);
     if (virFDStreamDataDisposed)
         st->privateData = NULL;
-    VIR_FORCE_CLOSE(fdin);
-    VIR_FORCE_CLOSE(fdout);
     virFDStreamThreadDataFree(data);
     return;
 
@@ -1160,9 +1158,10 @@ int virFDStreamConnectUNIX(virStreamPtr st,
 {
     struct sockaddr_un sa;
     virTimeBackOffVar timeout;
+    VIR_AUTOCLOSE fd = -1;
     int ret;
 
-    int fd = socket(AF_UNIX, SOCK_STREAM, 0);
+    fd = socket(AF_UNIX, SOCK_STREAM, 0);
     if (fd < 0) {
         virReportSystemError(errno, "%s", _("Unable to open UNIX socket"));
         goto error;
@@ -1197,10 +1196,11 @@ int virFDStreamConnectUNIX(virStreamPtr st,
 
     if (virFDStreamOpenInternal(st, fd, NULL, 0) < 0)
         goto error;
+    fd = -1;
+
     return 0;
 
  error:
-    VIR_FORCE_CLOSE(fd);
     return -1;
 }