You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jp...@apache.org on 2017/09/07 05:35:12 UTC

[2/6] mesos git commit: Added SAFE_EXIT as alternative to ABORT.

Added SAFE_EXIT as alternative to ABORT.

EXIT macro can't be used when async-signal safety is required.

Currently, ABORT is used for terminating a program after both
unexpected and expected errors, when async-signal safety is required.
In case of expected errors, `abort` causes coredumps, which might be
undesirable.

In addition, SAFE_EXIT supports formatted output conversion, thereby
SAFE_EXIT interface doesn't force users to concatenate strings, thus
making its usage more async-signal safe.

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


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

Branch: refs/heads/master
Commit: 7ee7caa4d92d107b31bb3c269366729c012e8279
Parents: be25f26
Author: Andrei Budnik <ab...@mesosphere.com>
Authored: Wed Sep 6 22:01:57 2017 -0700
Committer: James Peach <jp...@apache.org>
Committed: Wed Sep 6 22:01:57 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/exit.hpp | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/7ee7caa4/3rdparty/stout/include/stout/exit.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/exit.hpp b/3rdparty/stout/include/stout/exit.hpp
index e5c2d34..34585a0 100644
--- a/3rdparty/stout/include/stout/exit.hpp
+++ b/3rdparty/stout/include/stout/exit.hpp
@@ -18,6 +18,7 @@
 #include <ostream>
 
 #include <glog/logging.h>
+#include <glog/raw_logging.h>
 
 #include <stout/attributes.hpp>
 
@@ -29,6 +30,25 @@
 // Ex: EXIT(EXIT_FAILURE) << "Cgroups are not present in this system.";
 #define EXIT(status) __Exit(__FILE__, __LINE__, status).stream()
 
+// Async-signal safe exit which prints a message.
+//
+// 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.
+//
+// NOTE: We expect that compiler supports `,##__VA_ARGS__`, see:
+// https://stackoverflow.com/questions/5588855
+#define SAFE_EXIT(status, fmt, ...)                                       \
+  do {                                                                    \
+    if (status) {                                                         \
+      RAW_LOG(ERROR, "EXIT with status %d: " fmt, status, ##__VA_ARGS__); \
+    } else {                                                              \
+      RAW_LOG(INFO, "EXIT with status %d: " fmt, status, ##__VA_ARGS__);  \
+    }                                                                     \
+    ::_exit(status);                                                      \
+  } while (0)
+
 
 struct __Exit
 {