[asterisk-commits] mjordan: branch mjordan/trunk-deadlock r376377 - in /team/mjordan/trunk-deadl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Nov 15 20:34:02 CST 2012


Author: mjordan
Date: Thu Nov 15 20:33:58 2012
New Revision: 376377

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376377
Log:
Re-create trunk-deadlock branch

Now with a cleaned up version

Added:
    team/mjordan/trunk-deadlock/   (props changed)
      - copied from r376374, trunk/
Modified:
    team/mjordan/trunk-deadlock/main/asterisk.c
    team/mjordan/trunk-deadlock/main/utils.c

Propchange: team/mjordan/trunk-deadlock/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/mjordan/trunk-deadlock/
------------------------------------------------------------------------------
    automerge-email = mjordan at digium.com

Propchange: team/mjordan/trunk-deadlock/
------------------------------------------------------------------------------
--- branch-10-digiumphones-merged (added)
+++ branch-10-digiumphones-merged Thu Nov 15 20:33:58 2012
@@ -1,0 +1,1 @@
+/branches/10-digiumphones:364766,365396,368791,368963-368965,368999,369026

Propchange: team/mjordan/trunk-deadlock/
------------------------------------------------------------------------------
    branch-11-blocked = /branches/11:373240,375247,375702

Propchange: team/mjordan/trunk-deadlock/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Propchange: team/mjordan/trunk-deadlock/
------------------------------------------------------------------------------
    certified-branch-1.8.11-merged = /certified/branches/1.8.11:364761,365395

Propchange: team/mjordan/trunk-deadlock/
------------------------------------------------------------------------------
--- reviewboard:url (added)
+++ reviewboard:url Thu Nov 15 20:33:58 2012
@@ -1,0 +1,1 @@
+https://reviewboard.asterisk.org

Propchange: team/mjordan/trunk-deadlock/
------------------------------------------------------------------------------
--- svn:externals (added)
+++ svn:externals Thu Nov 15 20:33:58 2012
@@ -1,0 +1,1 @@
+menuselect https://origsvn.digium.com/svn/menuselect/trunk

Propchange: team/mjordan/trunk-deadlock/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Nov 15 20:33:58 2012
@@ -1,0 +1,20 @@
+.applied
+.cleancount
+.depend
+.lastclean
+.tags-depend
+.tags-sources
+.version
+TAGS
+aclocal.m4
+autom4te.cache
+config.cache
+config.log
+config.status
+defaults.h
+makeopts
+makeopts.embed_rules
+menuselect-tree
+menuselect.makedeps
+menuselect.makeopts
+tags

Propchange: team/mjordan/trunk-deadlock/
------------------------------------------------------------------------------
    svn:mergeinfo = /branches/11:372696

Modified: team/mjordan/trunk-deadlock/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-deadlock/main/asterisk.c?view=diff&rev=376377&r1=376374&r2=376377
==============================================================================
--- team/mjordan/trunk-deadlock/main/asterisk.c (original)
+++ team/mjordan/trunk-deadlock/main/asterisk.c Thu Nov 15 20:33:58 2012
@@ -1605,7 +1605,7 @@
 	int res;
 	ast_consock = socket(PF_LOCAL, SOCK_STREAM, 0);
 	if (ast_consock < 0) {
-		ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
+		fprintf(stderr, "Unable to create socket: %s\n", strerror(errno));
 		return 0;
 	}
 	memset(&sunaddr, 0, sizeof(sunaddr));
@@ -2439,7 +2439,7 @@
 				break;
 			if (errno == EINTR)
 				continue;
-			ast_log(LOG_ERROR, "poll failed: %s\n", strerror(errno));
+			fprintf(stderr, "poll failed: %s\n", strerror(errno));
 			break;
 		}
 
