From 365c992f80420944993784fdece5d55a7603360c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Jun 2018 15:48:50 +0530 Subject: [PATCH] Fix only one the two fds created by self_pipe having CLOEXEC and NONBLOCK set --- kitty/child-monitor.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 57797bdb4..de027f5a2 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -114,12 +114,14 @@ self_pipe(int fds[2]) { int flags; flags = pipe(fds); if (flags != 0) return false; - flags = fcntl(fds[0], F_GETFD); - if (flags == -1) { return false; } - if (fcntl(fds[0], F_SETFD, flags | FD_CLOEXEC) == -1) { return false; } - flags = fcntl(fds[0], F_GETFL); - if (flags == -1) { return false; } - if (fcntl(fds[0], F_SETFL, flags | O_NONBLOCK) == -1) { return false; } + for (int i = 0; i < 2; i++) { + flags = fcntl(fds[i], F_GETFD); + if (flags == -1) { return false; } + if (fcntl(fds[i], F_SETFD, flags | FD_CLOEXEC) == -1) { return false; } + flags = fcntl(fds[i], F_GETFL); + if (flags == -1) { return false; } + if (fcntl(fds[i], F_SETFL, flags | O_NONBLOCK) == -1) { return false; } + } return true; }