service: minor refactor of stdin redirect

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2025-07-02 16:36:57 +02:00
parent 91f7a75bee
commit 0da6bbe4a8
+10 -9
View File
@@ -208,13 +208,16 @@ 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);
fd = open("/dev/null", O_RDONLY);
if (fd == -1) {
warn("Failed opening /dev/null for stdin redirect");
return -1;
}
return -1;
dup2(fd, STDIN_FILENO);
close(fd);
return 0;
}
/*
@@ -261,12 +264,10 @@ static void fallback_logger(char *ident, char *prio)
static int lredirect(svc_t *svc)
{
static int have_sysklogd = -1;
pid_t pid, svc_pid;
pid_t svc_pid = getpid();
pid_t pid;
int fd;
svc_pid = getpid();
dbg("%s pid: %d", svc_ident(svc, NULL, 0), svc_pid);
/*
* Open PTY to connect to logger. A pty isn't buffered
* like a pipe, and it eats newlines so they aren't logged