@@ -3185,7 +3185,7 @@
 	if (ast_opt_override_config) {
 		cfg = ast_config_load2(ast_config_AST_CONFIG_FILE, "" /* core, can't reload */, config_flags);
 		if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
-			ast_log(LOG_WARNING, "Unable to open specified master config file '%s', using built-in defaults\n", ast_config_AST_CONFIG_FILE);
+			fprintf(stderr, "Unable to open specified master config file '%s', using built-in defaults\n", ast_config_AST_CONFIG_FILE);
 	} else
 		cfg = ast_config_load2(config, "" /* core, can't reload */, config_flags);
 
@@ -3412,7 +3412,7 @@
 	for (v = ast_variable_browse(cfg, "compat"); v; v = v->next) {
 		float version;
 		if (sscanf(v->value, "%30f", &version) != 1) {
-			ast_log(LOG_WARNING, "Compatibility version for option '%s' is not a number: '%s'\n", v->name, v->value);
+			fprintf(stderr, "Compatibility version for option '%s' is not a number: '%s'\n", v->name, v->value);
 			continue;
 		}
 		if (!strcasecmp(v->name, "app_set")) {
@@ -3568,15 +3568,6 @@
 	if (gethostname(hostname, sizeof(hostname)-1))
 		ast_copy_string(hostname, "<Unknown>", sizeof(hostname));
 	ast_mainpid = getpid();
-	ast_ulaw_init();
-	ast_alaw_init();
-	callerid_init();
-	ast_builtins_init();
-	ast_utils_init();
-	tdd_init();
-	ast_tps_init();
-	ast_fd_init();
-	ast_pbx_init();
 
 	if (getenv("HOME"))
 		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
@@ -3700,16 +3691,6 @@
 		}
 	}
 
-	if (ast_opt_console || option_verbose || (ast_opt_remote && !ast_opt_exec)) {
-		if (ast_register_verbose(console_verboser)) {
-			ast_log(LOG_WARNING, "Unable to register console verboser?\n");
-		}
-		WELCOME_MESSAGE;
-	}
-
-	if (ast_opt_console && !option_verbose)
-		ast_verbose("[ Booting...\n");
-
 	/* For remote connections, change the name of the remote connection.
 	 * We do this for the benefit of init scripts (which need to know if/when
 	 * the main asterisk process has died yet). */
@@ -3720,21 +3701,18 @@
 		}
 	}
 
-	if (ast_opt_console && !option_verbose) {
-		ast_verbose("[ Reading Master Configuration ]\n");
-	}
-
 	ast_readconfig();
 	env_init();
 
 	if (ast_opt_remote && remotesock != NULL)
 		ast_copy_string((char *) cfg_paths.socket_path, remotesock, sizeof(cfg_paths.socket_path));
 
-	if (!ast_language_is_prefix && !ast_opt_remote)
-		ast_log(LOG_WARNING, "The 'languageprefix' option in asterisk.conf is deprecated; in a future release it will be removed, and your sound files will need to be organized in the 'new style' language layout.\n");
+	if (!ast_language_is_prefix && !ast_opt_remote) {
+		fprintf(stderr, "The 'languageprefix' option in asterisk.conf is deprecated; in a future release it will be removed, and your sound files will need to be organized in the 'new style' language layout.\n");
+	}
 
 	if (ast_opt_always_fork && (ast_opt_remote || ast_opt_console)) {
-		ast_log(LOG_WARNING, "'alwaysfork' is not compatible with console or remote console mode; ignored\n");
+		fprintf(stderr, "'alwaysfork' is not compatible with console or remote console mode; ignored\n");
 		ast_clear_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK);
 	}
 
