[asterisk-commits] mjordan: branch mjordan/1.8_instrumented r366352 - /team/mjordan/1.8_instrume...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 14 09:17:10 CDT 2012


Author: mjordan
Date: Mon May 14 09:17:05 2012
New Revision: 366352

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=366352
Log:
More tweaks to the exit path

Modified:
    team/mjordan/1.8_instrumented/main/asterisk.c

Modified: team/mjordan/1.8_instrumented/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/1.8_instrumented/main/asterisk.c?view=diff&rev=366352&r1=366351&r2=366352
==============================================================================
--- team/mjordan/1.8_instrumented/main/asterisk.c (original)
+++ team/mjordan/1.8_instrumented/main/asterisk.c Mon May 14 09:17:05 2012
@@ -953,7 +953,7 @@
 
 	ae->func = func;
 
-	ast_unregister_atexit(func);	
+	ast_unregister_atexit(func);
 
 	AST_RWLIST_WRLOCK(&atexits);
 	AST_RWLIST_INSERT_HEAD(&atexits, ae, list);
@@ -1330,13 +1330,13 @@
 		}
 		fds[0].fd = ast_socket;
 		fds[0].events = POLLIN;
+		ast_mutex_unlock(&listener_lock);
 		s = ast_poll(fds, 1, -1);
 		pthread_testcancel();
 		if (s < 0) {
 			if (errno != EINTR) {
 				ast_log(LOG_WARNING, "poll returned error: %s\n", strerror(errno));
 			}
-			ast_mutex_unlock(&listener_lock);
 			continue;
 		}
 		len = sizeof(sunaddr);
@@ -1474,6 +1474,7 @@
 	ast_consock = socket(PF_LOCAL, SOCK_STREAM, 0);
 	if (ast_consock < 0) {
 		printf("Unable to create socket: %s\n", strerror(errno));
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		return 0;
 	}
 	memset(&sunaddr, 0, sizeof(sunaddr));
@@ -1482,6 +1483,7 @@
 	res = connect(ast_consock, (struct sockaddr *)&sunaddr, sizeof(sunaddr));
 	if (res) {
 		printf("connect returned %s\n", strerror(errno));
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		close(ast_consock);
 		ast_consock = -1;
 		return 0;
@@ -1787,7 +1789,7 @@
 		/* close logger */
 		close_logger();
 	}
-
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	exit(0);
 }
 
@@ -1802,7 +1804,7 @@
 	}
 	/* There is no need to restore the signal handler here, since the app
 	 * is going to exit */
-	printf("In __quit_handler\n");
+	printf("%s[%d]\n", __FILE__, __LINE__);
 }
 
 static void __remote_quit_handler(int num)
@@ -1899,6 +1901,7 @@
 	if ((strncasecmp(s, "quit", 4) == 0 || strncasecmp(s, "exit", 4) == 0) &&
 	    (s[4] == '\0' || isspace(s[4]))) {
 		printf("Starting quit handler in remoteconsolehandler [%s]\n", s);
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		quit_handler(0, SHUTDOWN_FAST, 0);
 		ret = 1;
 	}
@@ -1953,6 +1956,7 @@
 	if (a->argc != e->args)
 		return CLI_SHOWUSAGE;
 	printf("Calling quit handler for handle_stop_now\n");
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	quit_handler(0, SHUTDOWN_NORMAL, 0 /* not restart */);
 	return CLI_SUCCESS;
 }
@@ -1974,6 +1978,7 @@
 	if (a->argc != e->args)
 		return CLI_SHOWUSAGE;
 	printf("Calling quit handler from handle_stop_gracefully\n");
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	quit_handler(0, SHUTDOWN_NICE, 0 /* no restart */);
 	return CLI_SUCCESS;
 }
@@ -1995,6 +2000,7 @@
 		return CLI_SHOWUSAGE;
 	ast_cli(a->fd, "Waiting for inactivity to perform halt\n");
 	printf("Calling quit handler from stop when convenient\n");
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	quit_handler(0, SHUTDOWN_REALLY_NICE, 0 /* don't restart */);
 	return CLI_SUCCESS;
 }
