static bool mem;
static bool all;
-static int instance;
static const char *instance_name;
static const char * const stat_usage[] = {
int kvm_cmd_stat(int argc, const char **argv, const char *prefix)
{
+ int instance;
+ int r = 0;
+
parse_stat_options(argc, argv);
if (!mem)
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;
}