提交 dd00c3f6 编写于 作者: J Jim Fehlig

libxl: fix libvirtd segfault

Commit d72ef888 introduced a bug in the libxl driver that will
segfault libvirtd if libxl reports an error message, e.g. when
attempting to initialize the driver on a non-Xen system.  I
assumed it was valid to pass a NULL logger to libxl_ctx_alloc(),
but that is not the case since any errors associated with the ctx
that are emitted by libxl will dereference the logger and crash
libvirtd.

Errors associated with the libxl driver-wide ctx could be useful
for debugging anyway, so create a 'libxl-driver.log' to capture
these errors.
上级 b6c7e3bb
...@@ -57,6 +57,9 @@ struct _libxlDriverPrivate { ...@@ -57,6 +57,9 @@ struct _libxlDriverPrivate {
virDomainXMLOptionPtr xmlopt; virDomainXMLOptionPtr xmlopt;
unsigned int version; unsigned int version;
/* log stream for driver-wide libxl ctx */
FILE *logger_file;
xentoollog_logger *logger;
/* libxl ctx for driver wide ops; getVersion, getNodeInfo, ... */ /* libxl ctx for driver wide ops; getVersion, getNodeInfo, ... */
libxl_ctx *ctx; libxl_ctx *ctx;
......
...@@ -1180,6 +1180,9 @@ libxlStateCleanup(void) ...@@ -1180,6 +1180,9 @@ libxlStateCleanup(void)
virObjectUnref(libxl_driver->xmlopt); virObjectUnref(libxl_driver->xmlopt);
virObjectUnref(libxl_driver->domains); virObjectUnref(libxl_driver->domains);
libxl_ctx_free(libxl_driver->ctx); libxl_ctx_free(libxl_driver->ctx);
xtl_logger_destroy(libxl_driver->logger);
if (libxl_driver->logger_file)
VIR_FORCE_FCLOSE(libxl_driver->logger_file);
virObjectUnref(libxl_driver->reservedVNCPorts); virObjectUnref(libxl_driver->reservedVNCPorts);
...@@ -1229,6 +1232,7 @@ libxlStateInitialize(bool privileged, ...@@ -1229,6 +1232,7 @@ libxlStateInitialize(bool privileged,
void *opaque ATTRIBUTE_UNUSED) void *opaque ATTRIBUTE_UNUSED)
{ {
const libxl_version_info *ver_info; const libxl_version_info *ver_info;
char *log_file = NULL;
virCommandPtr cmd; virCommandPtr cmd;
int status, ret = 0; int status, ret = 0;
unsigned int free_mem; unsigned int free_mem;
...@@ -1308,6 +1312,17 @@ libxlStateInitialize(bool privileged, ...@@ -1308,6 +1312,17 @@ libxlStateInitialize(bool privileged,
goto error; goto error;
} }
if (virAsprintf(&log_file, "%s/libxl-driver.log", libxl_driver->logDir) < 0)
goto error;
if ((libxl_driver->logger_file = fopen(log_file, "a")) == NULL) {
virReportSystemError(errno,
_("failed to create logfile %s"),
log_file);
goto error;
}
VIR_FREE(log_file);
/* read the host sysinfo */ /* read the host sysinfo */
if (privileged) if (privileged)
libxl_driver->hostsysinfo = virSysinfoRead(); libxl_driver->hostsysinfo = virSysinfoRead();
...@@ -1316,8 +1331,18 @@ libxlStateInitialize(bool privileged, ...@@ -1316,8 +1331,18 @@ libxlStateInitialize(bool privileged,
if (!libxl_driver->domainEventState) if (!libxl_driver->domainEventState)
goto error; goto error;
if (libxl_ctx_alloc(&libxl_driver->ctx, LIBXL_VERSION, 0, NULL)) { libxl_driver->logger =
VIR_INFO("cannot initialize libxenlight context, probably not running in a Xen Dom0, disabling driver"); (xentoollog_logger *)xtl_createlogger_stdiostream(libxl_driver->logger_file, XTL_DEBUG, 0);
if (!libxl_driver->logger) {
VIR_INFO("cannot create logger for libxenlight, disabling driver");
goto fail;
}
if (libxl_ctx_alloc(&libxl_driver->ctx,
LIBXL_VERSION, 0,
libxl_driver->logger)) {
VIR_INFO("cannot initialize libxenlight context, probably not running "
"in a Xen Dom0, disabling driver");
goto fail; goto fail;
} }
...@@ -1383,6 +1408,7 @@ libxlStateInitialize(bool privileged, ...@@ -1383,6 +1408,7 @@ libxlStateInitialize(bool privileged,
error: error:
ret = -1; ret = -1;
fail: fail:
VIR_FREE(log_file);
if (libxl_driver) if (libxl_driver)
libxlDriverUnlock(libxl_driver); libxlDriverUnlock(libxl_driver);
libxlStateCleanup(); libxlStateCleanup();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册