You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2013/06/20 05:30:22 UTC

[6/6] git commit: Removed killtree.sh in favor of os::killtree from libstout.

Removed killtree.sh in favor of os::killtree from libstout.

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


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

Branch: refs/heads/master
Commit: 56c20b619ad7aa915eaf4fff914f5e426b676761
Parents: 5738e5a
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Wed Jun 12 14:41:03 2013 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Wed Jun 19 20:29:48 2013 -0700

----------------------------------------------------------------------
 bin/mesos-build-env.sh.in          |   2 -
 src/Makefile.am                    |  10 +-
 src/common/process_utils.hpp       |  72 ----------
 src/launcher/executor.cpp          |   5 +-
 src/scripts/killtree.sh            | 245 --------------------------------
 src/slave/process_isolator.cpp     |   3 +-
 src/tests/environment.cpp          |   9 --
 src/tests/environment.hpp          |   1 -
 src/tests/killtree_test.sh         |  10 --
 src/tests/killtree_tests.cpp       |  24 ----
 src/tests/mesos.cpp                |   9 --
 src/tests/mesos.hpp                |   1 -
 src/tests/slave_recovery_tests.cpp |   3 +-
 13 files changed, 6 insertions(+), 388 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/bin/mesos-build-env.sh.in
----------------------------------------------------------------------
diff --git a/bin/mesos-build-env.sh.in b/bin/mesos-build-env.sh.in
index 31bccad..f2bbe42 100644
--- a/bin/mesos-build-env.sh.in
+++ b/bin/mesos-build-env.sh.in
@@ -21,8 +21,6 @@
 
 MESOS_WEBUI_DIR=@abs_top_srcdir@/src/webui
 MESOS_LAUNCHER_DIR=@abs_top_builddir@/src
-MESOS_KILLTREE=@abs_top_srcdir@/src/scripts/killtree.sh
 
 export MESOS_WEBUI_DIR
 export MESOS_LAUNCHER_DIR
-export MESOS_KILLTREE
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 6491f56..9337435 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -214,7 +214,7 @@ endif
 libmesos_no_3rdparty_la_SOURCES += common/attributes.hpp		\
 	common/build.hpp common/date_utils.hpp common/factory.hpp	\
 	common/protobuf_utils.hpp					\
-	common/lock.hpp common/resources.hpp common/process_utils.hpp	\
+	common/lock.hpp common/resources.hpp				\
 	common/type_utils.hpp common/thread.hpp common/units.hpp	\
 	common/values.hpp						\
 	detector/detector.hpp examples/utils.hpp files/files.hpp	\
@@ -458,10 +458,6 @@ nobase_dist_webui_DATA +=							  \
   webui/master/static/bootstrap/js/README.md
 
 
-# And need to install the killtree script.
-dist_pkglibexec_SCRIPTS += scripts/killtree.sh
-
-
 # And the deploy related stuff.
 nodist_sbin_SCRIPTS += deploy/mesos-daemon.sh			\
   deploy/mesos-start-cluster.sh deploy/mesos-start-masters.sh	\
@@ -804,7 +800,6 @@ mesos_tests_SOURCES = tests/main.cpp tests/utils.cpp			\
 	              tests/examples_tests.cpp				\
 	              tests/protobuf_io_tests.cpp			\
 	              tests/zookeeper_url_tests.cpp			\
-	              tests/killtree_tests.cpp				\
 	              tests/exception_tests.cpp				\
 	              tests/attributes_tests.cpp			\
 	              tests/master_detector_tests.cpp			\
@@ -869,8 +864,7 @@ dist_check_SCRIPTS +=				\
   tests/no_executor_framework_test.sh		\
   tests/java_exception_test.sh			\
   tests/java_framework_test.sh			\