@@ -3743,12 +3721,12 @@
 		l.rlim_cur = RLIM_INFINITY;
 		l.rlim_max = RLIM_INFINITY;
 		if (setrlimit(RLIMIT_CORE, &l)) {
-			ast_log(LOG_WARNING, "Unable to disable core size resource limit: %s\n", strerror(errno));
+			fprintf(stderr, "Unable to disable core size resource limit: %s\n", strerror(errno));
 		}
 	}
 
 	if (getrlimit(RLIMIT_NOFILE, &l)) {
-		ast_log(LOG_WARNING, "Unable to check file descriptor limit: %s\n", strerror(errno));
+		fprintf(stderr, "Unable to check file descriptor limit: %s\n", strerror(errno));
 	}
 
 #if !defined(CONFIGURE_RAN_AS_ROOT)
@@ -3765,13 +3743,13 @@
 		}
 
 		if (!(fd = open("/dev/null", O_RDONLY))) {
-			ast_log(LOG_ERROR, "Cannot open a file descriptor at boot? %s\n", strerror(errno));
+			fprintf(stderr, "Cannot open a file descriptor at boot? %s\n", strerror(errno));
 			break; /* XXX Should we exit() here? XXX */
 		}
 
 		fd2 = ((l.rlim_cur > sizeof(readers) * 8) ? sizeof(readers) * 8 : l.rlim_cur) - 1;
 		if (dup2(fd, fd2) < 0) {
-			ast_log(LOG_WARNING, "Cannot open maximum file descriptor %d at boot? %s\n", fd2, strerror(errno));
+			fprintf(stderr, "Cannot open maximum file descriptor %d at boot? %s\n", fd2, strerror(errno));
 			close(fd);
 			break;
 		}
@@ -3779,7 +3757,7 @@
 		FD_ZERO(&readers);
 		FD_SET(fd2, &readers);
 		if (ast_select(fd2 + 1, &readers, NULL, NULL, &tv) < 0) {
-			ast_log(LOG_WARNING, "Maximum select()able file descriptor is %d\n", FD_SETSIZE);
+			fprintf(stderr, "Maximum select()able file descriptor is %d\n", FD_SETSIZE);
 		}
 		ast_FD_SETSIZE = l.rlim_cur > ast_FDMAX ? ast_FDMAX : l.rlim_cur;
 		close(fd);
@@ -3805,7 +3783,7 @@
 		if (errno == EEXIST) {
 			rundir_exists = 1;
 		} else {
-			ast_log(LOG_WARNING, "Unable to create socket file directory.  Remote consoles will not be able to connect! (%s)\n", strerror(x));
+			fprintf(stderr, "Unable to create socket file directory.  Remote consoles will not be able to connect! (%s)\n", strerror(x));
 		}
 	}
 
@@ -3819,18 +3797,18 @@
 		struct group *gr;
 		gr = getgrnam(rungroup);
 		if (!gr) {
-			ast_log(LOG_WARNING, "No such group '%s'!\n", rungroup);
+			fprintf(stderr, "No such group '%s'!\n", rungroup);
 			exit(1);
 		}
 		if (!rundir_exists && chown(ast_config_AST_RUN_DIR, -1, gr->gr_gid)) {
-			ast_log(LOG_WARNING, "Unable to chgrp run directory to %d (%s)\n", (int) gr->gr_gid, rungroup);
+			fprintf(stderr, "Unable to chgrp run directory to %d (%s)\n", (int) gr->gr_gid, rungroup);
 		}
 		if (setgid(gr->gr_gid)) {
-			ast_log(LOG_WARNING, "Unable to setgid to %d (%s)\n", (int)gr->gr_gid, rungroup);
+			fprintf(stderr, "Unable to setgid to %d (%s)\n", (int)gr->gr_gid, rungroup);
 			exit(1);
 		}
 		if (setgroups(0, NULL)) {
-			ast_log(LOG_WARNING, "Unable to drop unneeded groups\n");
+			fprintf(stderr, "Unable to drop unneeded groups\n");
 			exit(1);
 		}
 		ast_verb(1, "Running as group '%s'\n", rungroup);
