[libvirt] [PATCHv3 6/6] virsh: Add vshRebootShutdownModeCompleter
Eric Blake
eblake at redhat.com
Mon Aug 26 20:48:37 UTC 2013
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130826/c298ff22/attachment-0001.sig>
More information about the libvir-list
mailing list