]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: cleanup kvm_cmd_stat()
authorLai Jiangshan <laijs@cn.fujitsu.com>
Tue, 20 Dec 2011 09:08:47 +0000 (17:08 +0800)
committerPekka Enberg <penberg@kernel.org>
Wed, 21 Dec 2011 20:28:08 +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-stat.c

index 1f9ead43796b0377078b70e846b1dd6100ba1790..855cc8994e874c80c291cdde787d0ae695d5165e 100644 (file)
@@ -19,7 +19,6 @@ struct stat_cmd {
 
 static bool mem;
 static bool all;
-static int instance;
 static const char *instance_name;
 
 static const char * const stat_usage[] = {
@@ -106,6 +105,9 @@ static int do_memstat(const char *name, int sock)
 
 int kvm_cmd_stat(int argc, const char **argv, const char *prefix)
 {
+       int instance;
+       int r = 0;
+
        parse_stat_options(argc, argv);
 
        if (!mem)
@@ -114,18 +116,18 @@ int kvm_cmd_stat(int argc, const char **argv, const char *prefix)
        if (mem && all)
                return kvm__enumerate_instances(do_memstat);
 
-       if (instance_name == NULL &&
-           instance == 0)
+       if (instance_name == NULL)
                kvm_stat_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");
 
        if (mem)
-               return do_memstat(instance_name, instance);
+               r = do_memstat(instance_name, instance);
 
-       return 0;
+       close(instance);
+
+       return r;
 }