@@ -3843,37 +3821,37 @@
 		struct passwd *pw;
 		pw = getpwnam(runuser);
 		if (!pw) {
-			ast_log(LOG_WARNING, "No such user '%s'!\n", runuser);
+			fprintf(stderr, "No such user '%s'!\n", runuser);
 			exit(1);
 		}
 		if (chown(ast_config_AST_RUN_DIR, pw->pw_uid, -1)) {
-			ast_log(LOG_WARNING, "Unable to chown run directory to %d (%s)\n", (int) pw->pw_uid, runuser);
+			fprintf(stderr, "Unable to chown run directory to %d (%s)\n", (int) pw->pw_uid, runuser);
 		}
 #ifdef HAVE_CAP
 		if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
-			ast_log(LOG_WARNING, "Unable to keep capabilities.\n");
+			fprintf(stderr, "Unable to keep capabilities.\n");
 			has_cap = 0;
 		}
 #endif /* HAVE_CAP */
 		if (!isroot && pw->pw_uid != geteuid()) {
-			ast_log(LOG_ERROR, "Asterisk started as nonroot, but runuser '%s' requested.\n", runuser);
+			fprintf(stderr, "Asterisk started as nonroot, but runuser '%s' requested.\n", runuser);
 			exit(1);
 		}
 		if (!rungroup) {
 			if (setgid(pw->pw_gid)) {
-				ast_log(LOG_WARNING, "Unable to setgid to %d!\n", (int)pw->pw_gid);
+				fprintf(stderr, "Unable to setgid to %d!\n", (int)pw->pw_gid);
 				exit(1);
 			}
 			if (isroot && initgroups(pw->pw_name, pw->pw_gid)) {
-				ast_log(LOG_WARNING, "Unable to init groups for '%s'\n", runuser);
+				fprintf(stderr, "Unable to init groups for '%s'\n", runuser);
 				exit(1);
 			}
 		}
 		if (setuid(pw->pw_uid)) {
-			ast_log(LOG_WARNING, "Unable to setuid to %d (%s)\n", (int)pw->pw_uid, runuser);
+			fprintf(stderr, "Unable to setuid to %d (%s)\n", (int)pw->pw_uid, runuser);
 			exit(1);
 		}
-		ast_verb(1, "Running as user '%s'\n", runuser);
+
 #ifdef HAVE_CAP
 		if (has_cap) {
 			cap_t cap;
@@ -3894,7 +3872,7 @@
 #ifdef linux
 	if (geteuid() && ast_opt_dump_core) {
 		if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0) {
-			ast_log(LOG_WARNING, "Unable to set the process for core dumps after changing to a non-root user. %s\n", strerror(errno));
+			fprintf(stderr, "Unable to set the process for core dumps after changing to a non-root user. %s\n", strerror(errno));
 		}
 	}
 #endif
