hotplug-dispatch: redirect output to /dev/null
authorFlorian Eckert <fe@dev.tdt.de>
Tue, 8 Apr 2025 10:01:21 +0000 (12:01 +0200)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 9 Feb 2026 11:06:54 +0000 (11:06 +0000)
During the hotplug call via the procd, a list is first created with the files
in the hotplug.d directory. After that the scripts are then executed in
lexical order. However, if a script is deleted after the list has been
created, the following message is displayed on the tty console.

Command failed: Not found
/bin/sh: .: line 1: can't open '/etc/hotplug.d/ntp/25-travelmate_ntp': No such file or directory

So that the message is not displayed in the tty console the 'stderr' must be
redirected to '/dev/null'.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
hotplug-dispatch.c

index c89c90a2343534a83e5ed2b6a6a8afb5e30d42bf..aa0fcb96a2193474fb5500725347a71c353f708f 100644 (file)
@@ -33,6 +33,7 @@
 #include <libubus.h>
 
 #include "procd.h"
+#include "utils/utils.h"
 
 #define HOTPLUG_BASEDIR "/etc/hotplug.d"
 #define HOTPLUG_OBJECT_PREFIX "hotplug."
@@ -120,7 +121,10 @@ static void hotplug_exec(struct uloop_timeout *t)
        pc->process.pid = fork();
        if (pc->process.pid == 0) {
                /* child */
-               exit(execve(exec_argv[0], exec_argv, pc->envp));
+               patch_stdio("/dev/null");
+               execve(exec_argv[0], exec_argv, pc->envp);
+               ERROR("Failed to execute script: %m\n");
+               exit(EXIT_FAILURE);
        } else if (pc->process.pid < 0) {
                /* fork error */
                free(script);