From d1ba37f1c97b5c8e722c947e553f221bd1ec65e7 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Tue, 22 Jan 2008 20:33:16 +0000 Subject: Change the Asterisk CLI startup commands feature to read commands to run from cli.conf after a discussion on the -dev list. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@99642 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- CHANGES | 3 +-- configs/cli.conf.sample | 12 ++++++++++++ main/asterisk.c | 33 ++++++++++----------------------- 3 files changed, 23 insertions(+), 25 deletions(-) create mode 100644 configs/cli.conf.sample diff --git a/CHANGES b/CHANGES index 00757c4b1..704bef4a2 100644 --- a/CHANGES +++ b/CHANGES @@ -80,8 +80,7 @@ CLI Changes * 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 ----------- diff --git a/configs/cli.conf.sample b/configs/cli.conf.sample new file mode 100644 index 000000000..112ae1c90 --- /dev/null +++ b/configs/cli.conf.sample @@ -0,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 diff --git a/main/asterisk.c b/main/asterisk.c index 3b3c2cb2a..54a88a9f5 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -2683,36 +2683,23 @@ static void canary_exit(void) 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); + struct ast_config *cfg; + struct ast_flags cfg_flags = { 0 }; + struct ast_variable *v; - if (!(f = fopen(filename, "r"))) { - close(fd); + if (!(cfg = ast_config_load("cli.conf", cfg_flags))) return; - } - while (fgets(buf, sizeof(buf), f)) { - size_t res = strlen(buf); - - if (!res) - continue; - - if (buf[res - 1] == '\n') - buf[res - 1] = '\0'; + fd = open("/dev/null", O_RDWR); + if (fd < 0) + return; - ast_cli_command(fd, buf); - } + for (v = ast_variable_browse(cfg, "startup_commands"); v; v = v->next) + ast_cli_command(fd, v->name); - fclose(f); close(fd); + ast_config_destroy(cfg); } int main(int argc, char *argv[]) -- cgit v1.2.3