[asterisk-commits] mjordan: branch mjordan/trunk-deadlock r376261 - /team/mjordan/trunk-deadlock...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 14 16:16:39 CST 2012


Author: mjordan
Date: Wed Nov 14 16:16:35 2012
New Revision: 376261

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376261
Log:
Shuffle some things around on startup

Modified:
    team/mjordan/trunk-deadlock/main/asterisk.c
    team/mjordan/trunk-deadlock/main/logger.c

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=376261&r1=376260&r2=376261
==============================================================================
--- team/mjordan/trunk-deadlock/main/asterisk.c (original)
+++ team/mjordan/trunk-deadlock/main/asterisk.c Wed Nov 14 16:16:35 2012
@@ -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")) {
@@ -3564,15 +3564,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"));
@@ -3696,16 +3687,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). */
@@ -3716,10 +3697,6 @@
 		}
 	}
 
-	if (ast_opt_console && !option_verbose) {
-		ast_verbose("[ Reading Master Configuration ]\n");
-	}
-
 	ast_readconfig();
 	env_init();
 
@@ -3727,10 +3704,10 @@
 		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");
+		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);
 	}
 
@@ -3739,12 +3716,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)
@@ -3761,13 +3738,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;
 		}
@@ -3775,7 +3752,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);
@@ -3801,7 +3778,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));
 		}
 	}
 
@@ -3815,18 +3792,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);
@@ -3839,37 +3816,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;
@@ -3890,7 +3867,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
@@ -3919,9 +3896,65 @@
 		}
 	}
 
+#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);
+	}
+
 	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");
@@ -3960,6 +3993,7 @@
 		printf("%s", term_quit());
 		exit(1);
 	}
+
 	/* Blindly write pid file since we couldn't connect */
 	unlink(ast_config_AST_PID);
 	f = fopen(ast_config_AST_PID, "w");
@@ -3969,61 +4003,33 @@
 	} 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);
-	}
-	fprintf(stderr, "Asterisk (startup) pid: %ld\n", (long)getpid());
+
+	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()) {
 		printf("%s", term_quit());
 		exit(1);

Modified: team/mjordan/trunk-deadlock/main/logger.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-deadlock/main/logger.c?view=diff&rev=376261&r1=376260&r2=376261
==============================================================================
--- team/mjordan/trunk-deadlock/main/logger.c (original)
+++ team/mjordan/trunk-deadlock/main/logger.c Wed Nov 14 16:16:35 2012
@@ -1226,6 +1226,9 @@
 	/* auto rotate if sig SIGXFSZ comes a-knockin */
 	sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL);
 
+	/* re-initialize the log msgs mutex*/
+	ast_mutex_init(&logmsgs.lock);
+
 	/* start logger thread */
 	ast_cond_init(&logcond, NULL);
 	if (ast_pthread_create(&logthread, NULL, logger_thread, NULL) < 0) {




More information about the asterisk-commits mailing list