[Tarantool-patches] [PATCH 08/12] popen: fix close-on-exec flag setting

Alexander Turenko alexander.turenko at tarantool.org
Tue Apr 14 14:38:17 MSK 2020


fcntl(2) lists flags that can be set using F_SETFL: O_CLOEXEC is not
included there. F_SETFD should be used to set close-on-exec.

Parent's end of pipes are closed explicitly in a child process anyway.
However this change fixes closing of the copy of a logger fd. See commit
07a07b3cc7b85375d20b3fc6ca1e5060304f337b ('popen: decouple logger fd
from stderr') for more information why this file descriptor was
introduced.

Part of #4031.
---
 src/lib/core/popen.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c
index 4d57cd41e..1733e5131 100644
--- a/src/lib/core/popen.c
+++ b/src/lib/core/popen.c
@@ -638,8 +638,8 @@ make_pipe(int pfd[2])
 		diag_set(SystemError, "Can't create pipe");
 		return -1;
 	}
-	if (fcntl(pfd[0], F_SETFL, O_CLOEXEC) ||
-	    fcntl(pfd[1], F_SETFL, O_CLOEXEC)) {
+	if (fcntl(pfd[0], F_SETFD, FD_CLOEXEC) ||
+	    fcntl(pfd[1], F_SETFD, FD_CLOEXEC)) {
 		int saved_errno = errno;
 		diag_set(SystemError, "Can't unblock pipe");
 		close(pfd[0]), pfd[0] = -1;
@@ -899,9 +899,9 @@ popen_new(struct popen_opts *opts)
 		say_debug("popen: duplicate logfd: %d", log_fd);
 		if (log_fd < 0)
 			return NULL;
-		if (fcntl(log_fd, F_SETFL, O_CLOEXEC) != 0) {
+		if (fcntl(log_fd, F_SETFD, FD_CLOEXEC) != 0) {
 			diag_set(SystemError,
-				 "Unable to set O_CLOEXEC on temporary logfd");
+				 "Unable to set FD_CLOEXEC on temporary logfd");
 			close(log_fd);
 			return NULL;
 		}
-- 
2.25.0



More information about the Tarantool-patches mailing list