You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/03/28 18:19:10 UTC

[4/7] mesos git commit: Subprocess: [4/7] Refactored perf test without setup function.

Subprocess: [4/7] Refactored perf test without setup function.

With the newly introduced watchdog option there is no need
for the child setup function in the perf code anymore.

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


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

Branch: refs/heads/master
Commit: dbddb6bd4dafebb46efe64cf3c2424390bbcff6b
Parents: a3d1bd4
Author: Joerg Schad <jo...@mesosphere.io>
Authored: Mon Mar 28 17:02:12 2016 +0200
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Mar 28 18:17:11 2016 +0200

----------------------------------------------------------------------
 src/linux/perf.cpp | 85 +++++--------------------------------------------
 1 file changed, 8 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/dbddb6bd/src/linux/perf.cpp
----------------------------------------------------------------------
diff --git a/src/linux/perf.cpp b/src/linux/perf.cpp
index 1c113a2..749e676 100644
--- a/src/linux/perf.cpp
+++ b/src/linux/perf.cpp
@@ -111,7 +111,7 @@ protected:
   {
     // Kill the perf process (if it's still running) by sending
     // SIGTERM to the signal handler which will then SIGKILL the
-    // perf process group created by setupChild.
+    // perf process group created by the watchdog process.
     if (perf.isSome() && perf->status().isPending()) {
       kill(perf->pid(), SIGTERM);
     }
@@ -120,92 +120,23 @@ protected:
   }
 
 private:
-  static void signalHandler(int signal)
-  {
-    // Send SIGKILL to every process in the process group of the
-    // calling process. This will terminate both the perf process
-    // (including its children) and the bookkeeping process.
-    kill(0, SIGKILL);
-    abort();
-  }
-
-  // This function is invoked right before each 'perf' is exec'ed.
-  // Note that this function needs to be async signal safe. In fact,
-  // all the library functions we used in this function are async
-  // signal safe.
-  static int setupChild()
-  {
-    // Send SIGTERM to the current process if the parent (i.e., the
-    // slave) exits. Note that this function should always succeed
-    // because we are passing in a valid signal.
-    prctl(PR_SET_PDEATHSIG, SIGTERM);
-
-    // Put the current process into a separate process group so that
-    // we can kill it and all its children easily.
-    if (setpgid(0, 0) != 0) {
-      abort();
-    }
-
-    // Install a SIGTERM handler which will kill the current process
-    // group. Since we already setup the death signal above, the
-    // signal handler will be triggered when the parent (i.e., the
-    // slave) exits.
-    if (os::signals::install(SIGTERM, &signalHandler) != 0) {
-      abort();
-    }
-
-    pid_t pid = fork();
-    if (pid == -1) {
-      abort();
-    } else if (pid == 0) {
-      // Child. This is the process that is going to exec the perf
-      // process if zero is returned.
-
-      // We setup death signal for the perf process as well in case
-      // someone, though unlikely, accidentally kill the parent of
-      // this process (the bookkeeping process).
-      prctl(PR_SET_PDEATHSIG, SIGKILL);
-
-      // NOTE: We don't need to clear the signal handler explicitly
-      // because the subsequent 'exec' will clear them.
-      return 0;
-    } else {
-      // Parent. This is the bookkeeping process which will wait for
-      // the perf process to finish.
-
-      // Close the files to prevent interference on the communication
-      // between the slave and the perf process.
-      close(STDIN_FILENO);
-      close(STDOUT_FILENO);
-      close(STDERR_FILENO);
-
-      // Block until the perf process finishes.
-      int status = 0;
-      if (waitpid(pid, &status, 0) == -1) {
-        abort();
-      }
-
-      // Forward the exit status if the perf process exits normally.
-      if (WIFEXITED(status)) {
-        _exit(WEXITSTATUS(status));
-      }
-
-      abort();
-      UNREACHABLE();
-    }
-  }
-
   void execute()
   {
+    // NOTE: The watchdog process places perf in its own process group
+    // and will kill the perf process when the parent dies.
     Try<Subprocess> _perf = subprocess(
         "perf",
         argv,
         Subprocess::PIPE(),
         Subprocess::PIPE(),
         Subprocess::PIPE(),
+        NO_SETSID,
+        None(),
+        None(),
         None(),
+        Subprocess::Hook::None(),
         None(),
-        setupChild);
+        MONITOR);
 
     if (_perf.isError()) {
       promise.fail("Failed to launch perf process: " + _perf.error());