[PATCH v2 3/3] multipath-tools tests: check if /sys/dev/block is non-empty

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

 



From: Martin Wilck <mwilck@xxxxxxxx>

Since f131e31 ("multipath-tools: devt test: avoid failure when run in
containers"), we check the existence of /sys/dev/block before running
the devt test. It turns out that on recent releases of podman (3.0.1),
this check is insufficient, because /sys/dev/block exists now in
containers, albeit empty. So we need to check for actual entries
in the directory.

Fixes: f131e31 ("multipath-tools: devt test: avoid failure when run in containers")
Signed-off-by: Martin Wilck <mwilck@xxxxxxxx>
---
 tests/devt.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/tests/devt.c b/tests/devt.c
index 02f2e8f..d971302 100644
--- a/tests/devt.c
+++ b/tests/devt.c
@@ -13,7 +13,9 @@
 #include <sys/sysmacros.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <unistd.h>
+#include <dirent.h>
 #include "util.h"
 #include "debug.h"
 
@@ -21,12 +23,22 @@
 
 static bool sys_dev_block_exists(void)
 {
-	int fd;
-	bool rc;
+	DIR *dir;
+	bool rc = false;
 
-	fd = open("/sys/dev/block", O_RDONLY|O_DIRECTORY);
-	rc = (fd != -1);
-	close(fd);
+	dir = opendir("/sys/dev/block");
+	if (dir != NULL) {
+		struct dirent *de;
+
+		while((de = readdir(dir)) != NULL) {
+			if (strcmp(de->d_name, ".") &&
+			    strcmp(de->d_name, "..")) {
+				rc = true;
+				break;
+			}
+		}
+	}
+	closedir(dir);
 	return rc;
 }
 
-- 
2.30.1


--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/dm-devel




[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux