]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-spawn: search executed command in build directory 36985/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 3 Apr 2025 11:07:33 +0000 (20:07 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 4 Apr 2025 12:10:25 +0000 (21:10 +0900)
This should be useful when debugging RUN{program}= and friends.

src/udev/udev-spawn.c

index 9bd6847ef45c1262d3ccf60b5ec1730740ccab96..62db775250311037822f9eedf28e28d62eab0cf2 100644 (file)
@@ -2,9 +2,11 @@
 
 #include "sd-event.h"
 
+#include "build-path.h"
 #include "device-private.h"
 #include "device-util.h"
 #include "event-util.h"
+#include "exec-util.h"
 #include "fd-util.h"
 #include "path-util.h"
 #include "process-util.h"
@@ -279,6 +281,14 @@ int udev_event_spawn(
                 free_and_replace(argv[0], program);
         }
 
+        char *found;
+        _cleanup_close_ int fd_executable = r = pin_callout_binary(argv[0], &found);
+        if (r < 0)
+                return log_device_error_errno(event->dev, r, "Failed to find and pin callout binary \"%s\": %m", argv[0]);
+
+        log_device_debug(event->dev, "Found callout binary: \"%s\".", found);
+        free_and_replace(argv[0], found);
+
         char **envp;
         r = device_get_properties_strv(event->dev, &envp);
         if (r < 0)
@@ -290,7 +300,7 @@ int udev_event_spawn(
         r = pidref_safe_fork_full(
                         "(spawn)",
                         (int[]) { -EBADF, outpipe[WRITE_END], errpipe[WRITE_END] },
-                        NULL, 0,
+                        &fd_executable, 1,
                         FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_REARRANGE_STDIO|FORK_LOG|FORK_RLIMIT_NOFILE_SAFE,
                         &pidref);
         if (r < 0)
@@ -298,7 +308,7 @@ int udev_event_spawn(
                                               "Failed to fork() to execute command '%s': %m", cmd);
         if (r == 0) {
                 DEVICE_TRACE_POINT(spawn_exec, event->dev, cmd);
-                execve(argv[0], argv, envp);
+                (void) fexecve_or_execve(fd_executable, argv[0], argv, envp);
                 _exit(EXIT_FAILURE);
         }