procd/rcS: Use /dev/null as stdin
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 30 Apr 2017 07:51:20 +0000 (09:51 +0200)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 20 Jun 2017 14:48:43 +0000 (16:48 +0200)
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 <sojkam1@fel.cvut.cz>
rcS.c

diff --git a/rcS.c b/rcS.c
index 0dc0aa2fea02b400c6cd4798c1926671acc0bd14..913fc9a5f5b243702f692040df0c9239ef19169d 100644 (file)
--- 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);
 }