Repository: mesos Updated Branches: refs/heads/master 476c2f2d4 -> 7f04cf886
Windows: Stout: Adapted `os::killtree` to terminate job objects. On Windows, a "process tree" is in fact a job object. Thus, the implementation of `os::killtree` on Windows is an adapter which terminates the job object corresponding to the process group represented by the given PID. Review: https://reviews.apache.org/r/56367/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/176c09d8 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/176c09d8 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/176c09d8 Branch: refs/heads/master Commit: 176c09d8debb64e98fed14ef499f9205132b9180 Parents: db0f569 Author: Andrew Schwartzmeyer <[email protected]> Authored: Mon Apr 3 11:57:32 2017 -0700 Committer: Joseph Wu <[email protected]> Committed: Tue Apr 4 16:45:15 2017 -0700 ---------------------------------------------------------------------- .../stout/include/stout/os/windows/killtree.hpp | 38 ++++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/176c09d8/3rdparty/stout/include/stout/os/windows/killtree.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/killtree.hpp b/3rdparty/stout/include/stout/os/windows/killtree.hpp index 15b2faa..267a9a0 100644 --- a/3rdparty/stout/include/stout/os/windows/killtree.hpp +++ b/3rdparty/stout/include/stout/os/windows/killtree.hpp @@ -17,34 +17,42 @@ #include <stout/os.hpp> -#include <stout/os/pstree.hpp> +#include <stout/os.hpp> // For `kill_job`. +#include <stout/try.hpp> // For `Try<>`. +#include <stout/windows.hpp> // For `SharedHandle`. namespace os { -// Terminate the process tree rooted at the specified pid. -// Note that if the process 'pid' has exited we'll terminate the process -// tree(s) rooted at pids. -// Returns the process trees that were successfully or unsuccessfully -// signaled. Note that the process trees can be stringified. +// Terminate the "process tree" rooted at the specified pid. +// Since there is no process tree concept on Windows, +// internally this function looks up the job object for the given pid +// and terminates the job. This is possible because `name_job` +// provides an idempotent one-to-one mapping from pid to name. inline Try<std::list<ProcessTree>> killtree( pid_t pid, int signal, bool groups = false, bool sessions = false) { - std::list<ProcessTree> process_tree_list; - Try<ProcessTree> process_tree = os::pstree(pid); - if (process_tree.isError()) { - return WindowsError(); + Try<std::string> name = os::name_job(pid); + if (name.isError()) { + return Error("Failed to determine job object name: " + name.error()); } - process_tree_list.push_back(process_tree.get()); + Try<SharedHandle> handle = + os::open_job(JOB_OBJECT_TERMINATE, false, name.get()); + if (handle.isError()) { + return Error("Failed to open job object: " + handle.error()); + } - Try<Nothing> kill_job = os::kill_job(pid); - if (kill_job.isError()) - { - return Error(kill_job.error()); + Try<Nothing> killJobResult = os::kill_job(handle.get()); + if (killJobResult.isError()) { + return Error("Failed to delete job object: " + killJobResult.error()); } + + // NOTE: This return value is unused. A future refactor + // may change the return type to `Try<None>`. + std::list<ProcessTree> process_tree_list; return process_tree_list; }