-  tests/python_framework_test.sh		\
-  tests/killtree_test.sh
+  tests/python_framework_test.sh
 
 # We use a check-local target for now to avoid the parallel test
 # runner that ships with newer versions of autotools.

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/common/process_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/process_utils.hpp b/src/common/process_utils.hpp
deleted file mode 100644
index a04f4a2..0000000
--- a/src/common/process_utils.hpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __PROCESS_UTILS_HPP__
-#define __PROCESS_UTILS_HPP__
-
-#include <iostream>
-#include <sstream>
-
-#include <stout/os.hpp>
-#include <stout/strings.hpp>
-
-namespace mesos {
-namespace internal {
-namespace utils {
-namespace process {
-
-inline Try<int> killtree(
-    pid_t pid,
-    int signal,
-    bool killgroups,
-    bool killsess,
-    bool verbose)
-{
-  std::string cmdline;
-
-  // TODO(Charles Reiss): Use a configuration option.
-  if (os::hasenv("MESOS_KILLTREE")) {
-    // Set by mesos-build-env.sh.
-    cmdline = os::getenv("MESOS_KILLTREE");
-  } else if (os::hasenv("MESOS_SOURCE_DIR")) {
-    // Set by test harness for external tests.
-    cmdline = os::getenv("MESOS_SOURCE_DIR") +
-      "/src/scripts/killtree.sh";
-  } else {
-    cmdline = MESOS_LIBEXECDIR "/killtree.sh";
-  }
-
-  // Add the arguments.
-  Try<std::string> args = strings::format(" -p %d -s %d", pid, signal);
-  CHECK(!args.isError()) << args.error();
-  cmdline += args.get();
-
-  // Also add flags to kill all encountered groups and sessions.
-  if (killgroups) cmdline += " -g";
-  if (killsess) cmdline += " -x";
-  if (verbose) cmdline += " -v";
-
-  return os::shell(verbose ? &LOG(INFO) : NULL, cmdline);
-}
-
-} // namespace mesos {
-} // namespace internal {
-} // namespace utils {
-} // namespace process {
-
-#endif // __PROCESS_UTILS_HPP__

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/launcher/executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index 1a6725a..ef42b60 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -30,7 +30,6 @@
 #include <stout/os.hpp>
 #include <stout/strings.hpp>
 
-#include "common/process_utils.hpp"
 #include "common/thread.hpp"
 
 #include "logging/logging.hpp"
@@ -223,7 +222,7 @@ public:
   {
     // TODO(benh): Do kill escalation (i.e., after n seconds, kill -9).
     if (pid > 0) {
-      utils::process::killtree(pid, SIGTERM, true, true, true);
+      os::killtree(pid, SIGTERM, true, true, &std::cerr);
     }
   }
 
