[libvirt] [PATCH 3/4] lxc: validate container process during load config

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

 



This patch adds a check that validates that the container process pid still
exists.  This should catch cases where the container exits while libvirtd is down.

-- 
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization

---
 src/lxc_conf.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/lxc_conf.h |    1 +
 2 files changed, 47 insertions(+)

Index: b/src/lxc_conf.h
===================================================================
--- a/src/lxc_conf.h	2008-05-29 14:34:26.000000000 -0700
+++ b/src/lxc_conf.h	2008-05-29 14:47:55.000000000 -0700
@@ -124,6 +124,7 @@
                           const unsigned char *uuid);
 lxc_vm_t *lxcFindVMByName(const lxc_driver_t *driver,
                           const char *name);
+int lxcCheckContainerProcess(lxc_vm_def_t *vm);
 void lxcRemoveInactiveVM(lxc_driver_t *driver,
                          lxc_vm_t *vm);
 void lxcFreeVMs(lxc_vm_t *vms);
Index: b/src/lxc_conf.c
===================================================================
--- a/src/lxc_conf.c	2008-05-29 14:34:26.000000000 -0700
+++ b/src/lxc_conf.c	2008-05-29 14:48:52.000000000 -0700
@@ -348,6 +348,12 @@
                      _("invalid domain id"));
             goto error;
         }
+
+        /* verify the container process still exists */
+        if (1 != lxcCheckContainerProcess(containerDef)) {
+            containerDef->id = -1;
+        }
+
     } else {
         containerDef->id = -1;
     }
@@ -458,6 +464,46 @@
     return vm;
 }
 
+/**
+ * lxcCheckContainerProcess:
+ * @def: Ptr to VM definition
+ *
+ * Checks if the container process (stored at def->id is running
+ *
+ * Returns on success or -1 in case of error
+ * 0  - no process with id vm->def->id
+ * 1  - container process exists
+ * -1 - error
+ */
+int lxcCheckContainerProcess(lxc_vm_def_t *def)
+{
+    int rc = -1;
+
+    if (1 < def->id) {
+        if (-1 == kill(def->id, 0)) {
+            if (ESRCH == errno) {
+                rc = 0;
+                DEBUG("pid %d no longer exists", def->id);
+                goto done;
+            }
+
+            lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                     _("error checking container process: %d %s"),
+                     def->id, strerror(errno));
+            goto done;
+        }
+
+        DEBUG("pid %d still exists", def->id);
+        rc = 1;
+        goto done;
+    }
+
+    rc = 0;
+
+done:
+    return rc;
+}
+
 void lxcRemoveInactiveVM(lxc_driver_t *driver,
                          lxc_vm_t *vm)
 {

--
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]