summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Krempa <pkrempa@redhat.com>2022-03-01 14:24:33 +0100
committerPeter Krempa <pkrempa@redhat.com>2022-07-25 12:25:02 +0200
commit8e2a043c32c06c8d4978ca79bc9ffa9e39384649 (patch)
treedf6edb93c30e16bf844a3af82d9657e566d3ef32 /tools
parent619d825a180c04723ffb238c2e77975163928b3b (diff)
downloadlibvirt-8e2a043c32c06c8d4978ca79bc9ffa9e39384649.tar.gz
cmdQemuMonitorCommandQMPWrap: Reset ignored errors from JSON parsing
'cmdQemuMonitorCommandQMPWrap' is checking whether the user provided string is not valid JSON to avoid wrapping it. In cases where it's not JSON we ignore the error and add the wrapper. If the caller then reports a different non-libvirt error the error from the JSON parsing would be printed as well. Reset errors we ignore: # virsh qemu-monitor-command cd --pass-fds a asdf error: Unable to parse FD number 'a' error: internal error: cannot parse json asdf: lexical error: invalid char in json text. asdf (right here) ------^ In the above case 'asdf' is not valid JSON, but the code did wrap it into '{"execute":"asdf"}', the only problem is the argument for --pass-fds. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/virsh-domain.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 76d12d2b70..1f995a462a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9870,7 +9870,7 @@ cmdQemuMonitorCommandQMPWrap(vshControl *ctl,
const vshCmd *cmd)
{
g_autofree char *fullcmd = cmdQemuMonitorCommandConcatCmd(ctl, cmd, NULL);
- g_autoptr(virJSONValue) fullcmdjson = virJSONValueFromString(fullcmd);
+ g_autoptr(virJSONValue) fullcmdjson = NULL;
g_autofree char *fullargs = NULL;
g_autoptr(virJSONValue) fullargsjson = NULL;
const vshCmdOpt *opt = NULL;
@@ -9878,6 +9878,11 @@ cmdQemuMonitorCommandQMPWrap(vshControl *ctl,
g_autoptr(virJSONValue) command = NULL;
g_autoptr(virJSONValue) arguments = NULL;
+ if (!(fullcmdjson = virJSONValueFromString(fullcmd))) {
+ /* Reset the error before adding wrapping. */
+ vshResetLibvirtError();
+ }
+
/* if we've got a JSON object, pass it through */
if (virJSONValueIsObject(fullcmdjson))
return g_steal_pointer(&fullcmd);
@@ -9889,8 +9894,11 @@ cmdQemuMonitorCommandQMPWrap(vshControl *ctl,
commandname = opt->data;
/* now we process arguments similarly to how we've dealt with the full command */
- if ((fullargs = cmdQemuMonitorCommandConcatCmd(ctl, cmd, opt)))
- fullargsjson = virJSONValueFromString(fullargs);
+ if ((fullargs = cmdQemuMonitorCommandConcatCmd(ctl, cmd, opt)) &&
+ !(fullargsjson = virJSONValueFromString(fullargs))) {
+ /* Reset the error before adding wrapping. */
+ vshResetLibvirtError();
+ }
/* for empty args or a valid JSON object we just use that */
if (!fullargs || virJSONValueIsObject(fullargsjson)) {