Set death signal for forked du processes for posix/disk isolator. Review: https://reviews.apache.org/r/32694
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/86d45bc1 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/86d45bc1 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/86d45bc1 Branch: refs/heads/master Commit: 86d45bc1411544b0dd38b18b3c38c84107ccb926 Parents: 2b5e5b4 Author: Jie Yu <[email protected]> Authored: Tue Mar 31 11:08:55 2015 -0700 Committer: Jie Yu <[email protected]> Committed: Thu Apr 2 12:03:11 2015 -0700 ---------------------------------------------------------------------- .../containerizer/isolators/posix/disk.cpp | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/86d45bc1/src/slave/containerizer/isolators/posix/disk.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/isolators/posix/disk.cpp b/src/slave/containerizer/isolators/posix/disk.cpp index 6e41e2a..d2ea3b1 100644 --- a/src/slave/containerizer/isolators/posix/disk.cpp +++ b/src/slave/containerizer/isolators/posix/disk.cpp @@ -18,6 +18,9 @@ #include <signal.h> +#ifdef __linux__ +#include <sys/prctl.h> +#endif #include <sys/types.h> #include <deque> @@ -353,6 +356,20 @@ private: Promise<Bytes> promise; }; + // This function is invoked right before each 'du' is exec'ed. Note + // that this function needs to be async signal safe. + static int setupChild() + { +#ifdef __linux__ + // Kill the child process if the parent exits. + // NOTE: This function should never returns non-zero because we + // are passing in a valid signal. + return ::prctl(PR_SET_PDEATHSIG, SIGKILL); +#else + return 0; +#endif + } + void discard(const string& path) { for (auto it = entries.begin(); it != entries.end(); ++it) { @@ -387,10 +404,14 @@ private: // fs data structures, (b) disk I/O to read those structures, and // (c) the cpu time to traverse. Try<Subprocess> s = subprocess( - "du -k -s " + entry->path, + "du", + vector<string>({"du", "-k", "-s", entry->path}), Subprocess::PATH("/dev/null"), Subprocess::PIPE(), - Subprocess::PIPE()); + Subprocess::PIPE(), + None(), + None(), + setupChild); if (s.isError()) { entry->promise.fail("Failed to exec 'du': " + s.error());
