blob: 2c4b43bd033e6d615dec640dc82aef893cadd481 [file] [log] [blame]
From c4de31e1e2f1b2f78aeccd3df94199110610d9c5 Mon Sep 17 00:00:00 2001
From: Michael Biebl <biebl@debian.org>
Date: Tue, 29 Sep 2020 08:11:40 +0200
Subject: [PATCH] udev: search for udev callouts in both /lib/udev and
/usr/lib/udev
When systemd is built with split-usr support, udev rules can be
installed in both /lib/udev/rules.d and /usr/lib/udev/rules.d.
For udev callouts that aren't specified with a full path, try to find
the executable in both locations.
---
src/udev/udev-event.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index cd1a926602bd..ab736a72ff2d 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -6,6 +6,7 @@
#include <net/if.h>
#include <stddef.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -760,11 +761,22 @@ int udev_event_spawn(UdevEvent *event,
/* allow programs in /usr/lib/udev/ to be called without the path */
if (!path_is_absolute(argv[0])) {
char *program;
-
- program = path_join(UDEVLIBEXECDIR, argv[0]);
- if (!program)
+ char *executable;
+ _cleanup_free_ char *oldpath = NULL;
+
+ executable = strtok((char *)cmd, " ");
+ if (!executable)
+ return log_device_error_errno(event->dev, r, "Failed to get executable: %m", cmd);
+ oldpath = strdup(getenv("PATH"));
+ if (!oldpath)
return log_oom();
+ setenv("PATH", "/usr/lib/udev:/lib/udev", 1);
+ r = find_executable(executable, &program);
+ setenv("PATH", oldpath, 1);
+ if (r < 0)
+ return log_device_error_errno(event->dev, r, "Failed to determine whether udev helper '%s' exists: %m", cmd);
+
free_and_replace(argv[0], program);
}