@@ -233,7 +232,7 @@ public:
   {
     // TODO(benh): Do kill escalation (i.e., after n seconds, kill -9).
     if (pid > 0) {
-      utils::process::killtree(pid, SIGTERM, true, true, true);
+      os::killtree(pid, SIGTERM, true, true, &std::cerr);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/scripts/killtree.sh
----------------------------------------------------------------------
diff --git a/src/scripts/killtree.sh b/src/scripts/killtree.sh
deleted file mode 100755
index c426654..0000000
--- a/src/scripts/killtree.sh
+++ /dev/null
@@ -1,245 +0,0 @@
-#!/bin/bash
-
-# We unset the DYLD_LIBRARY_PATH environment variable because the
-# dynamic linker on OSX 10.8 complains if this path is set when
-# running setuid or setgid programs, e.g., /bin/ps used in this
-# script.
-unset DYLD_LIBRARY_PATH
-
-PID=
-SIGNAL="TERM"
-KILLGROUPS=0
-KILLSESS=0
-VERBOSE=0
-
-
-usage() {
-    cat <<EOF
-usage: $0 -p pid -s signal
-
-Sends a signal to a process tree rooted at the specified pid.
-
-Options:
--h      Display this message.
--p      Root pid of tree.
--s      Signal to send (number or symbolic name), default is TERM
--g      Recursively invoke on all processes that are members
-        of any encountered process group.
--x      Same as -g, but invoke on processes of encountered sessions.
--v      Be more verbose.
-EOF
-}
-
-set_union() {
-    A="$1"
-    B="$2"
-
-    result=$(printf "${A}\n${B}\n" | sort | uniq)
-    echo "${result}"
-}
-
-set_intersect() {
-    A="$1"
-    B="$2"
-
-    result=$(printf "${A}\n${B}" \
-        | sort | uniq -c | awk '{ if ($1 == 2) print $2 }')
-
-    echo "${result}"
-}
-
-set_diff() {
-    A="$1"
-    B="$2"
-
-    result=$(printf "${A}\n${B}" \
-        | sort | uniq -c | awk '{ if ($1 == 1) print $2 }')
-
-    echo "${result}"
-}
-
-while getopts "hp:s:gxv" OPTION
-do
-    HAVEOPT=1
-    case ${OPTION} in
-        h)
-            usage
-            exit 0
-            ;;
-        p)
-            PID="${OPTARG}"
-            test ${PID} -eq ${PID} >& /dev/null
-            if [[ ${?} != 0 ]]; then
-              echo "$(basename ${0}): pid should be a number"
-              exit 1
-            fi
-            if [[ ! ${PID} -eq ${PID} ]]; then
-                exit 1
-            fi
-            ;;
-        s)
-            SIGNAL="${OPTARG}"
-            if [[ -z ${SIGNAL} ]]; then
-              SIGNAL="TERM"
-            fi
-            ;;
-        g)
-            KILLGROUPS=1
-            ;;
-	x)
-	    KILLSESSIONS=1
-	    ;;
-        v)
-            VERBOSE=1
-            ;;
-        *)  usage
-            exit 1
-            ;;
-    esac
-done
-
-if [[ ! ${HAVEOPT} ]]; then
-    usage
-    exit 127
-fi
-
-if [[ -z ${PID} ]]; then
-    echo "$(basename ${0}): must specify pid"
-    exit 1
-fi
-
-# Confirm we get some output from ps.
-ps axo ppid,pid >/dev/null 2>&1
-if [[ ${?} -ne 0 ]]; then
-    echo "$(basename ${0}): failed to capture process tree using 'ps'"
-    exit 1
-fi
-
-# Confirm we have awk.
-ls | awk {'print $1'} >/dev/null 2>&1
-if [[ ${?} -ne 0 ]]; then
-    echo "$(basename ${0}): failed to detect awk on the system"
-    exit 1
-fi
-
-printpids() {
-  name="${1}"
-  tpids="${2}"
-  if [[ ! -z ${tpids} ]]; then
-      result=$(echo ${tpids} | xargs ps o pid,ppid,pgid,sess,command -p)
-      printf "\n${name}\n${result}\n"
-  fi
-}
-
-PIDS=${PID} # Already processed pids, global variable hack.
-
-killtree() {
-    MYPID=${1}
-
-    # Output pid if requested.
-    if [[ ${VERBOSE} -eq 1 ]]; then
-        echo "Stopping ... ${MYPID}"
-    fi
-
-    # Stop the process to keep it from forking while we are killing it
-    # since a forked child might get re-parented by init and become
-    # impossible to find.
-    kill -STOP ${MYPID} >/dev/null 2>&1
-
-    # There is a concern that even though some process is stopped,
-    # sending a signal to any of it's children may cause a SIGCLD to
-    # be delivered to it which wakes it up (or any other signal maybe
-    # delivered). However, from the Open Group standards on "Signal
-    # Concepts":
-    #
-    #   "While a process is stopped, any additional signals that are
-    #    sent to the process shall not be delivered until the process
-    #    is continued, except SIGKILL which always terminates the
-    #    receiving process."
-    #
-    # In practice, this is not what has been witnessed. Rather, a
-    # process that has been stopped will respond to SIGTERM, SIGINT,
-    # etc. That being said, we still continue the process below in the
-    # event that it doesn't terminate from the sending signal but it
-    # also doesn't get continued (as per the specifications above).
-
-    # Now collect all the children.
-    CHILDPIDS=$(ps axo ppid,pid | awk '{ if ($1 == '${MYPID}') print $2 }')
-
-    if [[ ${VERBOSE} -eq 1 ]]; then
-        printpids "Children:" "${CHILDPIDS}"
-    fi
-
-    # Optionally collect all processes that are part of the process group.
-    GROUPPIDS=""
-    if [[ ${KILLGROUPS} -eq 1 ]]; then
-
-	# First get the process group.
-        MYPGID=$(ps axo pid,pgid | awk '{ if ($1 == '${MYPID}') print $2 }')
-
-	if [[ ! -z ${MYPGID} ]]; then
-            # Now get all members.
-            GROUPPIDS=$(ps axo pgid,pid \
-                | awk '{ if ($1 == '${MYPGID}') print $2 }')
-
-	    if [[ ${VERBOSE} -eq 1 ]]; then
-	        printpids "Group members:" "${GROUPPIDS}"
-	    fi
-	fi
-    fi
-
-    # Optionally collect all processes that are part of the same session.
-    SESSPIDS=""
-    if [[ ${KILLSESSIONS} -eq 1 ]]; then
-
-	# First get the process session id.
-        MYPSID=$(ps axo pid,sess | awk '{ if ($1 == '${MYPID}') print $2 }')
-
-	# We check for session id not being "0", because on OSX 10.8
-	# the session id of all processes as reported by 'ps' is "0"!
-	if [[ ${MYPSID} -ne "0" && ! -z ${MYPSID} ]]; then
-            # Now get all members.
-            SESSPIDS=$(ps axo sess,pid \
-                | awk '{ if ($1 == "'${MYPSID}'") print $2 }')
-
-	    if [[ ${VERBOSE} -eq 1 ]]; then
-                printpids "Session members:" "${SESSPIDS}"
-	    fi
-	fi
-    fi
-
-    # Get out only the unseen pids.
-    # NEW = CHILDPIDS U GROUPPIDS U SESSPIDS
-    #NEW=$(printf "${CHILDPIDS}\n${GROUPPIDS}\n${SESSPIDS}" | sort | uniq)
-    NEW=$(set_union "$(set_union "${CHILDPIDS}" "${GROUPPIDS}")" "${SESSPIDS}")
-
-    # OLD = NEW ^ PIDS
-    #OLD=$(printf "${PIDS}\n${NEW}" \
-    #    | sort | uniq -c | awk '{ if ($1 == 2) print $2 }')
-    OLD=$(set_intersect "${PIDS}" "${NEW}")
-
-    # NEW = NEW - OLD
-    #NEW=$(printf "${NEW}\n${OLD}" \
-    #    | sort | uniq -c | awk '{ if ($1 == 1) print $2 }')
-    NEW=$(set_diff "${NEW}" "${OLD}")
-
-    # Add all the new pids.
-    PIDS=$(printf "${NEW}\n${PIDS}" | sort)
-
-    # Now send the signal.
-    kill -${SIGNAL} ${MYPID} >/dev/null 2>&1
-
-    # Try and continue the process in case ${SIGNAL} is
-    # non-terminating but doesn't continue the process.
-    kill -CONT ${MYPID} >/dev/null 2>&1
-
-    if [[ ${VERBOSE} -eq 1 ]]; then
-        echo "Sent signal to ${MYPID}"
-    fi
-
-    for pid in ${NEW}; do
-        killtree $pid
-    done
-}
-
-killtree ${PID}

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/slave/process_isolator.cpp
----------------------------------------------------------------------
diff --git a/src/slave/process_isolator.cpp b/src/slave/process_isolator.cpp
index 83bd8da..97a017e 100644
--- a/src/slave/process_isolator.cpp
+++ b/src/slave/process_isolator.cpp
@@ -37,7 +37,6 @@
 #include <stout/uuid.hpp>
 
 #include "common/type_utils.hpp"
