diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index 17f1d0c51de361f4f959d55fc7ae1dcfa8d7872f..bd80d9fe9a9945ca5fa48e1856af77a6c2336361 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -24,6 +24,10 @@ #include "lxc_domain.h" #include "memory.h" +#include "logging.h" +#include "virterror_internal.h" + +#define VIR_FROM_THIS VIR_FROM_LXC static void *virLXCDomainObjPrivateAlloc(void) { @@ -43,8 +47,36 @@ static void virLXCDomainObjPrivateFree(void *data) } +static int virLXCDomainObjPrivateXMLFormat(virBufferPtr buf, void *data) +{ + virLXCDomainObjPrivatePtr priv = data; + + virBufferAsprintf(buf, " \n", + (unsigned long long)priv->initpid); + + return 0; +} + +static int virLXCDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data) +{ + virLXCDomainObjPrivatePtr priv = data; + unsigned long long thepid; + + if (virXPathULongLong("string(./init[1]/@pid)", ctxt, &thepid) < 0) { + virErrorPtr err = virGetLastError(); + VIR_WARN("Failed to load init pid from state %s", err ? err->message : "null"); + priv->initpid = 0; + } else { + priv->initpid = thepid; + } + + return 0; +} + void virLXCDomainSetPrivateDataHooks(virCapsPtr caps) { caps->privateDataAllocFunc = virLXCDomainObjPrivateAlloc; caps->privateDataFreeFunc = virLXCDomainObjPrivateFree; + caps->privateDataXMLFormat = virLXCDomainObjPrivateXMLFormat; + caps->privateDataXMLParse = virLXCDomainObjPrivateXMLParse; } diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h index b1dd5d9eade26cc5f518ac49575cefe2d0851bb2..882f34ad9b4898105e28f271d6e72bbf1ac5ebb9 100644 --- a/src/lxc/lxc_domain.h +++ b/src/lxc/lxc_domain.h @@ -34,6 +34,8 @@ struct _virLXCDomainObjPrivate { bool doneStopEvent; int stopReason; bool wantReboot; + + pid_t initpid; }; void virLXCDomainSetPrivateDataHooks(virCapsPtr caps); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 1bf46975e03eff48aa8e28b16f52b2c04e863cf6..d489c048578c65553e2b36a23b7c4ea0fbf25ca6 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -637,11 +637,18 @@ static void virLXCProcessMonitorExitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED priv->stopReason, status); } +/* XXX a little evil */ +extern virLXCDriverPtr lxc_driver; static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED, pid_t initpid, virDomainObjPtr vm) { + virLXCDomainObjPrivatePtr priv = vm->privateData; + priv->initpid = initpid; virDomainAuditInit(vm, initpid); + + if (virDomainSaveStatus(lxc_driver->caps, lxc_driver->stateDir, vm) < 0) + VIR_WARN("Cannot update XML with PID for LXC %s", vm->def->name); } static virLXCMonitorCallbacks monitorCallbacks = {