@@ -2016,6 +2022,7 @@
 	if (a->argc != e->args)
 		return CLI_SHOWUSAGE;
 	printf("Calling quit handler from core restart now\n");
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	quit_handler(0, SHUTDOWN_NORMAL, 1 /* restart */);
 	return CLI_SUCCESS;
 }
@@ -2037,6 +2044,7 @@
 	if (a->argc != e->args)
 		return CLI_SHOWUSAGE;
 	printf("Calling quit handler from restart gracefully\n");
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	quit_handler(0, SHUTDOWN_NICE, 1 /* restart */);
 	return CLI_SUCCESS;
 }
@@ -2057,6 +2065,7 @@
 	if (a->argc != e->args)
 		return CLI_SHOWUSAGE;
 	ast_cli(a->fd, "Waiting for inactivity to perform restart\n");
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	quit_handler(0, SHUTDOWN_REALLY_NICE, 1 /* restart */);
 	return CLI_SUCCESS;
 }
@@ -2248,6 +2257,7 @@
 		if (!ast_opt_exec && fds[1].revents) {
 			num_read = read(STDIN_FILENO, cp, 1);
 			if (num_read < 1) {
+				printf("%s[%d]\n", __FILE__, __LINE__);
 				break;
 			} else 
 				return (num_read);
@@ -2258,8 +2268,10 @@
 			/* if the remote side disappears exit */
 			if (res < 1) {
 				fprintf(stderr, "\nDisconnected from Asterisk server\n");
+				printf("%s[%d]\n", __FILE__, __LINE__);
 				if (!ast_opt_reconnect) {
 					printf("Disconnected from Asterisk server, shutting down fast\n");
+					printf("%s[%d]\n", __FILE__, __LINE__);
 					quit_handler(0, SHUTDOWN_FAST, 0);
 				} else {
 					int tries;
@@ -2268,6 +2280,7 @@
 					for (tries = 0; tries < 30 * reconnects_per_second; tries++) {
 						if (ast_tryconnect()) {
 							fprintf(stderr, "Reconnect succeeded after %.3f seconds\n", 1.0 / reconnects_per_second * tries);
+							printf("%s[%d]\n", __FILE__, __LINE__);
 							printf("%s", term_quit());
 							WELCOME_MESSAGE;
 							if (!ast_opt_mute)
@@ -2280,6 +2293,7 @@
 					}
 					if (tries >= 30 * reconnects_per_second) {
 						fprintf(stderr, "Failed to reconnect for 30 seconds.  Quitting.\n");
+						printf("%s[%d]\n", __FILE__, __LINE__);
 						printf ("Failed to reconnect, shutting down fast\n");
 						quit_handler(0, SHUTDOWN_FAST, 0);
 					}
@@ -2300,18 +2314,21 @@
 			/* Write over the CLI prompt */
 			if (!ast_opt_exec && !lastpos) {
 				if (write(STDOUT_FILENO, "\r", 5) < 0) {
+					printf("%s[%d]\n", __FILE__, __LINE__);
 				}
 			}
 			if (write(STDOUT_FILENO, buf, res) < 0) {
+				printf("%s[%d]\n", __FILE__, __LINE__);
 			}
 			if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (buf[res-2] == '\n'))) {
 				*cp = CC_REFRESH;
+				printf("%s[%d]\n", __FILE__, __LINE__);
 				return(1);
 			} else
 				lastpos = 1;
 		}
 	}
-
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	*cp = '\0';
 	return (0);
 }
@@ -2586,6 +2603,7 @@
 			/* Start with a 2048 byte buffer */			
 			if (!(mbuf = ast_malloc(maxmbuf))) {
 				lf->cursor[0] = savechr;
+				printf("%s[%d]\n", __FILE__, __LINE__);
 				return (char *)(CC_ERROR);
 			}
 			snprintf(buf, sizeof(buf), "_COMMAND MATCHESARRAY \"%s\" \"%s\"", lf->buffer, ptr); 
