service: minor refactor of stdin redirect

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