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@xxxxxxxxxx +1-801-349-2682 Libvirt virtualization library http://libvirt.org -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list