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/05/08 03:51:24 UTC
git commit: Added the ability to install a failure signal handler,
updated the master and slave mains to do so.
Updated Branches:
refs/heads/master 6947c12f3 -> f50bd38fc
Added the ability to install a failure signal handler, updated the
master and slave mains to do so.
Review: https://reviews.apache.org/r/10990
Project: http://git-wip-us.apache.org/repos/asf/incubator-mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mesos/commit/f50bd38f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mesos/tree/f50bd38f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mesos/diff/f50bd38f
Branch: refs/heads/master
Commit: f50bd38fc9f22dc836ff285a4aa8ff4246fd2345
Parents: 6947c12
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Tue May 7 17:39:18 2013 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Tue May 7 18:51:04 2013 -0700
----------------------------------------------------------------------
src/logging/logging.cpp | 34 +++++++++++++++++++++++++++++++++-
src/logging/logging.hpp | 5 ++++-
src/master/main.cpp | 2 +-
src/slave/main.cpp | 2 +-
4 files changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/f50bd38f/src/logging/logging.cpp
----------------------------------------------------------------------
diff --git a/src/logging/logging.cpp b/src/logging/logging.cpp
index 32b2ac7..535bbae 100644
--- a/src/logging/logging.cpp
+++ b/src/logging/logging.cpp
@@ -16,6 +16,9 @@
* limitations under the License.
*/
+#include <signal.h> // For sigaction(), sigemptyset().
+#include <string.h> // For strsignal().
+
#include <glog/logging.h>
#include <map>
@@ -146,7 +149,18 @@ private:
string argv0;
-void initialize(const string& _argv0, const Flags& flags)
+void handler(int signal)
+{
+ std::cerr << "Received signal '" << strsignal(signal)
+ << "', escalating to SIGABRT" << std::endl;
+ raise(SIGABRT);
+}
+
+
+void initialize(
+ const string& _argv0,
+ const Flags& flags,
+ bool installFailureSignalHandler)
{
static Once* initialized = new Once();
@@ -183,6 +197,24 @@ void initialize(const string& _argv0, const Flags& flags)
// exits (i.e., use a supervisor which re-spawns appropriately).
spawn(new LoggingProcess(), true);
+ if (installFailureSignalHandler) {
+ // Handles SIGSEGV, SIGILL, SIGFPE, SIGABRT, SIGBUS, SIGTERM
+ // by default.
+ google::InstallFailureSignalHandler();
+
+ // Set up the SIGPIPE signal handler to escalate to SIGABRT
+ // in order to have the glog handler catch it and print all
+ // of its lovely information.
+ struct sigaction action;
+ action.sa_handler = handler;
+ // Block all additional signals while in the handler.
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ if (sigaction(SIGPIPE, &action, NULL) < 0) {
+ PLOG(FATAL) << "Failed to set sigaction";
+ }
+ }
+
initialized->done();
}
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/f50bd38f/src/logging/logging.hpp
----------------------------------------------------------------------
diff --git a/src/logging/logging.hpp b/src/logging/logging.hpp
index 6cf93e9..0e90ef1 100644
--- a/src/logging/logging.hpp
+++ b/src/logging/logging.hpp
@@ -33,7 +33,10 @@ namespace mesos {
namespace internal {
namespace logging {
-void initialize(const std::string& argv0, const Flags& flags);
+void initialize(
+ const std::string& argv0,
+ const Flags& flags,
+ bool installFailureSignalHandler = false);
// Returns the log file for the provided severity level.
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/f50bd38f/src/master/main.cpp
----------------------------------------------------------------------
diff --git a/src/master/main.cpp b/src/master/main.cpp
index d6e1c73..19b6524 100644
--- a/src/master/main.cpp
+++ b/src/master/main.cpp
@@ -111,7 +111,7 @@ int main(int argc, char** argv)
process::initialize("master");
- logging::initialize(argv[0], flags);
+ logging::initialize(argv[0], flags, true); // Catch signals.
LOG(INFO) << "Build: " << build::DATE << " by " << build::USER;
LOG(INFO) << "Starting Mesos master";
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/f50bd38f/src/slave/main.cpp
----------------------------------------------------------------------
diff --git a/src/slave/main.cpp b/src/slave/main.cpp
index 80b2a3c..da286a2 100644
--- a/src/slave/main.cpp
+++ b/src/slave/main.cpp
@@ -119,7 +119,7 @@ int main(int argc, char** argv)
process::initialize();
- logging::initialize(argv[0], flags);
+ logging::initialize(argv[0], flags, true); // Catch signals.
LOG(INFO) << "Creating \"" << isolation << "\" isolator";