Re: [PATCH 07/16] storage: Covert regex helpers to virCommand

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

 



On 05/10/2011 02:07 PM, Cole Robinson wrote:
> @@ -1372,6 +1371,9 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
>      int maxReg = 0, i, j;
>      int totgroups = 0, ngroup = 0, maxvars = 0;
>      char **groups;
> +    virCommandPtr cmd = NULL;
> +    const char * const *tmp;

No need for tmp...

> +    pid_t pid = -1;
>  
>      /* Compile all regular expressions */
>      if (VIR_ALLOC_N(reg, nregex) < 0) {
> @@ -1408,10 +1410,14 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
>          goto cleanup;
>      }
>  
> +    cmd = virCommandNew(prog[0]);
> +    tmp = prog;
> +    while (*(++tmp)) {
> +        virCommandAddArg(cmd, *tmp);
> +    }

...if you replace this with virCommandNewArgs(prog).

> +cleanup:
> +    if (pid > 0 && virCommandWait(cmd, outexit) < 0)
> +        ret = -1;
>  
> - cleanup:
>      if (groups) {
>          for (j = 0 ; j < totgroups ; j++)
>              VIR_FREE(groups[j]);
> @@ -1478,29 +1486,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
>      VIR_FORCE_FCLOSE(list);
>      VIR_FORCE_CLOSE(fd);
>  
> -    while ((err = waitpid(child, &exitstatus, 0) == -1) && errno == EINTR);
> -
> -    /* Don't bother checking exit status if we already failed */
> -    if (failed)
> -        return -1;
> -
> -    if (err == -1) {
> -        virReportSystemError(errno,
> -                             _("failed to wait for command '%s'"),
> -                             prog[0]);
> -        return -1;
> -    } else {
> -        if (WIFEXITED(exitstatus)) {
> -            if (outexit != NULL)
> -                *outexit = WEXITSTATUS(exitstatus);
> -        } else {
> -            virStorageReportError(VIR_ERR_INTERNAL_ERROR,
> -                                  "%s", _("command did not exit cleanly"));
> -            return -1;
> -        }
> -    }
> -
> -    return 0;
> +    return ret;

This leaks the memory for cmd; you still need a call to
virCommandFree(cmd) somewhere in the cleanup.

> @@ -1540,9 +1527,14 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
>      for (i = 0; i < n_columns; i++)
>          v[i] = NULL;
>  
> -    /* Run the program and capture its output */
> -    if (virExec(prog, NULL, NULL,
> -                &child, -1, &fd, NULL, VIR_EXEC_NONE) < 0) {
> +    cmd = virCommandNew(prog[0]);
> +    tmp = prog;
> +    while (*(++tmp)) {
> +        virCommandAddArg(cmd, *tmp);
> +    }

Again, virCommandNewArgs is more compact.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
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]