Skip to content

Commit a3613d2

Browse files
committed
BUILD: init: use the more portable FD_CLOEXEC for /dev/null
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.
1 parent f054830 commit a3613d2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/haproxy.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3920,11 +3920,16 @@ int main(int argc, char **argv)
39203920

39213921
/* End of initialization for standalone and worker modes */
39223922
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) {
3923-
devnullfd = open("/dev/null", (O_RDWR | O_CLOEXEC), 0);
3923+
devnullfd = open("/dev/null", O_RDWR, 0);
39243924
if (devnullfd < 0) {
39253925
ha_alert("Cannot open /dev/null\n");
39263926
exit(EXIT_FAILURE);
39273927
}
3928+
if (fcntl(devnullfd, FD_CLOEXEC) != 0) {
3929+
ha_alert("Cannot make /dev/null CLOEXEC\n");
3930+
close(devnullfd);
3931+
exit(EXIT_FAILURE);
3932+
}
39283933
}
39293934

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

0 commit comments

Comments
 (0)