From: Sasha Levin Subject: [PATCH 2/2] kvm tools: Cleanup ghost socket files Date: Fri, 28 Oct 2011 11:01:55 +0200 Message-ID: <1319792515-15642-2-git-send-email-levinsasha928@gmail.com> References: <1319792515-15642-1-git-send-email-levinsasha928@gmail.com> Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, Sasha Levin To: penberg@cs.helsinki.fi Return-path: Received: from mail-fx0-f46.google.com ([209.85.161.46]:36605 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751571Ab1J1JCK (ORCPT ); Fri, 28 Oct 2011 05:02:10 -0400 Received: by mail-fx0-f46.google.com with SMTP id n17so3434950faa.19 for ; Fri, 28 Oct 2011 02:02:09 -0700 (PDT) In-Reply-To: <1319792515-15642-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: Clean ghost socket files as part of the regular connection process. This fixes the bug of 'kvm list' failing with "Failed connecting to instance" when ghost socket files existed. Signed-off-by: Sasha Levin --- tools/kvm/kvm.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index d953b94..252bd18 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -208,8 +208,13 @@ int kvm__get_sock_by_instance(const char *name) len = strlen(local.sun_path) + sizeof(local.sun_family); r = connect(s, &local, len); - if (r < 0) + if (r < 0 && errno == ECONNREFUSED) { + /* Clean ghost socket file */ + unlink(sock_file); + return -1; + } else if (r < 0) { die("Failed connecting to instance"); + } return s; } @@ -232,6 +237,8 @@ int kvm__enumerate_instances(int (*callback)(const char *name, int fd)) if (entry.d_type == DT_SOCK) { entry.d_name[strlen(entry.d_name)-5] = 0; sock = kvm__get_sock_by_instance(entry.d_name); + if (sock < 0) + continue; ret = callback(entry.d_name, sock); close(sock); if (ret < 0) -- 1.7.7.1