[libvirt] [PATCH 2/2] virnetsockettest: Use a temporary directory in /tmp
Eric Blake
eblake at redhat.com
Wed Nov 2 21:39:54 UTC 2011
On 11/02/2011 03:31 PM, Guido Günther wrote:
> to avoid exceeding UNIX_PATH_MAX
> ---
> tests/virnetsockettest.c | 60 ++++++++++++++++++++++++++++++---------------
> 1 files changed, 40 insertions(+), 20 deletions(-)
I like this better than Stefan's proposal (a temporary directory is
better than unlink() on an open fd).
ACK with one nit:
> + char *template;
> + char *tmpdir = NULL;
> +
> + template = strdup("/tmp/libvirt_XXXXXX");
No need to malloc() the template. Just do:
char template[] = "/tmp/libvirt_XXXXXX";
> + if (template == NULL) {
> + virReportOOMError();
> + goto cleanup;
> + }
then ditch this clause,
> + tmpdir = mkdtemp(template);
> + if (tmpdir == NULL) {
> + virReportSystemError(errno, "%s",
> + _("Failed to create temporary directory"));
> + goto cleanup;
> + }
> + if (virAsprintf(&path, "%s/test.sock", tmpdir)< 0) {
> + virReportOOMError();
> + goto cleanup;
> }
>
> if (virNetSocketNewListenUNIX(path, 0700, -1, getgid(),&lsock)< 0)
> @@ -239,6 +246,9 @@ cleanup:
> VIR_FREE(path);
> virNetSocketFree(lsock);
> virNetSocketFree(ssock);
> + if (tmpdir)
> + rmdir(tmpdir);
> + VIR_FREE(template);
and drop this free, in both places.
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
More information about the libvir-list
mailing list