From 4a0016ec5f211887ad0c4931496ad9f7dfefe4e8 Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Tue, 20 Dec 2011 17:08:46 +0800 Subject: [PATCH] kvm tools: cleanup kvm_cmd_resume() Use stack variable. Remove unneeded branch. Close opened file. Signed-off-by: Lai Jiangshan Signed-off-by: Pekka Enberg --- builtin-resume.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/builtin-resume.c b/builtin-resume.c index 7b87f59..33ccc2b 100644 --- a/builtin-resume.c +++ b/builtin-resume.c @@ -15,7 +15,6 @@ struct resume_cmd { }; static bool all; -static int instance; static const char *instance_name; static const char * const resume_usage[] = { @@ -59,20 +58,25 @@ static int do_resume(const char *name, int sock) int kvm_cmd_resume(int argc, const char **argv, const char *prefix) { + int instance; + int r; + parse_resume_options(argc, argv); if (all) return kvm__enumerate_instances(do_resume); - if (instance_name == NULL && - instance == 0) + if (instance_name == NULL) kvm_resume_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_resume(instance_name, instance); + r = do_resume(instance_name, instance); + + close(instance); + + return r; }