Skip to contentSkip to conversation

qmp: fix handling of boolean values in qmp-shell

PATCH Applied Igor Mammedov 2 participants 2 messages Mar 25, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qmp: fix handling of boolean values in qmp-shell

qmp-shell converts only integer arguments and the rest is assumed to be strings which are faithfully sent as quoted strings by json. But QEMU refuses to accept qmp command with boolean argument whose value is escaped as string.

Fix it by special-casing true/false keywords and store value as corresponding boolean.

---
 QMP/qmp-shell |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
QMP/qmp-shell +6 -1
index 24b665c..d126e63 100755
@@ -101,7 +101,12 @@ class QMPShell(qmp.QEMUMonitorProtocol):
             try:
                 value = int(opt[1])
             except ValueError:
-                value = opt[1]
+                if opt[1] == 'true':
+                    value = True
+                elif opt[1] == 'false':
+                    value = False
+                else:
+                    value = opt[1]
             qmpcmd['arguments'][opt[0]] = value
         return qmpcmd
 
Signature · 1 line
1.7.1
#1 lore raw
Quoted 10 lines · On Mon, 25 Mar 2013 15:48:46 +0100 Igor Mammedov <[email protected]> wrote:

qmp-shell converts only integer arguments and the rest is assumed to be strings which are faithfully sent as quoted strings by json. But QEMU refuses to accept qmp command with boolean argument whose value is escaped as string.

Fix it by special-casing true/false keywords and store value as corresponding boolean.

Applied to the qmp branch, thanks.

Quoted 22 lines
---
 QMP/qmp-shell |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
QMP/qmp-shell +6 -1
index 24b665c..d126e63 100755
@@ -101,7 +101,12 @@ class QMPShell(qmp.QEMUMonitorProtocol):
             try:
                 value = int(opt[1])
             except ValueError:
-                value = opt[1]
+                if opt[1] == 'true':
+                    value = True
+                elif opt[1] == 'false':
+                    value = False
+                else:
+                    value = opt[1]
             qmpcmd['arguments'][opt[0]] = value
         return qmpcmd