Re: [PATCH 06/16] storage: Convert qemu-img -help parsing to virCommand

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 10, 2011 at 04:07:45PM -0400, Cole Robinson wrote:
> 
> Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
> ---
>  src/storage/storage_backend.c |   31 ++++++-------------------------
>  1 files changed, 6 insertions(+), 25 deletions(-)
> 
> diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
> index 2acbf90..63ba686 100644
> --- a/src/storage/storage_backend.c
> +++ b/src/storage/storage_backend.c
> @@ -607,28 +607,19 @@ enum {
>  
>  static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
>  {
> -    const char *const qemuarg[] = { qemuimg, "-h", NULL };
> -    const char *const qemuenv[] = { "LC_ALL=C", NULL };
> -    pid_t child = 0;
> -    int status;
> -    int newstdout = -1;
>      char *help = NULL;
> -    enum { MAX_HELP_OUTPUT_SIZE = 1024*8 };
>      char *start;
>      char *end;
>      char *tmp;
>      int ret = -1;
> +    virCommandPtr cmd = virCommandNewArgList(qemuimg, "-h", NULL);
>  
> -    if (virExec(qemuarg, qemuenv, NULL,
> -                &child, -1, &newstdout, NULL, VIR_EXEC_CLEAR_CAPS) < 0)
> -        goto cleanup;
> +    virCommandAddEnvString(cmd, "LC_ALL=C");
> +    virCommandSetOutputBuffer(cmd, &help);
> +    virCommandClearCaps(cmd);
>  
> -    if (virFileReadLimFD(newstdout, MAX_HELP_OUTPUT_SIZE, &help) < 0) {
> -        virReportSystemError(errno,
> -                             _("Unable to read '%s -h' output"),
> -                             qemuimg);
> +    if (virCommandRun(cmd, NULL) < 0)
>          goto cleanup;
> -    }
>  
>      start = strstr(help, " create ");
>      end = strstr(start, "\n");
> @@ -641,18 +632,8 @@ static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
>          ret = QEMU_IMG_BACKING_FORMAT_NONE;
>  
>  cleanup:
> +    virCommandFree(cmd);
>      VIR_FREE(help);
> -    VIR_FORCE_CLOSE(newstdout);
> -    if (child) {
> -        while (waitpid(child, &status, 0) == -1 && errno == EINTR);
> -        if (status) {
> -            tmp = virCommandTranslateStatus(status);
> -            VIR_WARN("Unexpected status, qemu probably failed: %s",
> -                     NULLSTR(tmp));
> -            VIR_FREE(tmp);
> -        }
> -    }
> -
>      return ret;
>  }

ACK

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]