[PATCH] kvm tools: Avoid overwriting socket files with same name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch prevents overwriting socket files by running two instances with
the same name.

Reported-by: Osier Yang <jyang@xxxxxxxxxx>
Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
---
 tools/kvm/kvm.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 8d6b5e1..f700d78 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -152,6 +152,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;
-- 
1.7.7

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux