[asterisk-commits] russell: trunk r98986 - in /trunk: CHANGES main/asterisk.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 16 18:05:13 CST 2008


Author: russell
Date: Wed Jan 16 18:05:13 2008
New Revision: 98986

URL: http://svn.digium.com/view/asterisk?view=rev&rev=98986
Log:
Add support for an easy way to automatically execute some Asterisk CLI commands
immediately at startup.  Any commands in the startup_commands file in the Asterisk
config diretory will get executed.

(closes issue #11781)
Reported by: jamesgolovich
Patches:
      asterisk-startupcmds.diff.txt uploaded by jamesgolovich (license 176)
	    -- With some changes by me.

Modified:
    trunk/CHANGES
    trunk/main/asterisk.c

Modified: trunk/CHANGES
URL: http://svn.digium.com/view/asterisk/trunk/CHANGES?view=diff&rev=98986&r1=98985&r2=98986
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Wed Jan 16 18:05:13 2008
@@ -79,6 +79,9 @@
      output to make debugging on busy systems much easier.
   * New CLI commands "dialplan set extenpatternmatching true/false"
   * New CLI command: "core set chanvar" to set a channel variable from the CLI.
+  * Added an easy way to execute Asterisk CLI commands at startup.  Any commands
+    listed in the startup_commands file in the Asterisk configuration directory
+    will get executed.
 
 SIP changes
 -----------

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=98986&r1=98985&r2=98986
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Wed Jan 16 18:05:13 2008
@@ -2664,7 +2664,7 @@
 		stat(canary_filename, &canary_stat);
 		tv = ast_tvnow();
 		if (tv.tv_sec > canary_stat.st_mtime + 60) {
-			ast_log(LOG_WARNING, "The canary is no more.  He has ceased to be!  He's expired and gone to meet his maker!  He's a stiff!  Bereft of life, he rests in peace.  His metabolic processes are now history!  He's off the twig!  He's kicked the bucket.  He's shuffled off his mortal coil, run down the curtain, and joined the bleeding choir invisibile!!  THIS is an EX-CANARY.  (Reducing priority)\n");
+			ast_log(LOG_WARNING, "The canary is no more.  He has ceased to be!  He's expired and gone to meet his maker!  He's a stiff!  Bereft of life, he rests in peace.  His metabolic processes are now history!  He's off the twig!  He's kicked the bucket.  He's shuffled off his mortal coil, run down the curtain, and joined the bleeding choir invisible!!  THIS is an EX-CANARY.  (Reducing priority)\n");
 			ast_set_priority(0);
 			pthread_exit(NULL);
 		}
@@ -2679,6 +2679,40 @@
 {
 	if (canary_pid > 0)
 		kill(canary_pid, SIGKILL);
+}
+
+static void run_startup_commands(void)
+{
+	char filename[PATH_MAX];
+	char buf[256];
+	FILE *f;
+	int fd;
+	
+	fd = open("/dev/null", O_RDWR);
+	if (fd < 0)
+		return;
+
+	snprintf(filename, sizeof(filename), "%s/startup_commands", ast_config_AST_CONFIG_DIR);
+
+	if (!(f = fopen(filename, "r"))) {
+		close(fd);
+		return;
+	}
+
+	while (fgets(buf, sizeof(buf), f)) {
+		size_t res = strlen(buf);
+
+		if (!res)
+			continue;
+
+		if (buf[res - 1] == '\n')
+			buf[res - 1] = '\0';
+
+		ast_cli_command(fd, buf);
+	}
+
+	fclose(f);
+	close(fd);
 }
 
 int main(int argc, char *argv[])
@@ -3186,6 +3220,8 @@
 	ast_lastreloadtime = ast_startuptime = ast_tvnow();
 	ast_cli_register_multiple(cli_asterisk, sizeof(cli_asterisk) / sizeof(struct ast_cli_entry));
 
+	run_startup_commands();
+
 	if (ast_opt_console) {
 		/* Console stuff now... */
 		/* Register our quit function */




More information about the asterisk-commits mailing list