diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 96bf0a25c8..e2fa1d6540 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -150,6 +150,7 @@ struct _virCaps { int (*privateDataXMLFormat)(virBufferPtr, void *); int (*privateDataXMLParse)(xmlXPathContextPtr, void *); bool hasWideScsiBus; + const char *defaultInitPath; virDomainXMLNamespace ns; }; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9ab9a5a498..f7e4959707 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5708,6 +5708,18 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (STREQ(def->os.type, "exe")) { def->os.init = virXPathString("string(./os/init[1])", ctxt); + if (!def->os.init) { + if (caps->defaultInitPath) { + def->os.init = strdup(caps->defaultInitPath); + if (!def->os.init) { + goto no_memory; + } + } else { + virDomainReportError(VIR_ERR_XML_ERROR, "%s", + _("init binary must be specified")); + goto error; + } + } } if (STREQ(def->os.type, "xen") || diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 88cd4c88ff..45bc398764 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -174,8 +174,10 @@ virCapsPtr openvzCapsInit(void) 0, NULL) == NULL) goto no_memory; - return caps; + caps->defaultInitPath = "/sbin/init"; + + return caps; no_memory: virCapabilitiesFree(caps); return NULL; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index fbb8800e36..3e1952fa1e 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -857,13 +857,6 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; - if (vmdef->os.init == NULL) { - if (!(vmdef->os.init = strdup("/sbin/init"))) { - virReportOOMError(); - goto cleanup; - } - } - vm = virDomainFindByName(&driver->domains, vmdef->name); if (vm) { openvzError(VIR_ERR_OPERATION_FAILED, @@ -943,13 +936,6 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; - if (vmdef->os.init == NULL) { - if (!(vmdef->os.init = strdup("/sbin/init"))) { - virReportOOMError(); - goto cleanup; - } - } - vm = virDomainFindByName(&driver->domains, vmdef->name); if (vm) { openvzError(VIR_ERR_OPERATION_FAILED,