From 83319e5ec7ae13794ebf39f753d643a2a439f594 Mon Sep 17 00:00:00 2001 From: Sergey Zagursky Date: Thu, 9 Jul 2026 09:23:43 +0100 Subject: main: fix reversed dup2 arguments in daemonize daemonize() intends to redirect the daemon's stdout and stderr to /dev/null, but the dup2() arguments are reversed. dup2(oldfd, newfd) duplicates oldfd onto newfd; the code passes STDOUT_FILENO/STDERR_FILENO as oldfd and the freshly opened /dev/null descriptor as newfd, so it overwrites the /dev/null fd with stdout/stderr and then closes it. stdout and stderr are never redirected and stay attached to the controlling terminal. Swap the arguments so /dev/null is duplicated onto STDOUT_FILENO and STDERR_FILENO as intended. --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 07e6667..9e6401f 100644 --- a/main.c +++ b/main.c @@ -66,8 +66,8 @@ static void daemonize(void) { setsid(); close(fds[0]); int devnull = open("/dev/null", O_RDWR); - dup2(STDOUT_FILENO, devnull); - dup2(STDERR_FILENO, devnull); + dup2(devnull, STDOUT_FILENO); + dup2(devnull, STDERR_FILENO); close(devnull); uint8_t success = 0; if (chdir("/") != 0) { -- cgit v1.2.3