提交 e5aab47a 编写于 作者: P Peter Krempa

tests: Remove temporary directories in qemumonitorjsontest

qemumonitorjsontest creates a temporary directory to hold the socket
that is simulating the monitor socket. The directory containing the
socket wasn't disposed properly at the end of the test leaving garbage
in the temporary folder.
上级 e25a32f3
...@@ -65,6 +65,8 @@ struct _qemuMonitorTest { ...@@ -65,6 +65,8 @@ struct _qemuMonitorTest {
qemuMonitorPtr mon; qemuMonitorPtr mon;
char *tmpdir;
size_t nitems; size_t nitems;
qemuMonitorTestItemPtr *items; qemuMonitorTestItemPtr *items;
...@@ -378,6 +380,11 @@ void qemuMonitorTestFree(qemuMonitorTestPtr test) ...@@ -378,6 +380,11 @@ void qemuMonitorTestFree(qemuMonitorTestPtr test)
qemuMonitorTestItemFree(test->items[i]); qemuMonitorTestItemFree(test->items[i]);
VIR_FREE(test->items); VIR_FREE(test->items);
if (test->tmpdir && rmdir(test->tmpdir) < 0)
VIR_WARN("Failed to remove tempdir: %s", strerror(errno));
VIR_FREE(test->tmpdir);
virMutexDestroy(&test->lock); virMutexDestroy(&test->lock);
VIR_FREE(test); VIR_FREE(test);
} }
...@@ -438,31 +445,11 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps) ...@@ -438,31 +445,11 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps)
{ {
qemuMonitorTestPtr test = NULL; qemuMonitorTestPtr test = NULL;
virDomainChrSourceDef src; virDomainChrSourceDef src;
char *path = NULL;
char *tmpdir_template = NULL;
char *tmpdir = NULL, *path = NULL; if (VIR_ALLOC(test) < 0)
char template[] = "/tmp/libvirt_XXXXXX"; goto no_memory;
tmpdir = mkdtemp(template);
if (tmpdir == NULL) {
virReportSystemError(errno, "%s",
"Failed to create temporary directory");
goto error;
}
if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", tmpdir) < 0) {
virReportOOMError();
goto error;
}
memset(&src, 0, sizeof(src));
src.type = VIR_DOMAIN_CHR_TYPE_UNIX;
src.data.nix.path = (char *)path;
src.data.nix.listen = false;
if (VIR_ALLOC(test) < 0) {
virReportOOMError();
return NULL;
}
if (virMutexInit(&test->lock) < 0) { if (virMutexInit(&test->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
...@@ -471,6 +458,20 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps) ...@@ -471,6 +458,20 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps)
return NULL; return NULL;
} }
if (!(tmpdir_template = strdup("/tmp/libvirt_XXXXXX")))
goto no_memory;
if (!(test->tmpdir = mkdtemp(tmpdir_template))) {
virReportSystemError(errno, "%s",
"Failed to create temporary directory");
goto error;
}
tmpdir_template = NULL;
if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0)
goto no_memory;
test->json = json; test->json = json;
if (!(test->vm = virDomainObjNew(caps))) if (!(test->vm = virDomainObjNew(caps)))
goto error; goto error;
...@@ -482,6 +483,10 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps) ...@@ -482,6 +483,10 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps)
&test->server) < 0) &test->server) < 0)
goto error; goto error;
memset(&src, 0, sizeof(src));
src.type = VIR_DOMAIN_CHR_TYPE_UNIX;
src.data.nix.path = (char *)path;
src.data.nix.listen = false;
if (virNetSocketListen(test->server, 1) < 0) if (virNetSocketListen(test->server, 1) < 0)
goto error; goto error;
...@@ -522,13 +527,14 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps) ...@@ -522,13 +527,14 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps)
virMutexUnlock(&test->lock); virMutexUnlock(&test->lock);
cleanup: cleanup:
if (tmpdir)
if (rmdir(tmpdir) < 0)
VIR_WARN("Failed to remove tempdir: %s", strerror(errno));
VIR_FREE(path); VIR_FREE(path);
return test; return test;
no_memory:
virReportOOMError();
error: error:
VIR_FREE(tmpdir_template);
qemuMonitorTestFree(test); qemuMonitorTestFree(test);
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册