aboutsummaryrefslogtreecommitdiffstats
path: root/builtin-stop.c
diff options
context:
space:
mode:
authorLai Jiangshan <laijs@cn.fujitsu.com>2011-12-20 17:08:48 +0800
committerWill Deacon <will.deacon@arm.com>2015-06-01 16:39:50 +0100
commit715bbf8b0b527557493900c34abf497db6be62d4 (patch)
treef8952948fbbd9fd64e423eb7e08b47582f22e14b /builtin-stop.c
parent28aadb17d61bfc7d4cf9f0efc86268437695a6a9 (diff)
downloadkvmtool-715bbf8b0b527557493900c34abf497db6be62d4.tar.gz
kvm tools: cleanup kvm_cmd_stop()
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>
Diffstat (limited to 'builtin-stop.c')
-rw-r--r--builtin-stop.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/builtin-stop.c b/builtin-stop.c
index 52325e57..7d29eacf 100644
--- a/builtin-stop.c
+++ b/builtin-stop.c
@@ -15,7 +15,6 @@ struct stop_cmd {
};
static bool all;
-static int instance;
static const char *instance_name;
static const char * const stop_usage[] = {
@@ -59,20 +58,25 @@ static int do_stop(const char *name, int sock)
int kvm_cmd_stop(int argc, const char **argv, const char *prefix)
{
+ int instance;
+ int r;
+
parse_stop_options(argc, argv);
if (all)
return kvm__enumerate_instances(do_stop);
- if (instance_name == NULL &&
- instance == 0)
+ if (instance_name == NULL)
kvm_stop_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_stop(instance_name, instance);
+ r = do_stop(instance_name, instance);
+
+ close(instance);
+
+ return r;
}