From 03803ae8e966755e8bf6d52b61209792cb830cf4 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 24 Apr 2015 11:20:26 -0500 Subject: start-stop-daemon: redirect stdin if --background option is used X-Gentoo-Bug: 498684 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=498684 --- src/rc/start-stop-daemon.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c index 7919835b..7d2aba37 100644 --- a/src/rc/start-stop-daemon.c +++ b/src/rc/start-stop-daemon.c @@ -678,6 +678,7 @@ start_stop_daemon(int argc, char **argv) int tid = 0; char *redirect_stderr = NULL; char *redirect_stdout = NULL; + int stdin_fd; int stdout_fd; int stderr_fd; pid_t pid, spid; @@ -1247,6 +1248,7 @@ start_stop_daemon(int argc, char **argv) setenv("PATH", newpath, 1); } + stdin_fd = devnull_fd; stdout_fd = devnull_fd; stderr_fd = devnull_fd; if (redirect_stdout) { @@ -1266,7 +1268,8 @@ start_stop_daemon(int argc, char **argv) applet, redirect_stderr, strerror(errno)); } - /* We don't redirect stdin as some daemons may need it */ + if (background) + dup2(stdin_fd, STDIN_FILENO); if (background || redirect_stdout || rc_yesno(getenv("EINFO_QUIET"))) dup2(stdout_fd, STDOUT_FILENO); if (background || redirect_stderr || rc_yesno(getenv("EINFO_QUIET"))) -- cgit v1.2.3