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

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

On Thu, Nov 03, 2011 at 08:45:45AM -0600, Eric Blake wrote:
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; }
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 11/03/2011 08:48 AM, Daniel P. Berrange wrote:
On Thu, Nov 03, 2011 at 08:45:45AM -0600, Eric Blake wrote:
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. ---
ACK
Pushed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Daniel P. Berrange
-
Eric Blake