[libvirt] [PATCH] virsh: Don't read nparams when virDomainGetMemoryParameters fails

Also exit early when nparams is 0. --- tools/virsh.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index d1ef698..3e37b06 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2941,17 +2941,22 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd) if (nparams == 0) { /* get the number of memory parameters */ - if ((virDomainGetMemoryParameters(dom, NULL, &nparams, 0) != 0) && - (nparams != 0)) { + if (virDomainGetMemoryParameters(dom, NULL, &nparams, 0) != 0) { vshError(ctl, "%s", _("Unable to get number of memory parameters")); goto cleanup; } + if (nparams == 0) { + /* nothing to output */ + ret = TRUE; + goto cleanup; + } + /* now go get all the memory parameters */ params = vshMalloc(ctl, sizeof(virMemoryParameter) * nparams); memset(params, 0, sizeof(virMemoryParameter) * nparams); - if (virDomainGetMemoryParameters(dom, params, &nparams, 0)) { + if (virDomainGetMemoryParameters(dom, params, &nparams, 0) != 0) { vshError(ctl, "%s", _("Unable to get memory parameters")); goto cleanup; } @@ -3026,7 +3031,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd) } } if (virDomainSetMemoryParameters(dom, params, nparams, 0) != 0) - vshError(ctl, "%s", _("Unable to change Memory Parameters")); + vshError(ctl, "%s", _("Unable to change memory parameters")); else ret = TRUE; } -- 1.7.0.4

On Wed, Oct 20, 2010 at 02:26:18PM +0200, Matthias Bolte wrote:
Also exit early when nparams is 0. --- tools/virsh.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
Okay, error message normalization sounds good too, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

2010/10/20 Daniel Veillard <veillard@redhat.com>:
On Wed, Oct 20, 2010 at 02:26:18PM +0200, Matthias Bolte wrote:
Also exit early when nparams is 0. --- tools/virsh.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
Okay, error message normalization sounds good too,
thanks !
Daniel
Thanks, pushed. Matthias
participants (2)
-
Daniel Veillard
-
Matthias Bolte