Repository: mesos
Updated Branches:
  refs/heads/master 988bab82f -> 04990253e


Windows: Moved "kill on close" job object flag to own function.

Instead of setting this flag unconditionally when we create a job
object, this patch abstracts it to the function
`set_job_kill_on_close_limit(pid_t)` so that users can choose how to tie
job object lifetimes together.

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


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

Branch: refs/heads/master
Commit: 65df55a40245fea1a52744a2e3290b37f0cc5011
Parents: 988bab8
Author: Andrew Schwartzmeyer <and...@schwartzmeyer.com>
Authored: Wed Nov 8 11:47:22 2017 -0800
Committer: Andrew Schwartzmeyer <and...@schwartzmeyer.com>
Committed: Fri Feb 9 11:54:11 2018 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/os.hpp | 58 +++++++++++++-----------
 1 file changed, 32 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/65df55a4/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 ec93520..545a005 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -604,11 +604,6 @@ inline Try<SharedHandle> open_job(
 }
 
 // `create_job` function creates a named job object using `name`.
-// This returns the safe job handle, which closes the job handle
-// when destructed. Because the job is destroyed when its last
-// handle is closed and all associated processes have exited,
-// a running process must be assigned to the created job
-// before the returned handle is closed.
 inline Try<SharedHandle> create_job(const std::wstring& name)
 {
   SharedHandle job_handle(
@@ -624,27 +619,6 @@ inline Try<SharedHandle> create_job(const std::wstring& 
name)
         stringify(name));
   }
 
-  JOBOBJECT_EXTENDED_LIMIT_INFORMATION info = {};
-
-  // 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.
-  // We set this flag so that the death of the agent process will
-  // always kill any running jobs, as the OS will close the remaining open
-  // handles if all destructors failed to run (catastrophic death).
-  info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
-
-  const BOOL result = ::SetInformationJobObject(
-      job_handle.get_handle(),
-      JobObjectExtendedLimitInformation,
-      &info,
-      sizeof(info));
-
-  if (result == FALSE) {
-    return WindowsError(
-        "os::create_job: `SetInformationJobObject` failed for job: " +
-        stringify(name));
-  }
-
   return job_handle;
 }
 
@@ -783,6 +757,38 @@ inline Try<Bytes> get_job_mem(pid_t pid) {
 }
 
 
+// `set_job_kill_on_close_limit` causes the job object to terminate all
+// processes assigned to it when the last handle to the job object is closed.
+// This can be used to limit the lifetime of the process group represented by
+// the job object. Without this limit set, the processes will continue to run.
+inline Try<Nothing> set_job_kill_on_close_limit(pid_t pid)
+{
+  Try<SharedHandle> job_handle =
+    os::open_job(JOB_OBJECT_SET_ATTRIBUTES, false, pid);
+
+  if (job_handle.isError()) {
+    return Error(job_handle.error());
+  }
+
+  JOBOBJECT_EXTENDED_LIMIT_INFORMATION info = {};
+  info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+
+  const BOOL result = ::SetInformationJobObject(
+      job_handle->get_handle(),
+      JobObjectExtendedLimitInformation,
+      &info,
+      sizeof(info));
+
+  if (result == FALSE) {
+    return WindowsError(
+        "os::set_job_kill_on_close_limit: call to `SetInformationJobObject` "
+        "failed");
+  }
+
+  return Nothing();
+}
+
+
 // `set_job_cpu_limit` sets a CPU limit for the process represented by
 // `pid`, assuming it is assigned to a job object. This function will fail
 // otherwise. This limit is a hard cap enforced by the OS.

Reply via email to