@@ -3906,40 +3884,21 @@
 #endif
 		char dir[PATH_MAX];
 		if (!getcwd(dir, sizeof(dir)) || eaccess(dir, R_OK | X_OK | F_OK)) {
-			ast_log(LOG_ERROR, "Unable to access the running directory (%s).  Changing to '/' for compatibility.\n", strerror(errno));
+			fprintf(stderr, "Unable to access the running directory (%s).  Changing to '/' for compatibility.\n", strerror(errno));
 			/* If we cannot access the CWD, then we couldn't dump core anyway,
 			 * so chdir("/") won't break anything. */
 			if (chdir("/")) {
 				/* chdir(/) should never fail, so this ends up being a no-op */
-				ast_log(LOG_ERROR, "chdir(\"/\") failed?!! %s\n", strerror(errno));
+				fprintf(stderr, "chdir(\"/\") failed?!! %s\n", strerror(errno));
 			}
 		} else
 #endif /* defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS) */
 		if (!ast_opt_no_fork && !ast_opt_dump_core) {
 			/* Backgrounding, but no cores, so chdir won't break anything. */
 			if (chdir("/")) {
-				ast_log(LOG_ERROR, "Unable to chdir(\"/\") ?!! %s\n", strerror(errno));
-			}
-		}
-	}
-
-	ast_term_init();
-	printf("%s", term_end());
-	fflush(stdout);
-
-	if (ast_opt_console && !option_verbose) {
-		ast_verbose("[ Initializing Custom Configuration Options ]\n");
-	}
-	/* custom config setup */
-	register_config_cli();
-	read_config_maps();
-
-	if (ast_opt_console) {
-		if (el_hist == NULL || el == NULL)
-			ast_el_initialize();
-
-		if (!ast_strlen_zero(filename))
-			ast_el_read_history(filename);
+				fprintf(stderr, "Unable to chdir(\"/\") ?!! %s\n", strerror(errno));
+			}
+		}
 	}
 
 	if (ast_tryconnect()) {
@@ -3955,77 +3914,137 @@
 			quit_handler(0, SHUTDOWN_FAST, 0);
 			exit(0);
 		} else {
-			ast_log(LOG_ERROR, "Asterisk already running on %s.  Use 'asterisk -r' to connect.\n", ast_config_AST_SOCKET);
+			fprintf(stderr, "Asterisk already running on %s.  Use 'asterisk -r' to connect.\n", ast_config_AST_SOCKET);
 			printf("%s", term_quit());
 			exit(1);
 		}
 	} else if (ast_opt_remote || ast_opt_exec) {
-		ast_log(LOG_ERROR, "Unable to connect to remote asterisk (does %s exist?)\n", ast_config_AST_SOCKET);
+		fprintf(stderr, "Unable to connect to remote asterisk (does %s exist?)\n", ast_config_AST_SOCKET);
 		printf("%s", term_quit());
 		exit(1);
 	}
