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
This commit is contained in:
Russell Bryant
2008-01-22 20:33:16 +00:00
parent 949bb30d03
commit d1ba37f1c9
3 changed files with 23 additions and 25 deletions

View File

@@ -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;
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);
for (v = ast_variable_browse(cfg, "startup_commands"); v; v = v->next)
ast_cli_command(fd, v->name);
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);
ast_config_destroy(cfg);
}
int main(int argc, char *argv[])