summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2008-05-14 21:40:43 +0000
committerRussell Bryant <russell@russellbryant.com>2008-05-14 21:40:43 +0000
commit08f91c1192559e847f955c57e7b259a9f1560a43 (patch)
treea37ef618305865e834fceab21afbecc8214fa482 /include
parentc51989a309f2b50714f4c1bcad3987913fdb1f56 (diff)
Merged revisions 116463 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r116463 | russell | 2008-05-14 16:32:00 -0500 (Wed, 14 May 2008) | 4 lines Add ast_assert(), which can be used to handle fatal errors. It is only compiled in if dev-mode is enabled, and only aborts if DO_CRASH is defined. (inspired by issue #12650) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@116469 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/channel.h8
-rw-r--r--include/asterisk/utils.h27
2 files changed, 27 insertions, 8 deletions
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 9fdc6deb7..5177734a4 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -1597,18 +1597,10 @@ static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *c
return state;
}
-
-#ifdef DO_CRASH
-#define CRASH do { fprintf(stderr, "!! Forcing immediate crash a-la abort !!\n"); *((int *)0) = 0; } while(0)
-#else
-#define CRASH do { } while(0)
-#endif
-
#define CHECK_BLOCKING(c) do { \
if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
if (option_debug) \
ast_log(LOG_DEBUG, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \
- CRASH; \
} else { \
(c)->blocker = pthread_self(); \
(c)->blockproc = __PRETTY_FUNCTION__; \
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index be7d3fbfd..0de0727a7 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -654,6 +654,33 @@ int ast_mkdir(const char *path, int mode);
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
+#ifdef AST_DEVMODE
+#define ast_assert(a) _ast_assert(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+static void force_inline _ast_assert(int condition, const char *condition_str,
+ const char *file, int line, const char *function)
+{
+ if (__builtin_expect(!condition, 1)) {
+ /* Attempt to put it into the logger, but hope that at least someone saw the
+ * message on stderr ... */
+ ast_log(LOG_ERROR, "FRACK!, Failed assertion %s (%d) at line %d in %s of %s\n",
+ condition_str, condition, line, function, file);
+ fprintf(stderr, "FRACK!, Failed assertion %s (%d) at line %d in %s of %s\n",
+ condition_str, condition, line, function, file);
+ /* Give the logger a chance to get the message out, just in case we abort(), or
+ * Asterisk crashes due to whatever problem just happened after we exit ast_assert(). */
+ usleep(1);
+#ifdef DO_CRASH
+ abort();
+ /* Just in case abort() doesn't work or something else super silly,
+ * and for Qwell's amusement. */
+ *((int*)0)=0;
+#endif
+ }
+}
+#else
+#define ast_assert(a)
+#endif
+
#include "asterisk/strings.h"
#endif /* _ASTERISK_UTILS_H */