-	/* Blindly write pid file since we couldn't connect */
+
+	/* This needs to remain as high up in the initial start up as possible.
+	 * daemon causes a fork to occur, which has all sorts of unintended
+	 * consequences for things that interact with threads.  This call *must*
+	 * occur before anything in Asterisk spawns or manipulates thread related
+	 * primitives.
+	 */
+#if HAVE_WORKING_FORK
+	if (ast_opt_always_fork || !ast_opt_no_fork) {
+#ifndef HAVE_SBIN_LAUNCHD
+		if (daemon(1, 0) < 0) {
+			fprintf(stderr, "daemon() failed: %s\n", strerror(errno));
+		}
+#else
+		fprintf(stderr, "Mac OS X detected.  Use 'launchctl load /Library/LaunchDaemon/org.asterisk.asterisk.plist'.\n");
+#endif
+	}
+#endif
+
+	/* Spawning of astcanary must happen AFTER the call to daemon(3) */
+	if (isroot && ast_opt_high_priority) {
+		snprintf(canary_filename, sizeof(canary_filename), "%s/alt.asterisk.canary.tweet.tweet.tweet", ast_config_AST_RUN_DIR);
+
+		/* Don't let the canary child kill Asterisk, if it dies immediately */
+		sigaction(SIGPIPE, &ignore_sig_handler, NULL);
+
+		canary_pid = fork();
+		if (canary_pid == 0) {
+			char canary_binary[PATH_MAX], ppid[12];
+
+			/* Reset signal handler */
+			signal(SIGCHLD, SIG_DFL);
+			signal(SIGPIPE, SIG_DFL);
+
+			ast_close_fds_above_n(0);
+			ast_set_priority(0);
+			snprintf(ppid, sizeof(ppid), "%d", (int) ast_mainpid);
+
+			/* Use the astcanary binary that we installed */
+			snprintf(canary_binary, sizeof(canary_binary), "%s/astcanary", ast_config_AST_SBIN_DIR);
+			execl(canary_binary, "astcanary", canary_filename, ppid, (char *)NULL);
+
+			/* Should never happen */
+			_exit(1);
+		} else if (canary_pid > 0) {
+			pthread_t dont_care;
+			ast_pthread_create_detached(&dont_care, NULL, canary_thread, NULL);
+		}
+
+		/* Kill the canary when we exit */
+		ast_register_atexit(canary_exit);
+	}
+
+	/* At this point everything has been forked successfully and
+	 * we have determined that we aren't attempting to connect to
+	 * an Asterisk instance, and that there isn't one already running.
+	 * Blindly write the PID file. */
 	unlink(ast_config_AST_PID);
 	f = fopen(ast_config_AST_PID, "w");
 	if (f) {
 		fprintf(f, "%ld\n", (long)getpid());
 		fclose(f);
-	} else
-		ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", ast_config_AST_PID, strerror(errno));
-
-#if HAVE_WORKING_FORK
-	if (ast_opt_always_fork || !ast_opt_no_fork) {
-#ifndef HAVE_SBIN_LAUNCHD
-		if (daemon(1, 0) < 0) {
-			ast_log(LOG_ERROR, "daemon() failed: %s\n", strerror(errno));
-		}
-		ast_mainpid = getpid();
-		/* Blindly re-write pid file since we are forking */
-		unlink(ast_config_AST_PID);
-		f = fopen(ast_config_AST_PID, "w");
-		if (f) {
-			fprintf(f, "%ld\n", (long)ast_mainpid);
-			fclose(f);
-		} else
-			ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", ast_config_AST_PID, strerror(errno));
-#else
-		ast_log(LOG_WARNING, "Mac OS X detected.  Use 'launchctl load /Library/LaunchDaemon/org.asterisk.asterisk.plist'.\n");
-#endif
-	}
-#endif
-
-	/* Spawning of astcanary must happen AFTER the call to daemon(3) */
-	if (isroot && ast_opt_high_priority) {
-		snprintf(canary_filename, sizeof(canary_filename), "%s/alt.asterisk.canary.tweet.tweet.tweet", ast_config_AST_RUN_DIR);
-
-		/* Don't let the canary child kill Asterisk, if it dies immediately */
-		sigaction(SIGPIPE, &ignore_sig_handler, NULL);
-
-		canary_pid = fork();
-		if (canary_pid == 0) {
-			char canary_binary[PATH_MAX], ppid[12];
-
-			/* Reset signal handler */
-			signal(SIGCHLD, SIG_DFL);
-			signal(SIGPIPE, SIG_DFL);
-
-			ast_close_fds_above_n(0);
-			ast_set_priority(0);
-			snprintf(ppid, sizeof(ppid), "%d", (int) ast_mainpid);
-
-			/* Use the astcanary binary that we installed */
-			snprintf(canary_binary, sizeof(canary_binary), "%s/astcanary", ast_config_AST_SBIN_DIR);
-			execl(canary_binary, "astcanary", canary_filename, ppid, (char *)NULL);
-
-			/* Should never happen */
-			_exit(1);
-		} else if (canary_pid > 0) {
-			pthread_t dont_care;
-			ast_pthread_create_detached(&dont_care, NULL, canary_thread, NULL);
-		}
-
-		/* Kill the canary when we exit */
-		ast_register_atexit(canary_exit);
+	} else {
+		fprintf(stderr, "Unable to open pid file '%s': %s\n", ast_config_AST_PID, strerror(errno));
+	}
+
+	/* Initialize the terminal.  Since all processes have been forked,
+	 * we can now start using the standard log messages.
+	 */
+	ast_term_init();
+	printf("%s", term_end());
+	fflush(stdout);
+
+	if (ast_opt_console || option_verbose || (ast_opt_remote && !ast_opt_exec)) {
+		if (ast_register_verbose(console_verboser)) {
+			fprintf(stderr, "Unable to register console verboser?\n");
+		}
+		WELCOME_MESSAGE;
+	}
+	if (runuser) {
+		ast_verbose("Running as user '%s'", runuser);
+	}
+
+	if (ast_opt_console && !option_verbose) {
+		ast_verbose("[ Initializing Custom Configuration Options ]\n");
+	}
+	/* custom config setup */
+	register_config_cli();
+	read_config_maps();
+
+	if (ast_opt_console) {
+		if (el_hist == NULL || el == NULL)
+			ast_el_initialize();
+
+		if (!ast_strlen_zero(filename))
+			ast_el_read_history(filename);
+	}
+
+	ast_ulaw_init();
+	ast_alaw_init();
+	tdd_init();
+	callerid_init();
+	ast_builtins_init();
+
+	if (ast_utils_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
+	if (ast_tps_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
+	if (ast_fd_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
+	if (ast_pbx_init()) {
+		printf("%s", term_quit());
+		exit(1);
 	}
 
 	if (ast_event_init()) {
@@ -4235,9 +4254,9 @@
 
 	pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
 
-#if defined(__AST_DEBUG_MALLOC)
+#ifdef __AST_DEBUG_MALLOC
 	__ast_mm_init_phase_2();
-#endif	/* defined(__AST_DEBUG_MALLOC) */
+#endif
 
 	ast_lastreloadtime = ast_startuptime = ast_tvnow();
 	ast_cli_register_multiple(cli_asterisk, ARRAY_LEN(cli_asterisk));

Modified: team/mjordan/trunk-deadlock/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-deadlock/main/utils.c?view=diff&rev=376377&r1=376374&r2=376377
==============================================================================
--- team/mjordan/trunk-deadlock/main/utils.c (original)
+++ team/mjordan/trunk-deadlock/main/utils.c Thu Nov 15 20:33:58 2012
@@ -999,7 +999,22 @@
 #ifdef DEBUG_THREADS
 	struct thr_lock_info *lock_info;
 	pthread_mutexattr_t mutex_attr;
-#endif
+
+	if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info))))
+		return NULL;
+
+	lock_info->thread_id = pthread_self();
+	lock_info->thread_name = strdup(a.name);
+
+	pthread_mutexattr_init(&mutex_attr);
+	pthread_mutexattr_settype(&mutex_attr, AST_MUTEX_KIND);
+	pthread_mutex_init(&lock_info->lock, &mutex_attr);
+	pthread_mutexattr_destroy(&mutex_attr);
+
+	pthread_mutex_lock(&lock_infos_lock.mutex); /* Intentionally not the wrapper */
+	AST_LIST_INSERT_TAIL(&lock_infos, lock_info, entry);
+	pthread_mutex_unlock(&lock_infos_lock.mutex); /* Intentionally not the wrapper */
+#endif /* DEBUG_THREADS */
 
 	/* note that even though data->name is a pointer to allocated memory,
 	   we are not freeing it here because ast_register_thread is going to
@@ -1009,23 +1024,6 @@
 	ast_free(data);
 	ast_register_thread(a.name);
 	pthread_cleanup_push(ast_unregister_thread, (void *) pthread_self());
-
-#ifdef DEBUG_THREADS
-	if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info))))
-		return NULL;
-
-	lock_info->thread_id = pthread_self();
-	lock_info->thread_name = strdup(a.name);
-
-	pthread_mutexattr_init(&mutex_attr);
-	pthread_mutexattr_settype(&mutex_attr, AST_MUTEX_KIND);
-	pthread_mutex_init(&lock_info->lock, &mutex_attr);
-	pthread_mutexattr_destroy(&mutex_attr);
-
-	pthread_mutex_lock(&lock_infos_lock.mutex); /* Intentionally not the wrapper */
-	AST_LIST_INSERT_TAIL(&lock_infos, lock_info, entry);
-	pthread_mutex_unlock(&lock_infos_lock.mutex); /* Intentionally not the wrapper */
-#endif /* DEBUG_THREADS */
 
 	ret = a.start_routine(a.data);
 




More information about the asterisk-commits mailing list