]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: cleanup kvm_cmd_debug()
authorLai Jiangshan <laijs@cn.fujitsu.com>
Tue, 20 Dec 2011 09:08:44 +0000 (17:08 +0800)
committerPekka Enberg <penberg@kernel.org>
Wed, 21 Dec 2011 20:28:07 +0000 (22:28 +0200)
Use stack variable.
Remove unneeded branch.
Close opened file.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-debug.c

index 7c51ea3984bb3321b877a1877805b6554d034535..add9b5c4460f6912fa9d5be973b5d3222edde6f9 100644 (file)
@@ -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;
 }