@@ -2770,6 +2788,7 @@
 
 	if (read(ast_consock, buf, sizeof(buf)) < 0) {
 		ast_log(LOG_ERROR, "read() failed: %s\n", strerror(errno));
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		return;
 	}
 	if (data) {
@@ -2778,7 +2797,9 @@
 		sprintf(tmp, "%s%s", prefix, data);
 		if (write(ast_consock, tmp, strlen(tmp) + 1) < 0) {
 			ast_log(LOG_ERROR, "write() failed: %s\n", strerror(errno));
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			if (sig_flags.need_quit || sig_flags.need_quit_handler) {
+				printf("%s[%d]\n", __FILE__, __LINE__);
 				return;
 			}
 		}
@@ -2836,6 +2857,7 @@
 					not_written = 0;
 					if (write(STDOUT_FILENO, curline, nextline - curline) < 0) {
 						ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
+						printf("%s[%d]\n", __FILE__, __LINE__);
 					}
 				}
 				curline = nextline;
@@ -2850,6 +2872,7 @@
 	}
 
 	ast_verbose("Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid);
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	remotehostname = hostname;
 	if (getenv("HOME")) 
 		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
@@ -2865,6 +2888,7 @@
 		ebuf = (char *)el_gets(el, &num);
 
 		if (sig_flags.need_quit || sig_flags.need_quit_handler) {
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			break;
 		}
 
@@ -2886,6 +2910,7 @@
 				res = write(ast_consock, ebuf, strlen(ebuf) + 1);
 				if (res < 1) {
 					ast_log(LOG_WARNING, "Unable to write: %s\n", strerror(errno));
+					printf("%s[%d]\n", __FILE__, __LINE__);
 					break;
 				}
 			}
@@ -3193,6 +3218,7 @@
 				sig_flags.need_quit_handler = 1;
 				pthread_kill(consolethread, SIGURG);
 			} else {
+				printf("%s[%d]\n", __FILE__, __LINE__);
 				quit_handler(0, SHUTDOWN_NORMAL, 0);
 			}
 		}
@@ -3515,12 +3541,14 @@
 
 		if (!(fd = open("/dev/null", O_RDONLY))) {
 			ast_log(LOG_ERROR, "Cannot open a file descriptor at boot? %s\n", strerror(errno));
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			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));
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			close(fd);
 			break;
 		}
@@ -3529,6 +3557,7 @@
 		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);
+			printf("%s[%d]\n", __FILE__, __LINE__);
 		}
 		ast_FD_SETSIZE = l.rlim_cur > ast_FDMAX ? ast_FDMAX : l.rlim_cur;
 		close(fd);
@@ -3554,6 +3583,7 @@
 		if (errno == EEXIST) {
 			rundir_exists = 1;
 		} else {
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			printf("Unable to create socket file directory.  Remote consoles will not be able to connect! (%s)\n", strerror(x));
 		}
 	}
@@ -3569,17 +3599,21 @@
 		gr = getgrnam(rungroup);
 		if (!gr) {
 			printf("No such group '%s'!\n", rungroup);
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			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);
+			printf("%s[%d]\n", __FILE__, __LINE__);
 		}
 		if (setgid(gr->gr_gid)) {
 			printf("Unable to setgid to %d (%s)\n", (int)gr->gr_gid, rungroup);
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			exit(1);
 		}
 		if (setgroups(0, NULL)) {
 			printf("Unable to drop unneeded groups\n");
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			exit(1);
 		}
 		if (option_verbose)
@@ -3594,33 +3628,40 @@
 		pw = getpwnam(runuser);
 		if (!pw) {
 			printf("No such user '%s'!\n", runuser);
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			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);
+			printf("%s[%d]\n", __FILE__, __LINE__);
 		}
 #ifdef HAVE_CAP
 		if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
 			ast_log(LOG_WARNING, "Unable to keep capabilities.\n");
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			has_cap = 0;
 		}
 #endif /* HAVE_CAP */
 		if (!isroot && pw->pw_uid != geteuid()) {
 			printf("Asterisk started as nonroot, but runuser '%s' requested.\n", runuser);
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			exit(1);
 		}
 		if (!rungroup) {
 			if (setgid(pw->pw_gid)) {
 				printf("Unable to setgid to %d!\n", (int)pw->pw_gid);
+				printf("%s[%d]\n", __FILE__, __LINE__);
 				exit(1);
 			}
 			if (isroot && initgroups(pw->pw_name, pw->pw_gid)) {
 				printf("Unable to init groups for '%s'\n", runuser);
+				printf("%s[%d]\n", __FILE__, __LINE__);
 				exit(1);
 			}
 		}
 		if (setuid(pw->pw_uid)) {
 			printf("Unable to setuid to %d (%s)\n", (int)pw->pw_uid, runuser);
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			exit(1);
 		}
 		if (option_verbose)
