From d42b21ed9305b91f300f0cebda77e5792f29fc07 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Sun, 30 Apr 2017 09:51:20 +0200 Subject: [PATCH] procd/rcS: Use /dev/null as stdin This change ensures that /etc/init.d/* scripts are started with /dev/null as stdin. This is useful in cases where an init.d script reads (e.g. by mistake) from stdin, which a user can perceive as if some characters typed into shell on serial console are "eaten" by something else (i.e. by the init.d script running on background). This is very annoying, because each character needs to be pressed several times before it appears on the screen. Signed-off-by: Michal Sojka --- rcS.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rcS.c b/rcS.c index 0dc0aa2..913fc9a 100644 --- a/rcS.c +++ b/rcS.c @@ -88,9 +88,15 @@ static void q_initd_run(struct runqueue *q, struct runqueue_task *t) return; } close(pipefd[0]); + + int devnull = open("/dev/null", O_RDONLY); + dup2(devnull, STDIN_FILENO); dup2(pipefd[1], STDOUT_FILENO); dup2(pipefd[1], STDERR_FILENO); + if (devnull > STDERR_FILENO) + close(devnull); + execlp(s->file, s->file, s->param, NULL); exit(1); } -- 2.25.1