[tip:tools/kvm] kvm tools: Fix dirent handling on dirent non-friendly filesystems

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

 



Commit-ID:  1550e2827d4d5f24303bd3c123cee924f737d5a3
Gitweb:     http://git.kernel.org/tip/1550e2827d4d5f24303bd3c123cee924f737d5a3
Author:     Milan Kocian <milon@xxxxx>
AuthorDate: Thu, 6 Jun 2013 23:15:16 +0200
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Fri, 7 Jun 2013 09:38:50 +0300

kvm tools: Fix dirent handling on dirent non-friendly filesystems

Some filesystems don't return valid d_type field in dirent
structure (e.g XFS). So we must handle this case properly.

Signed-off-by: Milan Kocian <milon@xxxxx>
Cc: Sasha Levin <levinsasha928@xxxxxxxxx>
[ penberg@xxxxxxxxxx: cleanups ]
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/kvm-ipc.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/kvm-ipc.c b/tools/kvm/kvm-ipc.c
index 7897519..b1c43dd 100644
--- a/tools/kvm/kvm-ipc.c
+++ b/tools/kvm/kvm-ipc.c
@@ -112,14 +112,38 @@ int kvm__get_sock_by_instance(const char *name)
 	return s;
 }
 
+static bool is_socket(const char *base_path, const struct dirent *dent)
+{
+	switch (dent->d_type) {
+	case DT_SOCK:
+		return true;
+
+	case DT_UNKNOWN: {
+		char path[PATH_MAX];
+		struct stat st;
+
+		sprintf(path, "%s/%s", base_path, dent->d_name);
+		if (stat(path, &st))
+			return false;
+
+		return S_ISSOCK(st.st_mode);
+	}
+	default:
+		return false;
+	}
+}
+
 int kvm__enumerate_instances(int (*callback)(const char *name, int fd))
 {
 	int sock;
 	DIR *dir;
 	struct dirent entry, *result;
 	int ret = 0;
+	const char *path;
+
+	path = kvm__get_dir();
 
-	dir = opendir(kvm__get_dir());
+	dir = opendir(path);
 	if (!dir)
 		return -errno;
 
@@ -127,7 +151,7 @@ int kvm__enumerate_instances(int (*callback)(const char *name, int fd))
 		readdir_r(dir, &entry, &result);
 		if (result == NULL)
 			break;
-		if (entry.d_type == DT_SOCK) {
+		if (is_socket(path, &entry)) {
 			ssize_t name_len = strlen(entry.d_name);
 			char *p;
 
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux