mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
Fix #120: Redirect stdin to /dev/null for services by default
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
ff24ee3553
commit
770a79fa89
1 file changed
+21
-1
+21
-1
@@ -116,6 +116,23 @@ static int service_timeout_cancel(svc_t *svc)
|
|||||||
return err;
|
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
|
* 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);
|
close(svc->stdin_fd);
|
||||||
dup2(STDIN_FILENO, STDOUT_FILENO);
|
dup2(STDIN_FILENO, STDOUT_FILENO);
|
||||||
dup2(STDIN_FILENO, STDERR_FILENO);
|
dup2(STDIN_FILENO, STDERR_FILENO);
|
||||||
} else
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
stdin_redirect();
|
||||||
|
|
||||||
if (svc->log.enabled) {
|
if (svc->log.enabled) {
|
||||||
if (svc->log.null)
|
if (svc->log.null)
|
||||||
|
|||||||
Reference in new issue
Block a user