Blame SOURCES/0008-filter-sysfs-support-old-kernels-without-sys-dev-blo.patch

429878
From fad2b3dc8c44ba1222508ee78b5f161994efe638 Mon Sep 17 00:00:00 2001
429878
From: David Teigland <teigland@redhat.com>
429878
Date: Tue, 9 Nov 2021 11:54:48 -0600
ab86b0
Subject: [PATCH 08/54] filter-sysfs: support old kernels without sys/dev/block
429878
429878
rhel5 for example doesn't have /sys/dev/block
429878
---
429878
 lib/filters/filter-sysfs.c | 28 ++++++++++++++++++++++++++++
429878
 1 file changed, 28 insertions(+)
429878
429878
diff --git a/lib/filters/filter-sysfs.c b/lib/filters/filter-sysfs.c
429878
index 672211057..d8de7940b 100644
429878
--- a/lib/filters/filter-sysfs.c
429878
+++ b/lib/filters/filter-sysfs.c
429878
@@ -15,6 +15,8 @@
429878
 #include "lib/misc/lib.h"
429878
 #include "lib/filters/filter.h"
429878
 
429878
+static int _sys_dev_block_found;
429878
+
429878
 #ifdef __linux__
429878
 
429878
 static int _accept_p(struct cmd_context *cmd, struct dev_filter *f, struct device *dev, const char *use_filter_name)
429878
@@ -23,6 +25,9 @@ static int _accept_p(struct cmd_context *cmd, struct dev_filter *f, struct devic
429878
 	const char *sysfs_dir;
429878
 	struct stat info;
429878
 
429878
+	if (!_sys_dev_block_found)
429878
+		return 1;
429878
+
429878
 	dev->filtered_flags &= ~DEV_FILTERED_SYSFS;
429878
 
429878
 	/*
429878
@@ -57,6 +62,26 @@ static void _destroy(struct dev_filter *f)
429878
 	free(f);
429878
 }
429878
 
429878
+static void _check_sys_dev_block(void)
429878
+{
429878
+	char path[PATH_MAX];
429878
+	const char *sysfs_dir;
429878
+	struct stat info;
429878
+
429878
+	sysfs_dir = dm_sysfs_dir();
429878
+	if (sysfs_dir && *sysfs_dir) {
429878
+		if (dm_snprintf(path, sizeof(path), "%sdev/block", sysfs_dir) < 0)
429878
+			return;
429878
+
429878
+		if (lstat(path, &info)) {
429878
+			log_debug("filter-sysfs disabled: /sys/dev/block not found");
429878
+			_sys_dev_block_found = 0;
429878
+		} else {
429878
+			_sys_dev_block_found = 1;
429878
+		}
429878
+	}
429878
+}
429878
+
429878
 struct dev_filter *sysfs_filter_create(void)
429878
 {
429878
 	const char *sysfs_dir = dm_sysfs_dir();
429878
@@ -67,6 +92,9 @@ struct dev_filter *sysfs_filter_create(void)
429878
 		return NULL;
429878
 	}
429878
 
429878
+	/* support old kernels that don't have this */
429878
+	_check_sys_dev_block();
429878
+
429878
 	if (!(f = zalloc(sizeof(*f))))
429878
 		goto_bad;
429878
 
429878
-- 
ab86b0
2.34.3
429878