virnetsockettest: Use a temporary directory in /tmp

to avoid exceeding UNIX_PATH_MAX
This commit is contained in:
Guido Günther 2011-11-02 22:06:44 +01:00
parent 6bab30d071
commit 745c3e7981

View File

@ -202,17 +202,19 @@ static int testSocketUNIXAccept(const void *data ATTRIBUTE_UNUSED)
int ret = -1;
char *path;
if (progname[0] == '/') {
if (virAsprintf(&path, "%s-test.sock", progname) < 0) {
virReportOOMError();
char *tmpdir;
char template[] = "/tmp/libvirt_XXXXXX";
tmpdir = mkdtemp(template);
if (tmpdir == NULL) {
virReportSystemError(errno, "%s",
_("Failed to create temporary directory"));
goto cleanup;
}
} else {
if (virAsprintf(&path, "%s/%s-test.sock", abs_builddir, progname) < 0) {
if (virAsprintf(&path, "%s/test.sock", tmpdir) < 0) {
virReportOOMError();
goto cleanup;
}
}
if (virNetSocketNewListenUNIX(path, 0700, -1, getgid(), &lsock) < 0)
goto cleanup;
@ -239,6 +241,8 @@ cleanup:
VIR_FREE(path);
virNetSocketFree(lsock);
virNetSocketFree(ssock);
if (tmpdir)
rmdir(tmpdir);
return ret;
}
@ -251,17 +255,19 @@ static int testSocketUNIXAddrs(const void *data ATTRIBUTE_UNUSED)
int ret = -1;
char *path;
if (progname[0] == '/') {
if (virAsprintf(&path, "%s-test.sock", progname) < 0) {
virReportOOMError();
char *tmpdir;
char template[] = "/tmp/libvirt_XXXXXX";
tmpdir = mkdtemp(template);
if (tmpdir == NULL) {
virReportSystemError(errno, "%s",
_("Failed to create temporary directory"));
goto cleanup;
}
} else {
if (virAsprintf(&path, "%s/%s-test.sock", abs_builddir, progname) < 0) {
if (virAsprintf(&path, "%s/test.sock", tmpdir) < 0) {
virReportOOMError();
goto cleanup;
}
}
if (virNetSocketNewListenUNIX(path, 0700, -1, getgid(), &lsock) < 0)
goto cleanup;
@ -317,6 +323,8 @@ cleanup:
virNetSocketFree(lsock);
virNetSocketFree(ssock);
virNetSocketFree(csock);
if (tmpdir)
rmdir(tmpdir);
return ret;
}