Made platform-dependent subprocess helpers internal. Remove platform-dependent subprocess helper code from the public header file so that clients don't have to pay the cost of importing the unnecessary definitions.
Review: https://reviews.apache.org/r/60521/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e38ed106 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e38ed106 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e38ed106 Branch: refs/heads/master Commit: e38ed106946ac99faa8a94ee4daa5495205029f5 Parents: c486544 Author: James Peach <jpe...@apache.org> Authored: Wed Jul 12 17:01:13 2017 -0700 Committer: Greg Mann <gregorywm...@gmail.com> Committed: Wed Jul 12 17:01:13 2017 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/include/Makefile.am | 6 ++-- .../include/process/posix/subprocess.hpp | 21 ++++++------ .../libprocess/include/process/subprocess.hpp | 6 ---- .../include/process/subprocess_base.hpp | 32 ----------------- 3rdparty/libprocess/src/subprocess.cpp | 36 +++++++++++++++++++- 5 files changed, 49 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/e38ed106/3rdparty/libprocess/include/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/Makefile.am b/3rdparty/libprocess/include/Makefile.am index 6322815..e6aebf0 100644 --- a/3rdparty/libprocess/include/Makefile.am +++ b/3rdparty/libprocess/include/Makefile.am @@ -48,7 +48,6 @@ nobase_include_HEADERS = \ process/metrics/metric.hpp \ process/metrics/metrics.hpp \ process/metrics/timer.hpp \ - process/posix/subprocess.hpp \ process/network.hpp \ process/once.hpp \ process/owned.hpp \ @@ -72,5 +71,8 @@ nobase_include_HEADERS = \ process/time.hpp \ process/timeout.hpp \ process/timer.hpp \ - process/timeseries.hpp \ + process/timeseries.hpp + +noinst_HEADERS = \ + process/posix/subprocess.hpp \ process/windows/subprocess.hpp http://git-wip-us.apache.org/repos/asf/mesos/blob/e38ed106/3rdparty/libprocess/include/process/posix/subprocess.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/posix/subprocess.hpp b/3rdparty/libprocess/include/process/posix/subprocess.hpp index a5d10ce..b478bec 100644 --- a/3rdparty/libprocess/include/process/posix/subprocess.hpp +++ b/3rdparty/libprocess/include/process/posix/subprocess.hpp @@ -43,6 +43,16 @@ #include <stout/os/strerror.hpp> namespace process { +namespace internal { + +static void close(std::initializer_list<int_fd> fds); + + +static void close( + const Subprocess::IO::InputFileDescriptors& stdinfds, + const Subprocess::IO::OutputFileDescriptors& stdoutfds, + const Subprocess::IO::OutputFileDescriptors& stderrfds); + inline pid_t defaultClone(const lambda::function<int()>& func) { @@ -60,8 +70,6 @@ inline pid_t defaultClone(const lambda::function<int()>& func) } -namespace internal { - // This function will invoke `os::cloexec` on all specified file // descriptors that are valid (i.e., not `None` and >= 0). inline Try<Nothing> cloexec( @@ -91,15 +99,6 @@ inline Try<Nothing> cloexec( } -inline void signalHandler(int signal) -{ - // Send SIGKILL to every process in the process group of the - // calling process. - kill(0, SIGKILL); - abort(); -} - - // The main entry of the child process. // // NOTE: This function has to be async signal safe. http://git-wip-us.apache.org/repos/asf/mesos/blob/e38ed106/3rdparty/libprocess/include/process/subprocess.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/subprocess.hpp b/3rdparty/libprocess/include/process/subprocess.hpp index 106798d..e259ac0 100644 --- a/3rdparty/libprocess/include/process/subprocess.hpp +++ b/3rdparty/libprocess/include/process/subprocess.hpp @@ -17,10 +17,4 @@ // include the platform-dependent versions of the headers. #include <process/subprocess_base.hpp> -#ifndef __WINDOWS__ -#include <process/posix/subprocess.hpp> -#else -#include <process/windows/subprocess.hpp> -#endif // __WINDOWS__ - #endif // __PROCESS_SUBPROCESS_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/e38ed106/3rdparty/libprocess/include/process/subprocess_base.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/subprocess_base.hpp b/3rdparty/libprocess/include/process/subprocess_base.hpp index d33be2b..898ce94 100644 --- a/3rdparty/libprocess/include/process/subprocess_base.hpp +++ b/3rdparty/libprocess/include/process/subprocess_base.hpp @@ -13,12 +13,8 @@ #ifndef __PROCESS_SUBPROCESS_BASE_HPP__ #define __PROCESS_SUBPROCESS_BASE_HPP__ -#include <sys/types.h> - -#include <initializer_list> #include <map> #include <memory> -#include <mutex> #include <string> #include <vector> @@ -434,34 +430,6 @@ inline Try<Subprocess> subprocess( child_hooks); } -namespace internal { - -inline void close(std::initializer_list<int_fd> fds) -{ - foreach (int_fd fd, fds) { - if (fd >= 0) { - os::close(fd); - } - } -} - -// This function will invoke `os::close` on all specified file -// descriptors that are valid (i.e., not `None` and >= 0). -inline void close( - const Subprocess::IO::InputFileDescriptors& stdinfds, - const Subprocess::IO::OutputFileDescriptors& stdoutfds, - const Subprocess::IO::OutputFileDescriptors& stderrfds) -{ - close( - {stdinfds.read, - stdinfds.write.getOrElse(-1), - stdoutfds.read.getOrElse(-1), - stdoutfds.write, - stderrfds.read.getOrElse(-1), - stderrfds.write}); -} - -} // namespace internal { } // namespace process { #endif // __PROCESS_SUBPROCESS_BASE_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/e38ed106/3rdparty/libprocess/src/subprocess.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/subprocess.cpp b/3rdparty/libprocess/src/subprocess.cpp index 8f8a715..8e1a944 100644 --- a/3rdparty/libprocess/src/subprocess.cpp +++ b/3rdparty/libprocess/src/subprocess.cpp @@ -23,6 +23,7 @@ #endif // __linux__ #include <sys/types.h> +#include <initializer_list> #include <string> #include <glog/logging.h> @@ -31,6 +32,12 @@ #include <process/reap.hpp> #include <process/subprocess.hpp> +#ifdef __WINDOWS__ +#include <process/windows/subprocess.hpp> +#else +#include <process/posix/subprocess.hpp> +#endif // __WINDOWS__ + #include <stout/error.hpp> #include <stout/lambda.hpp> #include <stout/foreach.hpp> @@ -110,7 +117,7 @@ Subprocess::ChildHook Subprocess::ChildHook::UNSET_CLOEXEC(int fd) #ifdef __linux__ -inline void signalHandler(int signal) +static void signalHandler(int signal) { // Send SIGKILL to every process in the process group of the // calling process. @@ -266,6 +273,33 @@ static void cleanup( delete promise; } + +static void close(std::initializer_list<int_fd> fds) +{ + foreach (int_fd fd, fds) { + if (fd >= 0) { + os::close(fd); + } + } +} + + +// This function will invoke `os::close` on all specified file +// descriptors that are valid (i.e., not `None` and >= 0). +static void close( + const Subprocess::IO::InputFileDescriptors& stdinfds, + const Subprocess::IO::OutputFileDescriptors& stdoutfds, + const Subprocess::IO::OutputFileDescriptors& stderrfds) +{ + close( + {stdinfds.read, + stdinfds.write.getOrElse(-1), + stdoutfds.read.getOrElse(-1), + stdoutfds.write, + stderrfds.read.getOrElse(-1), + stderrfds.write}); +} + } // namespace internal {