diff options
| author | Sergey Zagursky <sz@joom.com> | 2026-07-09 09:23:43 +0100 |
|---|---|---|
| committer | Kenny Levinsen <kl@kl.wtf> | 2026-07-09 11:58:43 +0200 |
| commit | 83319e5ec7ae13794ebf39f753d643a2a439f594 (patch) | |
| tree | 85a94513149a4666ee1001afa599f40c90feb9fb | |
| parent | 1a4c472c11ee0354e5a689e33fad4ecce533ddc3 (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.
| -rw-r--r-- | main.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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) { |
