From aac7f6e8f249cd72a114b33cb67bf4ad81633ca3 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 29 Jan 2020 16:03:12 -0800 Subject: [PATCH 1/3] Set Pipe file descriptor flags correctly --- src/Pipe.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pipe.cc b/src/Pipe.cc index 9957e25dce..f388366c5d 100644 --- a/src/Pipe.cc +++ b/src/Pipe.cc @@ -92,8 +92,8 @@ Pipe::Pipe(int flags0, int flags1, int status_flags0, int status_flags1, pipe_fail(errno); } - flags[0] = set_flags(fds[0], flags[0]); - flags[1] = set_flags(fds[1], flags[1]); + flags[0] = set_flags(fds[0], flags0); + flags[1] = set_flags(fds[1], flags1); status_flags[0] = set_status_flags(fds[0], status_flags0); status_flags[1] = set_status_flags(fds[1], status_flags1); } From fd2c6c56a5dd693eb3387662dcbed94d4fd4fb26 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 29 Jan 2020 16:04:46 -0800 Subject: [PATCH 2/3] Add checks for failed fcntl calls --- src/Pipe.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Pipe.cc b/src/Pipe.cc index f388366c5d..5a0916a3dd 100644 --- a/src/Pipe.cc +++ b/src/Pipe.cc @@ -24,6 +24,9 @@ static int set_flags(int fd, int flags) { auto rval = fcntl(fd, F_GETFD); + if ( rval == -1 ) + pipe_fail(errno); + if ( flags ) { rval |= flags; @@ -39,6 +42,9 @@ static int unset_flags(int fd, int flags) { auto rval = fcntl(fd, F_GETFD); + if ( rval == -1 ) + pipe_fail(errno); + if ( flags ) { rval &= ~flags; @@ -54,6 +60,9 @@ static int set_status_flags(int fd, int flags) { auto rval = fcntl(fd, F_GETFL); + if ( rval == -1 ) + pipe_fail(errno); + if ( flags ) { rval |= flags; From 948cc32844432413aac192d125805c66f0ca13b5 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 29 Jan 2020 16:05:39 -0800 Subject: [PATCH 3/3] Fix leaked FDs in redirecting supervised node stdout/stderr --- src/supervisor/Supervisor.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 4d971a1068..4d41383a85 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1241,6 +1241,8 @@ void Supervisor::SupervisedNode::Init(zeek::Options* options) const strerror(errno)); exit(1); } + + safe_close(fd); } if ( config.stdout_file ) @@ -1256,6 +1258,8 @@ void Supervisor::SupervisedNode::Init(zeek::Options* options) const strerror(errno)); exit(1); } + + safe_close(fd); } if ( config.cpu_affinity )