summaryrefslogtreecommitdiff
path: root/main/asterisk.c
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2008-01-17 00:05:13 +0000
committerRussell Bryant <russell@russellbryant.com>2008-01-17 00:05:13 +0000
commit8a5e93d766b7eae022550c8e38c76bc69aeb9429 (patch)
treecabd950041b10ac3d1014e2c257b8820d5b1df7d /main/asterisk.c
parentf2d31ec0c8d9a64e0adb9912716d0f4afc33fed6 (diff)
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. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@98986 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/asterisk.c')
-rw-r--r--main/asterisk.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 3ba00753c..3b3c2cb2a 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2664,7 +2664,7 @@ static void *canary_thread(void *unused)
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);
}
@@ -2681,6 +2681,40 @@ static void canary_exit(void)
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[])
{
int c;
@@ -3186,6 +3220,8 @@ int main(int argc, char *argv[])
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 */