device-mapper-multipath/0138-multipath-tools-tests-check-if-sys-dev-block-is-non-.patch
Benjamin Marzinski b05147c356 device-mapper-multipath-0.8.5-6
Change patch format to remove Git version
  * Patches 0001-0122 only have the patch format modified
Update to the head of the upstream staging branch plus redhat patches
  * Patches 0123-0134 & 1036-0142 are from the upstream staging branch
  * Patches 0143-1046 have been submitted upstream
  * Patch 0156 is a Red Hat only patch. Red Hat udev rules set ID_SERIAL
    from 60-persistent-storage.rules instead of 55-scsi-sg3_id.rules.
    Multipath's parse_vpd_pg83() function needs to match the ID_SERIAL
    value from udev.
Rename files
  * Previous patches 0123-0132 are now patches 1035 & 0147-0155
2021-03-26 13:33:56 -05:00

63 lines
1.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martin Wilck <mwilck@suse.com>
Date: Thu, 18 Mar 2021 09:50:55 +0100
Subject: [PATCH] multipath-tools tests: check if /sys/dev/block is non-empty
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")
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
tests/devt.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/tests/devt.c b/tests/devt.c
index 02f2e8f3..d971302c 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;
}