[libvirt] [PATCH] Create temporary dir for socket

Eric Blake eblake at redhat.com
Tue Oct 30 13:08:36 UTC 2012


On 10/29/2012 06:05 AM, Guido Günther wrote:
> to avoid ENAMETOOLONG:
> 
> https://buildd.debian.org/status/fetch.php?pkg=libvirt&arch=amd64&ver=1.0.0~rc1-1&stamp=1351453521
> ---
>  tests/qemumonitortestutils.c |   22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)

ACK once you fix this bug:

> 
> diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
> index 7133c99..1369cb7 100644
> --- a/tests/qemumonitortestutils.c
> +++ b/tests/qemumonitortestutils.c
> @@ -424,9 +424,23 @@ static qemuMonitorCallbacks qemuCallbacks = {
>  qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps)
>  {
>      qemuMonitorTestPtr test;

Uninitialized...

> -    const char *path = abs_builddir "/qemumonitorjsontest.sock";
>      virDomainChrSourceDef src;
>  
> +    char *tmpdir = NULL, *path = NULL;
> +    char template[] = "/tmp/libvirt_XXXXXX";
> +
> +    tmpdir = mkdtemp(template);
> +    if (tmpdir == NULL) {
> +        virReportSystemError(errno, "%s",
> +                             "Failed to create temporary directory");
> +        goto error;

Still uninitialized...

> +    }
> +
> +    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;
> @@ -494,11 +508,15 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps)
>      test->running = true;
>      virMutexUnlock(&test->lock);
>  
> +cleanup:
> +    if (tmpdir)
> +        rmdir(tmpdir);
> +    VIR_FREE(path);
>      return test;
>  
>  error:
>      qemuMonitorTestFree(test);

...and freed.  Crash-tastic.

Also, it might be worth adding a VIR_WARN if the rmdir() fails.

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 617 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20121030/d328394d/attachment-0001.sig>


More information about the libvir-list mailing list