]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Avoid overwriting socket files with same name
authorSasha Levin <levinsasha928@gmail.com>
Tue, 25 Oct 2011 13:21:49 +0000 (15:21 +0200)
committerPekka Enberg <penberg@kernel.org>
Tue, 25 Oct 2011 13:24:17 +0000 (16:24 +0300)
This patch prevents overwriting socket files by running two instances with
the same name.

Reported-by: Osier Yang <jyang@redhat.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/kvm.c

index 6f1f107c69b59d5857f1f92cc2c4266137a32268..f470c1707b4c39191b1bc21eb95e8976f9824896 100644 (file)
@@ -157,6 +157,9 @@ static int kvm__create_socket(struct kvm *kvm)
        sprintf(full_name, "%s", kvm__get_dir());
        mkdir(full_name, 0777);
        sprintf(full_name, "%s/%s.sock", kvm__get_dir(), kvm->name);
+       if (access(full_name, F_OK) == 0)
+               die("Socket file %s already exist", full_name);
+
        s = socket(AF_UNIX, SOCK_STREAM, 0);
        if (s < 0)
                return s;