Fix #120: Redirect stdin to /dev/null for services by default

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2020-04-11 22:24:33 +02:00
parent ff24ee3553
commit 770a79fa89
+21 -1
View File
@@ -116,6 +116,23 @@ static int service_timeout_cancel(svc_t *svc)
return err;
}
/*
* Redirect stdin to /dev/null => all reads by process = EOF
* https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Logging%20and%20Standard%20Input/Output
*/
static int stdin_redirect(void)
{
int fd;
fd = open("/dev/null", O_RDONLY | O_APPEND);
if (-1 != fd) {
dup2(fd, STDIN_FILENO);
return close(fd);
}
return -1;
}
/*
* Redirect output to a file, e.g., /dev/null, or /dev/console
*/
@@ -238,8 +255,11 @@ static int redirect(svc_t *svc)
close(svc->stdin_fd);
dup2(STDIN_FILENO, STDOUT_FILENO);
dup2(STDIN_FILENO, STDERR_FILENO);
} else
return 0;
}
#endif
stdin_redirect();
if (svc->log.enabled) {
if (svc->log.null)