Skip to content

Commit

Permalink
BUILD: init: use the more portable FD_CLOEXEC for /dev/null
Browse files Browse the repository at this point in the history
In 3.1-dev10, commit 8dd4efe ("MAJOR: mworker: move master-worker
fork in init()"), the FD associated to /dev/null was made CLOEXEC
using O_CLOEXEC. Unfortunately this is not portable on older OSes,
doesn't build on Solaris for example, and was even reported as breaking
moderately old Linux OSes for other projects. Better not use it unless
absolutely certain it will work (currently we only use it for Linux
namespaces, which are optional), and use the conventional FD_CLOEXEC
instead.

No backport is needed.
  • Loading branch information
wtarreau committed Nov 25, 2024
1 parent f054830 commit a3613d2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/haproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3920,11 +3920,16 @@ int main(int argc, char **argv)

/* End of initialization for standalone and worker modes */
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) {
devnullfd = open("/dev/null", (O_RDWR | O_CLOEXEC), 0);
devnullfd = open("/dev/null", O_RDWR, 0);
if (devnullfd < 0) {
ha_alert("Cannot open /dev/null\n");
exit(EXIT_FAILURE);
}
if (fcntl(devnullfd, FD_CLOEXEC) != 0) {
ha_alert("Cannot make /dev/null CLOEXEC\n");
close(devnullfd);
exit(EXIT_FAILURE);
}
}

/* applies the renice value in the worker or standalone after configuration parsing
Expand Down

0 comments on commit a3613d2

Please sign in to comment.