From 7a50442ac0dae04ba0cce1baa08834be2d6dc6a4 Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Tue, 20 Dec 2011 17:08:44 +0800 Subject: [PATCH] kvm tools: cleanup kvm_cmd_debug() Use stack variable. Remove unneeded branch. Close opened file. Signed-off-by: Lai Jiangshan Signed-off-by: Pekka Enberg --- tools/kvm/builtin-debug.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/kvm/builtin-debug.c b/tools/kvm/builtin-debug.c index 7c51ea3984bb..add9b5c4460f 100644 --- a/tools/kvm/builtin-debug.c +++ b/tools/kvm/builtin-debug.c @@ -13,7 +13,6 @@ #define BUFFER_SIZE 100 static bool all; -static int instance; static int nmi = -1; static bool dump; static const char *instance_name; @@ -82,19 +81,23 @@ static int do_debug(const char *name, int sock) int kvm_cmd_debug(int argc, const char **argv, const char *prefix) { parse_debug_options(argc, argv); + int instance; + int r; if (all) return kvm__enumerate_instances(do_debug); - if (instance_name == NULL && - instance == 0) + if (instance_name == NULL) kvm_debug_help(); - if (instance_name) - instance = kvm__get_sock_by_instance(instance_name); + instance = kvm__get_sock_by_instance(instance_name); if (instance <= 0) die("Failed locating instance"); - return do_debug(instance_name, instance); + r = do_debug(instance_name, instance); + + close(instance); + + return r; } -- 2.39.5