All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2]  mdopen: add sbin path to env PATH when call system("modprobe md_mod")
@ 2025-01-22  3:53 Coly Li
  2025-01-22 12:01 ` Mariusz Tkaczyk
  0 siblings, 1 reply; 5+ messages in thread
From: Coly Li @ 2025-01-22  3:53 UTC (permalink / raw)
  To: mtkaczyk; +Cc: linux-raid, Coly Li

During the boot process if mdadm is called in udev context, sbin paths
like /sbin, /usr/sbin, /usr/local/sbin normally not defined in PATH env
variable, calling system("modprobe md_mod") in create_named_array() may
fail with 'sh: modprobe: command not found' error message.

We don't want to move modprobe binary into udev private directory, so
setting the PATH env is a more proper method to avoid the above issue.

This patch sets PATH env variable with "/sbin:/usr/sbin:/usr/local/sbin"
before calling system("modprobe md_mod"). The change only takes effect
within the udev worker context, not seen by global udev environment.

Signed-off-by: Coly Li <colyli@suse.de>
---
Changelog,
v2: set buf[PATH_MAX] to 0 in stack variable announcement.
v1: the original version.


 mdopen.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/mdopen.c b/mdopen.c
index 26f0c716..65bd8a1b 100644
--- a/mdopen.c
+++ b/mdopen.c
@@ -39,6 +39,17 @@ int create_named_array(char *devnm)
 
 	fd = open(new_array_file, O_WRONLY);
 	if (fd < 0 && errno == ENOENT) {
+		char buf[PATH_MAX] = {0};
+
+		/*
+		 * When called by udev worker context, path of modprobe
+		 * might not be in env PATH. Set sbin paths into PATH
+		 * env to avoid potential failure when run modprobe here.
+		 */
+		snprintf(buf, PATH_MAX - 1, "%s:%s", getenv("PATH"),
+			 "/sbin:/usr/sbin:/usr/local/sbin");
+		setenv("PATH", buf, 1);
+
 		if (system("modprobe md_mod") == 0)
 			fd = open(new_array_file, O_WRONLY);
 	}
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-01-22 15:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-22  3:53 [PATCH v2] mdopen: add sbin path to env PATH when call system("modprobe md_mod") Coly Li
2025-01-22 12:01 ` Mariusz Tkaczyk
2025-01-22 12:43   ` Coly Li
2025-01-22 13:26     ` Mariusz Tkaczyk
2025-01-22 15:30       ` Coly Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.