You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2013/09/27 20:03:33 UTC

git commit: Preserved exit status when SIGTERM is received.

Updated Branches:
  refs/heads/master da9c30a0b -> 8cf5bfa82


Preserved exit status when SIGTERM is received.

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


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

Branch: refs/heads/master
Commit: 8cf5bfa82e780fa97c2a2bdba443169de5180489
Parents: da9c30a
Author: Vinod Kone <vi...@twitter.com>
Authored: Mon Sep 16 12:59:46 2013 -0700
Committer: Vinod Kone <vi...@twitter.com>
Committed: Fri Sep 27 11:02:58 2013 -0700

----------------------------------------------------------------------
 src/logging/logging.cpp | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8cf5bfa8/src/logging/logging.cpp
----------------------------------------------------------------------
diff --git a/src/logging/logging.cpp b/src/logging/logging.cpp
index 0282b1f..49a804c 100644
--- a/src/logging/logging.cpp
+++ b/src/logging/logging.cpp
@@ -20,6 +20,7 @@
 #include <string.h> // For strsignal().
 
 #include <glog/logging.h>
+#include <glog/raw_logging.h>
 
 #include <string>
 
@@ -47,16 +48,28 @@ namespace logging {
 string argv0;
 
 
+// NOTE: We use RAW_LOG instead of LOG because RAW_LOG doesn't
+// allocate any memory or grab locks. And according to
+// https://code.google.com/p/google-glog/issues/detail?id=161
+// it should work in 'most' cases in signal handlers.
 void handler(int signal)
 {
   if (signal == SIGTERM) {
-    EXIT(1) << "Received signal SIGTERM; exiting.";
+    RAW_LOG(WARNING, "Received signal SIGTERM; exiting.");
+
+    // Setup the default handler for SIGTERM so that we don't print
+    // a stack trace.
+    struct sigaction action;
+    memset(&action, 0, sizeof(action));
+    sigemptyset(&action.sa_mask);
+    action.sa_handler = SIG_DFL;
+    sigaction(signal, &action, NULL);
+    raise(signal);
   } else if (signal == SIGPIPE) {
-    LOG(WARNING) << "Received signal SIGPIPE; escalating to SIGABRT";
+    RAW_LOG(WARNING, "Received signal SIGPIPE; escalating to SIGABRT");
     raise(SIGABRT);
   } else {
-    LOG(FATAL) << "Unexpected signal in signal handler: '"
-               << strsignal(signal) << "'";
+    RAW_LOG(FATAL, "Unexpected signal in signal handler: " + signal);
   }
 }