diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-05-14 21:32:00 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-05-14 21:32:00 +0000 |
commit | 848841973a5c5b8d2de336ed32f5b4ab80ca8d79 (patch) | |
tree | d36d7d542d0d6ba89c806a8acd12d366bd58a368 /include | |
parent | ec6b2c6e0554dd4374dea87f80d99f9495a80b03 (diff) |
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: http://svn.digium.com/svn/asterisk/branches/1.4@116463 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/channel.h | 7 | ||||
-rw-r--r-- | include/asterisk/utils.h | 27 |
2 files changed, 27 insertions, 7 deletions
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 1172274f7..41371ccc0 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -1340,17 +1340,10 @@ static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, #endif } -#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 1e5203671..44994f4c0 100644 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -562,4 +562,31 @@ void ast_enable_packet_fragmentation(int sock); #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 + #endif /* _ASTERISK_UTILS_H */ |