From e9abaef0b7e5758371ed023af9cda99a48330d15 Mon Sep 17 00:00:00 2001 From: Alexander Turenko <alexander.turenko@tarantool.org> Date: Sun, 12 Apr 2020 15:54:06 +0300 Subject: [PATCH] popen: fix close-on-exec flag setting 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. Acked-by: Cyrill Gorcunov <gorcunov@gmail.com> --- 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 4d57cd41ea..1733e51316 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; } -- GitLab