-#include "common/process_utils.hpp"
 
 #include "slave/flags.hpp"
 #include "slave/process_isolator.hpp"
@@ -265,7 +264,7 @@ void ProcessIsolator::killExecutor(
     // TODO(vinod): Call killtree on the pid of the actual executor process
     // that is running the tasks (stored in the local storage by the
     // executor module).
-    utils::process::killtree(pid.get(), SIGKILL, true, true, true);
+    os::killtree(pid.get(), SIGKILL, true, true, &LOG(INFO));
 
     // Also kill all processes that belong to the process group of the executor.
     // This is valuable in situations where the top level executor process

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/tests/environment.cpp
----------------------------------------------------------------------
diff --git a/src/tests/environment.cpp b/src/tests/environment.cpp
index 54649a5..2bdec1f 100644
--- a/src/tests/environment.cpp
+++ b/src/tests/environment.cpp
@@ -217,15 +217,6 @@ void Environment::SetUp()
   if (!GTEST_IS_THREADSAFE) {
     EXIT(1) << "Testing environment is not thread safe, bailing!";
   }
-
-  // For locating killtree.sh.
-  os::setenv("MESOS_SOURCE_DIR", tests::flags.source_dir);
-}
-
-
-void Environment::TearDown()
-{
-  os::unsetenv("MESOS_SOURCE_DIR");
 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/tests/environment.hpp
----------------------------------------------------------------------
diff --git a/src/tests/environment.hpp b/src/tests/environment.hpp
index 691291f..9acbe2f 100644
--- a/src/tests/environment.hpp
+++ b/src/tests/environment.hpp
@@ -37,7 +37,6 @@ public:
   virtual ~Environment();
 
   virtual void SetUp();
-  virtual void TearDown();
 
   // Helper to create a temporary directory based on the current test
   // case name and test name (derived from TestInfo via

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/tests/killtree_test.sh
----------------------------------------------------------------------
diff --git a/src/tests/killtree_test.sh b/src/tests/killtree_test.sh
deleted file mode 100755
index 3962954..0000000
--- a/src/tests/killtree_test.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/bash
-
-# Fork the proces that spawns processes in a chain
-$MESOS_HOME/tests/process-spawn &
-
-#Now get the pid of the above process
-
-pid=`ps -e | grep process-spawn | awk '{print $1}'`
-
-echo pid

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/tests/killtree_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/killtree_tests.cpp b/src/tests/killtree_tests.cpp
deleted file mode 100644
index 753c5c0..0000000
--- a/src/tests/killtree_tests.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <gtest/gtest.h>
-
-#include "tests/script.hpp"
-
-
-TEST_SCRIPT(KillTreeTest, KillTree, "killtree_test.sh")

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index 6dbf7f3..776cb0f 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -149,17 +149,8 @@ void MesosTest::ShutdownSlaves()
 }
 
 
