mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 12:41:29 +00:00
virnetsockettest: Use a temporary directory in /tmp
to avoid exceeding UNIX_PATH_MAX
This commit is contained in:
parent
6bab30d071
commit
745c3e7981
@ -202,16 +202,18 @@ static int testSocketUNIXAccept(const void *data ATTRIBUTE_UNUSED)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
if (progname[0] == '/') {
|
char *tmpdir;
|
||||||
if (virAsprintf(&path, "%s-test.sock", progname) < 0) {
|
char template[] = "/tmp/libvirt_XXXXXX";
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
tmpdir = mkdtemp(template);
|
||||||
}
|
if (tmpdir == NULL) {
|
||||||
} else {
|
virReportSystemError(errno, "%s",
|
||||||
if (virAsprintf(&path, "%s/%s-test.sock", abs_builddir, progname) < 0) {
|
_("Failed to create temporary directory"));
|
||||||
virReportOOMError();
|
goto cleanup;
|
||||||
goto cleanup;
|
}
|
||||||
}
|
if (virAsprintf(&path, "%s/test.sock", tmpdir) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virNetSocketNewListenUNIX(path, 0700, -1, getgid(), &lsock) < 0)
|
if (virNetSocketNewListenUNIX(path, 0700, -1, getgid(), &lsock) < 0)
|
||||||
@ -239,6 +241,8 @@ cleanup:
|
|||||||
VIR_FREE(path);
|
VIR_FREE(path);
|
||||||
virNetSocketFree(lsock);
|
virNetSocketFree(lsock);
|
||||||
virNetSocketFree(ssock);
|
virNetSocketFree(ssock);
|
||||||
|
if (tmpdir)
|
||||||
|
rmdir(tmpdir);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,16 +255,18 @@ static int testSocketUNIXAddrs(const void *data ATTRIBUTE_UNUSED)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
if (progname[0] == '/') {
|
char *tmpdir;
|
||||||
if (virAsprintf(&path, "%s-test.sock", progname) < 0) {
|
char template[] = "/tmp/libvirt_XXXXXX";
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
tmpdir = mkdtemp(template);
|
||||||
}
|
if (tmpdir == NULL) {
|
||||||
} else {
|
virReportSystemError(errno, "%s",
|
||||||
if (virAsprintf(&path, "%s/%s-test.sock", abs_builddir, progname) < 0) {
|
_("Failed to create temporary directory"));
|
||||||
virReportOOMError();
|
goto cleanup;
|
||||||
goto cleanup;
|
}
|
||||||
}
|
if (virAsprintf(&path, "%s/test.sock", tmpdir) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virNetSocketNewListenUNIX(path, 0700, -1, getgid(), &lsock) < 0)
|
if (virNetSocketNewListenUNIX(path, 0700, -1, getgid(), &lsock) < 0)
|
||||||
@ -317,6 +323,8 @@ cleanup:
|
|||||||
virNetSocketFree(lsock);
|
virNetSocketFree(lsock);
|
||||||
virNetSocketFree(ssock);
|
virNetSocketFree(ssock);
|
||||||
virNetSocketFree(csock);
|
virNetSocketFree(csock);
|
||||||
|
if (tmpdir)
|
||||||
|
rmdir(tmpdir);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user