[libvirt] [PATCH] lxc: use common code for process cleanup

Eric Blake eblake at redhat.com
Thu Nov 3 14:45:45 UTC 2011


Based on a Coverity report - the return value of waitpid() should
always be checked, to avoid problems with leaking resources.

* src/lxc/lxc_controller.c (lxcControllerRun): Use simpler virPidAbort.
---

Daniel previously said to wait until after the lxc multi-console
patches were in before visiting this file; but now that those are
in, this fix is still applicable:
https://www.redhat.com/archives/libvir-list/2011-October/msg01083.html

 src/lxc/lxc_controller.c |   11 +++--------
 1 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 649ac87..137ef52 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -59,6 +59,7 @@
 #include "util.h"
 #include "virfile.h"
 #include "virpidfile.h"
+#include "command.h"

 #define VIR_FROM_THIS VIR_FROM_LXC

@@ -1266,14 +1267,8 @@ cleanup:
         VIR_FORCE_CLOSE(loopDevs[i]);
     VIR_FREE(loopDevs);

-    if (container > 1) {
-        int status;
-        kill(container, SIGTERM);
-        if (!(waitpid(container, &status, WNOHANG) == 0 &&
-            WIFEXITED(status)))
-            kill(container, SIGKILL);
-        waitpid(container, NULL, 0);
-    }
+    virPidAbort(container);
+
     return rc;
 }

-- 
1.7.4.4




More information about the libvir-list mailing list