-void MesosTest::SetUp()
-{
-  // For locating killtree.sh.
-  os::setenv("MESOS_SOURCE_DIR", tests::flags.source_dir);
-}
-
-
 void MesosTest::TearDown()
 {
-  os::unsetenv("MESOS_SOURCE_DIR");
-
   // TODO(benh): Fail the test if shutdown hasn't been called?
   Shutdown();
 }

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index fca41aa..891cc78 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -67,7 +67,6 @@ class MesosTest : public ::testing::Test
 protected:
   MesosTest(const Option<zookeeper::URL>& url = None());
 
-  virtual void SetUp();
   virtual void TearDown();
 
   // Returns the flags used to create masters.

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/56c20b61/src/tests/slave_recovery_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_recovery_tests.cpp b/src/tests/slave_recovery_tests.cpp
index 0315c52..0195e68 100644
--- a/src/tests/slave_recovery_tests.cpp
+++ b/src/tests/slave_recovery_tests.cpp
@@ -31,10 +31,10 @@
 #include <stout/none.hpp>
 #include <stout/numify.hpp>
 #include <stout/option.hpp>
+#include <stout/os.hpp>
 #include <stout/path.hpp>
 #include <stout/uuid.hpp>
 
-#include "common/process_utils.hpp"
 #include "common/protobuf_utils.hpp"
 #include "common/resources.hpp"
 
@@ -64,7 +64,6 @@ using namespace mesos;
 using namespace mesos::internal;
 using namespace mesos::internal::slave;
 using namespace mesos::internal::tests;
-using namespace mesos::internal::utils::process;
 
 using namespace process;