procd/rcS: Use /dev/null as stdin
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 30 Apr 2017 07:51:20 +0000 (09:51 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 9 May 2017 20:59:12 +0000 (22:59 +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 0dc0aa2..913fc9a 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]);
                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);
 
        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);
 }
        execlp(s->file, s->file, s->param, NULL);
        exit(1);
 }