From 808f7dd4be8e203c6eb83859263cf313f718f1d2 Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Tue, 20 Dec 2011 17:08:47 +0800 Subject: [PATCH] kvm tools: cleanup kvm_cmd_stat() Use stack variable. Remove unneeded branch. Close opened file. Signed-off-by: Lai Jiangshan Signed-off-by: Pekka Enberg --- tools/kvm/builtin-stat.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/kvm/builtin-stat.c b/tools/kvm/builtin-stat.c index 1f9ead43796b..855cc8994e87 100644 --- a/tools/kvm/builtin-stat.c +++ b/tools/kvm/builtin-stat.c @@ -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; } -- 2.39.5