]> xenbits.xensource.com Git - libvirt.git/commit
virsh: detect programming errors with option parsing
authorEric Blake <eblake@redhat.com>
Fri, 16 Aug 2013 22:07:31 +0000 (16:07 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 28 Aug 2013 20:48:24 +0000 (14:48 -0600)
commit8aecd351266a66efa59b7f7be77bf66693d99ce0
treeaae6b2a4a93f883e0f8a4f91929ed1f054e71d9e
parent74c5156f9db3be51eb7431a84f32731e7f687f2c
virsh: detect programming errors with option parsing

Noticed while reviewing another patch that had an accidental
mismatch due to refactoring.  An audit of the code showed that
very few callers of vshCommandOpt were expecting a return of
-2, indicating programmer error, and of those that DID check,
they just propagated that status to yet another caller that
did not check.  Fix this by making the code blatantly warn
the programmer, rather than silently ignoring it and possibly
doing the wrong thing downstream.

I know that we frown on assert()/abort() inside libvirtd
(libraries should NEVER kill the program that linked them),
but as virsh is an app rather than the library, and as this
is not the first use of assert() in virsh, I think this
approach is okay.

* tools/virsh.h (vshCommandOpt): Drop declaration.
* tools/virsh.c (vshCommandOpt): Make static, and add a
parameter.  Abort on programmer errors rather than making callers
repeat that logic.
(vshCommandOptInt, vshCommandOptUInt, vshCommandOptUL)
(vshCommandOptString, vshCommandOptStringReq)
(vshCommandOptLongLong, vshCommandOptULongLong)
(vshCommandOptBool): Adjust callers.

Signed-off-by: Eric Blake <eblake@redhat.com>
tools/virsh.c
tools/virsh.h