Windows: Enabled `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE` on job objects.

Review: https://reviews.apache.org/r/47442/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/563c9ff5
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/563c9ff5
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/563c9ff5

Branch: refs/heads/master
Commit: 563c9ff5b539dc2d4ce1ba987dec925045cef5b8
Parents: ec2a8a8
Author: Daniel Pravat <[email protected]>
Authored: Mon May 30 18:02:24 2016 -0700
Committer: Joris Van Remoortere <[email protected]>
Committed: Mon May 30 18:02:31 2016 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/os.hpp | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/563c9ff5/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp 
b/3rdparty/stout/include/stout/windows/os.hpp
index 1363be1..275c17d 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -668,7 +668,7 @@ inline int random()
 // Every process started by the `pid` process which is part of the job
 // object becomes part of the job object. The job name should match
 // the name used in `kill_job`.
-inline Try<Nothing> create_job(pid_t pid)
+inline Try<HANDLE> create_job(pid_t pid)
 {
   Try<std::string> alpha_pid = strings::internal::format("MESOS_JOB_%X", pid);
   if (alpha_pid.isError()) {
@@ -692,16 +692,26 @@ inline Try<Nothing> create_job(pid_t pid)
     return WindowsError("os::create_job: Call to `CreateJobObject` failed");
   }
 
-  SharedHandle safe_job_handle(job_handle, ::CloseHandle);
+  JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { { 0 }, 0 };
+
+  jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+
+  // The job object will be terminated when the job handle closes. This allows
+  // the job tree to be terminated in case of errors by closing the handle.
+  ::SetInformationJobObject(
+      job_handle,
+      JobObjectExtendedLimitInformation,
+      &jeli,
+      sizeof(jeli));
 
   if (::AssignProcessToJobObject(
-          safe_job_handle.get_handle(),
+          job_handle,
           safe_process_handle.get_handle()) == 0) {
     return WindowsError(
         "os::create_job: Call to `AssignProcessToJobObject` failed");
   };
 
-  return Nothing();
+  return job_handle;
 }
 
 

Reply via email to