From: Michal Sojka Date: Sun, 30 Apr 2017 07:51:20 +0000 (+0200) Subject: procd/rcS: Use /dev/null as stdin X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fprocd.git;a=commitdiff_plain;h=d42b21ed9305 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 --- 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); }