[asterisk-commits] russell: trunk r99642 - in /trunk: ./ configs/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 22 14:33:16 CST 2008


Author: russell
Date: Tue Jan 22 14:33:16 2008
New Revision: 99642

URL: http://svn.digium.com/view/asterisk?view=rev&rev=99642
Log:
Change the Asterisk CLI startup commands feature to read commands to run from cli.conf
after a discussion on the -dev list.

Added:
    trunk/configs/cli.conf.sample   (with props)
Modified:
    trunk/CHANGES
    trunk/main/asterisk.c

Change Statistics:
 0 files changed

Modified: trunk/CHANGES
URL: http://svn.digium.com/view/asterisk/trunk/CHANGES?view=diff&rev=99642&r1=99641&r2=99642
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Tue Jan 22 14:33:16 2008
@@ -80,8 +80,7 @@
   * 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.
+    listed in the startup_commands section of cli.conf will get executed.
 
 SIP changes
 -----------

Added: trunk/configs/cli.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/cli.conf.sample?view=auto&rev=99642
==============================================================================
--- trunk/configs/cli.conf.sample (added)
+++ trunk/configs/cli.conf.sample Tue Jan 22 14:33:16 2008
@@ -1,0 +1,12 @@
+;
+; Asterisk CLI configuration
+;
+
+[startup_commands]
+;
+; Any commands listed in this section will get automatically executed
+; when Asterisk starts.
+;
+;sip set debug on = yes
+;core set verbose 3 = yes
+;core set debug 1 = yes

Propchange: trunk/configs/cli.conf.sample
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/configs/cli.conf.sample
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/configs/cli.conf.sample
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=99642&r1=99641&r2=99642
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Tue Jan 22 14:33:16 2008
@@ -2683,36 +2683,23 @@
 
 static void run_startup_commands(void)
 {
-	char filename[PATH_MAX];
-	char buf[256];
-	FILE *f;
 	int fd;
-	
+	struct ast_config *cfg;
+	struct ast_flags cfg_flags = { 0 };
+	struct ast_variable *v;
+
+	if (!(cfg = ast_config_load("cli.conf", cfg_flags)))
+		return;
+
 	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);
+	for (v = ast_variable_browse(cfg, "startup_commands"); v; v = v->next)
+		ast_cli_command(fd, v->name);
+
 	close(fd);
+	ast_config_destroy(cfg);
 }
 
 int main(int argc, char *argv[])




More information about the asterisk-commits mailing list