Re: [PATCH] bye to close(), welcome to VIR_(FORCE_)CLOSE()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/22/2010 05:19 AM, Stefan Berger wrote:
Using automated replacement with sed and editing I have now replaced all
occurrences of close() with VIR_(FORCE_)CLOSE() except for one, of
course. Some replacements were straight forward, others I needed to pay
attention. I hope I payed attention in all the right places... Please
have a look. This should have at least solved one more double-close
error.

Signed-off-by: Stefan Berger<stefanb@xxxxxxxxxx>

---
  daemon/libvirtd.c                         |   46 ++++++---------

Continuing on (looks like I'll be replying quite a few times today)...

@@ -127,7 +128,7 @@ static int lxcContainerExecInit(virDomai
  static int lxcContainerSetStdio(int control, int ttyfd)
  {
      int rc = -1;
-    int open_max, i;
+    int open_max, i, tpmfd;

      if (setsid()<  0) {
          virReportSystemError(errno, "%s",
@@ -145,8 +146,10 @@ static int lxcContainerSetStdio(int cont
       * close all FDs before executing the container */
      open_max = sysconf (_SC_OPEN_MAX);
      for (i = 0; i<  open_max; i++)
-        if (i != ttyfd&&  i != control)
-            close(i);
+        if (i != ttyfd&&  i != control) {
+            tpmfd = i;
+            VIR_FORCE_CLOSE(tpmfd);

Yeah, I guess you do have to introduce a temporary rather than clobbering your iterator.

s/tpmfd/tmpfd/, and perhaps reduce it's scope to just the for loop or if statement where it is needed.

Index: libvirt-acl/src/lxc/lxc_driver.c
===================================================================
--- libvirt-acl.orig/src/lxc/lxc_driver.c
+++ libvirt-acl/src/lxc/lxc_driver.c
@@ -1544,14 +1544,10 @@ cleanup:
              vethDelete(veths[i]);
          VIR_FREE(veths[i]);
      }
-    if (rc != 0&&  priv->monitor != -1) {
-        close(priv->monitor);
-        priv->monitor = -1;
-    }
-    if (parentTty != -1)
-        close(parentTty);
-    if (logfd != -1)
-        close(logfd);
+    if (rc != 0)
+        VIR_FORCE_CLOSE(priv->monitor);
+    VIR_FORCE_CLOSE(parentTty);
+    VIR_FORCE_CLOSE(logfd);

logfd might be one where we want to hoist a normal VIR_CLOSE and check for errors.

Index: libvirt-acl/src/phyp/phyp_driver.c

Pausing here for my lunch...

--
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]