[PATCH v2 09/11] tools/kvm_stat: stop ignoring unhandled arguments

Stefan Raspl
2017-12-11T11:25:38Z

Unhandled arguments, which could easily include typos, are simply
ignored. We should be strict to avoid undetected typos.
To reproduce start kvm_stat with an extra argument, e.g.
'kvm_stat -d bnuh5ol' and note that this will actually work.

Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com>
---
tools/kvm/kvm_stat/kvm_stat | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index 6ca18d15488e..42c34b8818f7 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -1517,7 +1517,9 @@ Press any other key to refresh statistics immediately.
help='restrict statistics to guest by name',
callback=cb_guest_to_pid,
)
- (options, _) = optparser.parse_args(sys.argv)
+ options, ukn = optparser.parse_args(sys.argv)
+ if len(ukn) != 1:
+ sys.exit('Error: Unknown argument(s): ' + ', '.join(ukn[-2:]))
try:
# verify that we were passed a valid regex up front
re.compile(options.fields)
--
2.13.5