Index: channels/chan_agent.c =================================================================== --- channels/chan_agent.c (revision 116407) +++ channels/chan_agent.c (working copy) @@ -1051,7 +1051,7 @@ if (p->chan) { if (ast_test_flag(p->chan, AST_FLAG_BLOCKING)) { ast_log( LOG_ERROR, "A blocker exists after agent channel ownership acquired\n" ); - CRASH; + ast_assert(0); } } return tmp; Index: include/asterisk/utils.h =================================================================== --- include/asterisk/utils.h (revision 116407) +++ include/asterisk/utils.h (working copy) @@ -562,4 +562,28 @@ #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, "Fatal Error, Failed assertion %s (%d) at line %d in %s of %s\n", + condition_str, condition, line, function, file); + fprintf(stderr, "Fatal Error, 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(); +#endif + } +} +#else +#define ast_assert(a) +#endif + #endif /* _ASTERISK_UTILS_H */ Index: include/asterisk/channel.h =================================================================== --- include/asterisk/channel.h (revision 116407) +++ include/asterisk/channel.h (working copy) @@ -1340,17 +1340,10 @@ #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__; \ Index: main/channel.c =================================================================== --- main/channel.c (revision 116407) +++ main/channel.c (working copy) @@ -912,7 +912,7 @@ if (((fin->frametype == AST_FRAME_VOICE) && (qlen > 96)) || (qlen > 128)) { if (fin->frametype != AST_FRAME_VOICE) { ast_log(LOG_WARNING, "Exceptionally long queue length queuing to %s\n", chan->name); - CRASH; + ast_assert(0); } else { if (option_debug) ast_log(LOG_DEBUG, "Dropping voice to exceptionally long queue on %s\n", chan->name); @@ -1476,7 +1476,7 @@ ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd " "is blocked by thread %ld in procedure %s! Expect a failure\n", (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc); - CRASH; + ast_assert(0); } if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) { if (option_debug) Index: main/rtp.c =================================================================== --- main/rtp.c (revision 116407) +++ main/rtp.c (working copy) @@ -855,8 +855,7 @@ rtcpheader = (unsigned int *)(rtcpdata + AST_FRIENDLY_OFFSET); if (res < 0) { - if (errno == EBADF) - CRASH; + ast_assert(errno != EBADF); if (errno != EAGAIN) { ast_log(LOG_WARNING, "RTCP Read error: %s. Hanging up.\n", strerror(errno)); return NULL; @@ -1134,8 +1133,7 @@ rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET); if (res < 0) { - if (errno == EBADF) - CRASH; + ast_assert(errno != EBADF); if (errno != EAGAIN) { ast_log(LOG_WARNING, "RTP Read error: %s. Hanging up.\n", strerror(errno)); return NULL; Index: main/abstract_jb.c =================================================================== --- main/abstract_jb.c (revision 116407) +++ main/abstract_jb.c (working copy) @@ -433,7 +433,7 @@ return; default: ast_log(LOG_ERROR, "This should never happen!\n"); - CRASH; + ast_assert(0); break; } @@ -489,7 +489,7 @@ bridged = ast_bridged_channel(chan); if (!bridged) { /* We should always have bridged chan if a jitterbuffer is in use */ - CRASH; + ast_assert(0); } snprintf(name1, sizeof(name1), "%s", bridged->name); tmp = strchr(name1, '/'); Index: main/udptl.c =================================================================== --- main/udptl.c (revision 116407) +++ main/udptl.c (working copy) @@ -639,8 +639,7 @@ if (res < 0) { if (errno != EAGAIN) ast_log(LOG_WARNING, "UDPTL read error: %s\n", strerror(errno)); - if (errno == EBADF) - CRASH; + ast_assert(errno != EBADF); return &ast_null_frame; } Index: main/sched.c =================================================================== --- main/sched.c (revision 116407) +++ main/sched.c (working copy) @@ -282,9 +282,7 @@ if (!s) { if (option_debug) ast_log(LOG_DEBUG, "Attempted to delete nonexistent schedule entry %d!\n", id); -#ifdef DO_CRASH - CRASH; -#endif + ast_assert(0); return -1; }