[Libguestfs] [PATCH v2] appliance: extract UUID from QCOW2 disk image

Richard W.M. Jones rjones at redhat.com
Wed Aug 12 16:23:31 UTC 2020


So the patch is generally fine now, but there's one thing
I didn't spot in the earlier version:

> +/**
> + * Get the UUID from the appliance disk image.
> + */
> +static char *
> +get_root_uuid (guestfs_h *g, const char *appliance)
> +{
> +  char *uuid = NULL;
> +  int ret;
> +  char tmp_file[] = "/tmp/libguestfsXXXXXX";
> +
> +  uuid = do_get_root_uuid (g, appliance);
> +  if (uuid) {
> +      return uuid;
> +  }
> +
> +  if (!mktemp (tmp_file)) {
> +    error (g, "get_root_uuid: mktemp failed");
> +    return NULL;
> +  }

mktemp isn't safe to use in modern code.  Libguestfs already makes a
temporary directory for handles to use so you can create a file in
that directory like this:

  CLEANUP_FREE char *file = NULL;

  file = guestfs_int_make_temp_path (g, "root", "raw");
  if (!file) return -1;

Note you don't have to delete the file explicitly.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/




More information about the Libguestfs mailing list