Skip to content

Commit

Permalink
MINOR: startup: close devnullfd, when daemon mode is applied
Browse files Browse the repository at this point in the history
In case of daemon mode now daemonization fork happens in the early init stage
before parsing and applying the configuration, so we can't close
stdio/stderr/stdout immediately after forking. We keep it open until the most
of configuration, including chroot are applied in order to show alerts, if
there are some problems. To achieve this /dev/null is opened just before calling
chroot(), and after the chroot block it's used to close all standard outputs
and stdin. At this point we no longer need the fd of /dev/null, so we can close
it as well.
  • Loading branch information
vkssv authored and wtarreau committed Oct 16, 2024
1 parent dc53c37 commit c42ad79
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/haproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3948,6 +3948,8 @@ int main(int argc, char **argv)
stdio_quiet(devnullfd);
global.mode &= ~MODE_VERBOSE;
global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
close(devnullfd);
devnullfd = -1;
}
pid = getpid(); /* update pid */
setsid();
Expand Down

0 comments on commit c42ad79

Please sign in to comment.