diff options
| author | Jo-Philipp Wich | 2018-12-21 08:09:55 +0000 |
|---|---|---|
| committer | Jo-Philipp Wich | 2020-05-26 14:21:13 +0000 |
| commit | cd09c5f3512c9d6dca0c0ed7144cb1a994672454 (patch) | |
| tree | 244aec5cdb0489aa5614d574a36c415e269b7c6b | |
| parent | efbcedb76186d4e86c4a538ea93289e7c10a88cb (diff) | |
file: patch process stdin to /dev/null
This prevents broken pipe errors in executed child processes that
attempt to access stdin.
Suggested-by: Vytautas Virvičius <vy.virvicius@gmail.com>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 67118a6b334cd50c9f39a0c04506befd49bf592a)
| -rw-r--r-- | file.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -597,6 +597,7 @@ rpc_file_exec_run(const char *cmd, { pid_t pid; + int devnull; int opipe[2]; int epipe[2]; @@ -629,10 +630,16 @@ rpc_file_exec_run(const char *cmd, case 0: uloop_done(); + devnull = open("/dev/null", O_RDWR); + + if (devnull == -1) + return UBUS_STATUS_UNKNOWN_ERROR; + + dup2(devnull, 0); dup2(opipe[1], 1); dup2(epipe[1], 2); - close(0); + close(devnull); close(opipe[0]); close(opipe[1]); close(epipe[0]); |