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

Re: [libvirt] [PATCHv3 6/6] virsh: Add vshRebootShutdownModeCompleter



On 08/26/2013 06:36 AM, Tomas Meszaros wrote:
> vshRebootShutdownModeCompleter returns available shutdown mode
> names. This can be used for --mode auto completion for commands
> such as reboot or shutdown.
> 
> for example:
> 
> virsh> reboot --mode <TAB>
> acpi     agent    initctl  signal
> virsh> reboot --mode i<TAB>
> virsh> reboot --mode initctl
> ---
> v3
> * removed useless if
> * used virStringFreeList() instead of iteration
> * moved all .completer = vshRebootShutdownModeCompleter initializations
>   into this patch

Once again, seems reasonable, but can be shortened:


> +char **
> +vshRebootShutdownModeCompleter(unsigned int unused_flags ATTRIBUTE_UNUSED)
> +{
> +    const char *modes[] = {"acpi", "agent", "initctl", "signal"};
> +    const unsigned int modes_size = ARRAY_CARDINALITY(modes);
> +    char **names = NULL;
> +    size_t i;
> +
> +    names = vshMalloc(NULL, sizeof(char *) * (modes_size + 1));
> +
> +    for (i = 0; i < modes_size; i++) {
> +        if (VIR_STRDUP(names[i], modes[i]) < 0)
> +            goto cleanup;
> +    }
> +
> +    names[i] = NULL;
> +    return names;
> +
> +cleanup:
> +    virStringFreeList(names);
> +    return NULL;

All this boils down to an open-coded version of
 return virStringSplit("acpi agent initctl signal", " ", 0);

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

Attachment: signature.asc
Description: OpenPGP digital signature


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