[PATCH procd] Fix retriggering of init.d-scripts.

Markus Gothe markus.gothe at genexis.eu
Mon Aug 28 07:12:01 PDT 2023


Fix retriggering of init.d-scripts which calls
commands dependent on functional STDIN/STDOUT/STDERR.

If we just close these file descriptors those commands
will not work as expected leading to unwanted
consequences. If we instead redirect the file descriptors
to /dev/null, we will end up the same end-result and these
commands will work as expected.

Signed-off-by: Markus Gothe <markus.gothe at genexis.eu>
---
  service/trigger.c | 13 ++++++++++---
  1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/service/trigger.c b/service/trigger.c
index 4af1474..324d78e 100644
--- a/service/trigger.c
+++ b/service/trigger.c
@@ -118,9 +118,16 @@ static void trigger_command_run(struct runqueue *q, 
struct runqueue_task *t)
      }

      if (debug < 3) {
-        close(STDIN_FILENO);
-        close(STDOUT_FILENO);
-        close(STDERR_FILENO);
+        int devnull = open("/dev/null", O_RDWR);
+
+        if (devnull >= 0) {
+            dup2(devnull, STDIN_FILENO);
+            dup2(devnull, STDOUT_FILENO);
+            dup2(devnull, STDERR_FILENO);
+
+            if (devnull > STDERR_FILENO)
+                close(devnull);
+        }
      }

      blobmsg_for_each_attr(cur, cmd->data, rem)
-- 
2.34.1


More information about the openwrt-devel mailing list