From: Lennart Poettering Date: Sat, 23 Dec 2017 23:54:40 +0000 (+0100) Subject: terminal-util: open /dev/null with O_CLOEXEC in make_stdio_null() X-Git-Tag: v237~173^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d8caff6db672ab0f2d8064c61f5ef0e8e8d288ca;p=thirdparty%2Fsystemd.git terminal-util: open /dev/null with O_CLOEXEC in make_stdio_null() Ultimately, O_CLOEXEC should be off in fd 0, 1, 2, but when we open /dev/null here it's unlikely to be < 0, and after dupping the fd to 0, 1, 2 we turn off O_CLOEXEC explicitly anyway. Unless we know that what we are about to open will return 0, 1 or 2 we should always set O_CLOEXEC in order to be safe to other threads forking of subprocesses at the wrong moment. --- diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 4d849981890..6051daf5bb5 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -898,7 +898,7 @@ int make_stdio(int fd) { int make_null_stdio(void) { int null_fd; - null_fd = open("/dev/null", O_RDWR|O_NOCTTY); + null_fd = open("/dev/null", O_RDWR|O_NOCTTY|O_CLOEXEC); if (null_fd < 0) return -errno;