[asterisk-commits] russell: branch 1.6.0 r116470 - in /branches/1.6.0: ./ channels/ include/aste...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 14 16:41:09 CDT 2008


Author: russell
Date: Wed May 14 16:41:09 2008
New Revision: 116470

URL: http://svn.digium.com/view/asterisk?view=rev&rev=116470
Log:
Merged revisions 116469 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r116469 | russell | 2008-05-14 16:40:43 -0500 (Wed, 14 May 2008) | 12 lines

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)

........

................

Modified:
    branches/1.6.0/   (props changed)
    branches/1.6.0/channels/chan_agent.c
    branches/1.6.0/include/asterisk/channel.h
    branches/1.6.0/include/asterisk/utils.h
    branches/1.6.0/main/abstract_jb.c
    branches/1.6.0/main/channel.c
    branches/1.6.0/main/rtp.c
    branches/1.6.0/main/sched.c
    branches/1.6.0/main/udptl.c

Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.0/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/channels/chan_agent.c?view=diff&rev=116470&r1=116469&r2=116470
==============================================================================
--- branches/1.6.0/channels/chan_agent.c (original)
+++ branches/1.6.0/channels/chan_agent.c Wed May 14 16:41:09 2008
@@ -1008,7 +1008,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;

Modified: branches/1.6.0/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/include/asterisk/channel.h?view=diff&rev=116470&r1=116469&r2=116470
==============================================================================
--- branches/1.6.0/include/asterisk/channel.h (original)
+++ branches/1.6.0/include/asterisk/channel.h Wed May 14 16:41:09 2008
@@ -1594,18 +1594,10 @@
 	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__; \

Modified: branches/1.6.0/include/asterisk/utils.h
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/include/asterisk/utils.h?view=diff&rev=116470&r1=116469&r2=116470
==============================================================================
--- branches/1.6.0/include/asterisk/utils.h (original)
+++ branches/1.6.0/include/asterisk/utils.h Wed May 14 16:41:09 2008
@@ -654,6 +654,33 @@
 
 #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 */

Modified: branches/1.6.0/main/abstract_jb.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/main/abstract_jb.c?view=diff&rev=116470&r1=116469&r2=116470
==============================================================================
--- branches/1.6.0/main/abstract_jb.c (original)
+++ branches/1.6.0/main/abstract_jb.c Wed May 14 16:41:09 2008
@@ -430,7 +430,7 @@
 			return;
 		default:
 			ast_log(LOG_ERROR, "This should never happen!\n");
-			CRASH;
+			ast_assert(0);
 			break;
 		}
 		
@@ -486,7 +486,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, '/');

Modified: branches/1.6.0/main/channel.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/main/channel.c?view=diff&rev=116470&r1=116469&r2=116470
==============================================================================
--- branches/1.6.0/main/channel.c (original)
+++ branches/1.6.0/main/channel.c Wed May 14 16:41:09 2008
@@ -975,7 +975,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 {
 			ast_debug(1, "Dropping voice to exceptionally long queue on %s\n", chan->name);
 			ast_frfree(f);
@@ -1611,7 +1611,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)) {
 		ast_debug(1, "Hanging up channel '%s'\n", chan->name);

Modified: branches/1.6.0/main/rtp.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/main/rtp.c?view=diff&rev=116470&r1=116469&r2=116470
==============================================================================
--- branches/1.6.0/main/rtp.c (original)
+++ branches/1.6.0/main/rtp.c Wed May 14 16:41:09 2008
@@ -1077,8 +1077,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;
@@ -1420,8 +1419,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;

Modified: branches/1.6.0/main/sched.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/main/sched.c?view=diff&rev=116470&r1=116469&r2=116470
==============================================================================
--- branches/1.6.0/main/sched.c (original)
+++ branches/1.6.0/main/sched.c Wed May 14 16:41:09 2008
@@ -289,9 +289,7 @@
 
 	if (!s) {
 		ast_debug(1, "Attempted to delete nonexistent schedule entry %d!\n", id);
-#ifdef DO_CRASH
-		CRASH;
-#endif
+		ast_assert(0);
 		return -1;
 	}
 	

Modified: branches/1.6.0/main/udptl.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/main/udptl.c?view=diff&rev=116470&r1=116469&r2=116470
==============================================================================
--- branches/1.6.0/main/udptl.c (original)
+++ branches/1.6.0/main/udptl.c Wed May 14 16:41:09 2008
@@ -659,8 +659,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;
 	}
 




More information about the asterisk-commits mailing list