@@ -3699,37 +3740,45 @@
 			if (ast_opt_exec) {
 				ast_remotecontrol(xarg);
 				printf("Shutting down fast after command execution\n");
+				printf("%s[%d]\n", __FILE__, __LINE__);
 				quit_handler(0, SHUTDOWN_FAST, 0);
 				exit(0);
 			}
 			printf("%s", term_quit());
 			ast_remotecontrol(NULL);
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			quit_handler(0, SHUTDOWN_FAST, 0);
 			exit(0);
 		} else {
 			printf("Asterisk already running on %s.  Use 'asterisk -r' to connect.\n", ast_config_AST_SOCKET);
 			printf("%s", term_quit());
+			printf("%s[%d]\n", __FILE__, __LINE__);
 			exit(1);
 		}
 	} else if (ast_opt_remote || ast_opt_exec) {
 		printf("Unable to connect to remote asterisk (does %s exist?)\n", ast_config_AST_SOCKET);
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 	/* Blindly write pid file since we couldn't connect */
 	unlink(ast_config_AST_PID);
 	f = fopen(ast_config_AST_PID, "w");
 	if (f) {
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		fprintf(f, "%ld\n", (long)getpid());
 		fclose(f);
-	} else
+	} else {
 		printf("Unable to open pid file '%s': %s\n", ast_config_AST_PID, strerror(errno));
+		printf("%s[%d]\n", __FILE__, __LINE__);
+	}
 
 #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));
+			printf("%s[%d]\n", __FILE__, __LINE__);
 		}
 		ast_mainpid = getpid();
 		/* Blindly re-write pid file since we are forking */
@@ -3787,18 +3836,21 @@
 
 	if (ast_event_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 #ifdef TEST_FRAMEWORK
 	if (ast_test_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 #endif
 
 	ast_aoc_cli_init();
 	printf("Before make socket\n");
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	ast_makesocket();
 	sigemptyset(&sigs);
 	sigaddset(&sigs, SIGHUP);
@@ -3813,6 +3865,7 @@
 	sigaction(SIGHUP, &hup_handler, NULL);
 	sigaction(SIGPIPE, &ignore_sig_handler, NULL);
 	printf("After signal handlers\n");
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	/* ensure that the random number generators are seeded with a different value every time
 	   Asterisk is started
 	*/
@@ -3821,22 +3874,25 @@
 
 	if (init_logger()) {		/* Start logging subsystem */
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	threadstorage_init();
-
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	astobj2_init();
-
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	ast_autoservice_init();
-
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	if (ast_timing_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (ast_ssl_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
@@ -3848,93 +3904,110 @@
 	/* initialize the data retrieval API */
 	if (ast_data_init()) {
 		printf ("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	ast_channels_init();
-
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	if ((moduleresult = load_modules(1))) {		/* Load modules, pre-load only */
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(moduleresult == -2 ? 2 : 1);
 	}
 
 	if (dnsmgr_init()) {		/* Initialize the DNS manager */
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	ast_http_init();		/* Start the HTTP server, if needed */
-
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	if (init_manager()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (ast_cdr_engine_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (ast_cel_engine_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (ast_device_state_engine_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	ast_dsp_init();
 	ast_udptl_init();
-
+	printf("%s[%d]\n", __FILE__, __LINE__);
 	if (ast_image_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (ast_file_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (load_pbx()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (ast_indications_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (ast_features_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (init_framer()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (astdb_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (ast_enum_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if (ast_cc_init()) {
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(1);
 	}
 
 	if ((moduleresult = load_modules(0))) {		/* Load modules */
 		printf("%s", term_quit());
+		printf("%s[%d]\n", __FILE__, __LINE__);
 		exit(moduleresult == -2 ? 2 : 1);
 	}
 
@@ -3989,6 +4062,7 @@
 		for (;;) {
 			if (sig_flags.need_quit || sig_flags.need_quit_handler) {
 				printf("Detected signal that we need to shut down now\n");
+				printf("%s[%d]\n", __FILE__, __LINE__);
 				quit_handler(0, SHUTDOWN_FAST, 0);
 				break;
 			}




More information about the asterisk-commits mailing list