summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorSergey Zagursky <sz@joom.com>2026-07-09 09:23:43 +0100
committerKenny Levinsen <kl@kl.wtf>2026-07-09 11:58:43 +0200
commit83319e5ec7ae13794ebf39f753d643a2a439f594 (patch)
tree85a94513149a4666ee1001afa599f40c90feb9fb /main.c
parent1a4c472c11ee0354e5a689e33fad4ecce533ddc3 (diff)
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.
Diffstat (limited to 'main.c')
-rw-r--r--main.c4
1 files 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) {