Repository: mesos Updated Branches: refs/heads/master 472f935e8 -> 769701ce3
Windows: Stout: Implemented `kill`. Review: https://reviews.apache.org/r/47168/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0613e0db Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0613e0db Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0613e0db Branch: refs/heads/master Commit: 0613e0db20b1a4d813883b9ecfdf786411d2d513 Parents: 472f935 Author: Daniel Pravat <dpra...@outlook.com> Authored: Mon May 16 12:19:42 2016 -0400 Committer: Joris Van Remoortere <joris.van.remoort...@gmail.com> Committed: Mon May 16 12:30:33 2016 -0400 ---------------------------------------------------------------------- 3rdparty/stout/include/Makefile.am | 3 + 3rdparty/stout/include/stout/os/kill.hpp | 26 +++++++ 3rdparty/stout/include/stout/os/posix/kill.hpp | 28 ++++++++ .../stout/include/stout/os/windows/kill.hpp | 73 ++++++++++++++++++++ 3rdparty/stout/include/stout/windows.hpp | 20 ++++-- 5 files changed, 145 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/0613e0db/3rdparty/stout/include/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am index 9b39ce3..23d1497 100644 --- a/3rdparty/stout/include/Makefile.am +++ b/3rdparty/stout/include/Makefile.am @@ -71,6 +71,7 @@ nobase_include_HEADERS = \ stout/os/freebsd.hpp \ stout/os/ftruncate.hpp \ stout/os/getcwd.hpp \ + stout/os/kill.hpp \ stout/os/killtree.hpp \ stout/os/linux.hpp \ stout/os/ls.hpp \ @@ -109,6 +110,7 @@ nobase_include_HEADERS = \ stout/os/posix/fcntl.hpp \ stout/os/posix/fork.hpp \ stout/os/posix/ftruncate.hpp \ + stout/os/posix/kill.hpp \ stout/os/posix/killtree.hpp \ stout/os/posix/mkdtemp.hpp \ stout/os/posix/pagesize.hpp \ @@ -132,6 +134,7 @@ nobase_include_HEADERS = \ stout/os/windows/fcntl.hpp \ stout/os/windows/fork.hpp \ stout/os/windows/ftruncate.hpp \ + stout/os/windows/kill.hpp \ stout/os/windows/killtree.hpp \ stout/os/windows/mkdtemp.hpp \ stout/os/windows/pagesize.hpp \ http://git-wip-us.apache.org/repos/asf/mesos/blob/0613e0db/3rdparty/stout/include/stout/os/kill.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/kill.hpp b/3rdparty/stout/include/stout/os/kill.hpp new file mode 100644 index 0000000..3d72032 --- /dev/null +++ b/3rdparty/stout/include/stout/os/kill.hpp @@ -0,0 +1,26 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef __STOUT_OS_KILL_HPP__ +#define __STOUT_OS_KILL_HPP__ + + +// For readability, we minimize the number of #ifdef blocks in the code by +// splitting platform specifc system calls into separate directories. +#ifdef __WINDOWS__ +#include <stout/os/windows/kill.hpp> +#else +#include <stout/os/posix/kill.hpp> +#endif // __WINDOWS__ + + +#endif // __STOUT_OS_KILL_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/0613e0db/3rdparty/stout/include/stout/os/posix/kill.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/posix/kill.hpp b/3rdparty/stout/include/stout/os/posix/kill.hpp new file mode 100644 index 0000000..c94a292 --- /dev/null +++ b/3rdparty/stout/include/stout/os/posix/kill.hpp @@ -0,0 +1,28 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef __STOUT_OS_POSIX_KILL_HPP__ +#define __STOUT_OS_POSIX_KILL_HPP__ + +#include <signal.h> +#include <sys/types.h> + +namespace os { + +inline int kill(pid_t pid, int sig) +{ + return ::kill(pid, sig); +} + +} // namespace os { + +#endif // __STOUT_OS_POSIX_KILL_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/0613e0db/3rdparty/stout/include/stout/os/windows/kill.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/kill.hpp b/3rdparty/stout/include/stout/os/windows/kill.hpp new file mode 100644 index 0000000..660c872 --- /dev/null +++ b/3rdparty/stout/include/stout/os/windows/kill.hpp @@ -0,0 +1,73 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef __STOUT_OS_WINDOWS_KILL_HPP__ +#define __STOUT_OS_WINDOWS_KILL_HPP__ + +#include <logging/logging.hpp> + +#include <stout/windows.hpp> +#include <stout/windows/os.hpp> + + +namespace os { + +const int KILL_PASS = 0; // Success return for `kill` function. +const int KILL_FAIL = -1; // Error return for `kill` function. + +namespace internal { + +inline int kill_process(pid_t pid) +{ + HANDLE process_handle = ::OpenProcess(PROCESS_TERMINATE, FALSE, pid); + if (process_handle == NULL) { + LOG(ERROR) << "os::kill_process(): Failed call to OpenProcess"; + + return KILL_FAIL; + } + + SharedHandle safe_process_handle(process_handle, ::CloseHandle); + + if (::TerminateProcess(safe_process_handle.get_handle(), 1) != 0) { + LOG(ERROR) << "os::kill_process(): Failed call to TerminateProcess"; + + return KILL_FAIL; + } + + return KILL_PASS; +} + +} // namespace internal { + + +inline int kill(pid_t pid, int sig) +{ + // SIGCONT is not supported. + // SIGKILL call TerminateProcess. + // SIGSTOP and SIGTERM have the same behaviour as SIGKILL. + + if (sig == SIGKILL || sig == SIGSTOP || sig == SIGTERM) { + return os::internal::kill_process(pid); + } + + LOG(ERROR) << "Failed call to os::kill(): " + << "Signal value: '" << sig << "' is not handled. " + << "Valid Signal values for Windows os::kill() are " + << "'SIGSTOP' and 'SIGKILL'"; + + _set_errno(EINVAL); + return KILL_FAIL; +} + +} // namespace os { + +#endif // __STOUT_OS_WINDOWS_KILL_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/0613e0db/3rdparty/stout/include/stout/windows.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/windows.hpp b/3rdparty/stout/include/stout/windows.hpp index 39f204f..1ee457c 100644 --- a/3rdparty/stout/include/stout/windows.hpp +++ b/3rdparty/stout/include/stout/windows.hpp @@ -13,15 +13,16 @@ #ifndef __STOUT_WINDOWS_HPP__ #define __STOUT_WINDOWS_HPP__ - #include <direct.h> // For `_mkdir`. +#include <errno.h> // For `_set_errno`. #include <fcntl.h> // For file access flags like `_O_CREAT`. #include <io.h> // For `_read`, `_write`. +#include <process.h> // For `_getpid`. #include <stdlib.h> // For `_PATH_MAX`. #include <sys/stat.h> // For permissions flags. -#include <BaseTsd.h> // For `SSIZE_T`. +#include <BaseTsd.h> // For `SSIZE_T`. // We include `Winsock2.h` before `Windows.h` explicitly to avoid symbold // re-definitions. This is a known pattern in the windows community. #include <WS2tcpip.h> @@ -303,8 +304,15 @@ const mode_t S_ISVTX = 0x02000000; // No-op. // Flags not supported by Windows. -const mode_t O_SYNC = 0x00000000; // No-op. +const mode_t O_SYNC = 0x00000000; // No-op. +const mode_t O_NONBLOCK = 0x00000000; // No-op. +// Linux signal flags not used in Windows. We define them per +// `Linux sys/signal.h` to branch properly for Windows +// processes' stop, resume and kill. +const mode_t SIGCONT = 0x00000009; // Signal Cont. +const mode_t SIGSTOP = 0x00000011; // Signal Stop. +const mode_t SIGKILL = 0x00000013; // Signal Kill. inline auto strerror_r(int errnum, char* buffer, size_t length) -> decltype(strerror_s(buffer, length, errnum)) @@ -369,8 +377,10 @@ decltype(_mktemp_s(path, strlen(path) + 1)) } // NOTE: We open the file with read / write access for the given user, an - // attempt to match POSIX's specification of `mkstemp`. - return _open(path, S_IRUSR | S_IWUSR); + // attempt to match POSIX's specification of `mkstemp`. We use `_S_IREAD` and + // `_S_IWRITE` here instead of the POSIX equivalents. On Windows the file is + // is not present, we use `_O_CREAT` option when opening the file. + return _open(path, _O_CREAT, _S_IREAD | _S_IWRITE); }