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

Benjamin Marzinski bmarzins at redhat.com
Thu Mar 18 15:11:02 UTC 2021


On Thu, Mar 18, 2021 at 10:14:13AM +0100, mwilck at suse.com wrote:
> From: Martin Wilck <mwilck at suse.com>
> 
> 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 at redhat.com>
> Signed-off-by: Martin Wilck <mwilck at suse.com>
> ---
>  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




More information about the dm-devel mailing list