aboutsummaryrefslogtreecommitdiffstats
path: root/main/asterisk.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2009-02-24 20:08:19 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2009-02-24 20:08:19 +0000
commitd8f744c6ec06b936939d9e567af277e5afa658a1 (patch)
tree99fa7f393b4ca65102c04fc9aa3eb1dbc8774720 /main/asterisk.c
parentb565e2b16f7fa888a492f14b95162bb0e2203d1b (diff)
Merged revisions 178342 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ........ r178342 | tilghman | 2009-02-24 14:06:48 -0600 (Tue, 24 Feb 2009) | 2 lines Use a SIGPIPE to kill the process, instead of depending upon the astcanary process being inherited by init. ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.1@178344 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/asterisk.c')
-rw-r--r--main/asterisk.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index b8cd0ad9a..9b3cb8f96 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -259,6 +259,7 @@ static int restartnow;
static pthread_t consolethread = AST_PTHREADT_NULL;
static int canary_pid = 0;
static char canary_filename[128];
+static int canary_pipe = -1;
static char randompool[256];
@@ -3139,8 +3140,17 @@ int main(int argc, char *argv[])
if (isroot) {
ast_set_priority(ast_opt_high_priority);
if (ast_opt_high_priority) {
+ int cpipe[2];
+
+ /* PIPE signal ensures that astcanary dies when Asterisk dies */
+ pipe(cpipe);
+ canary_pipe = cpipe[0];
+
snprintf(canary_filename, sizeof(canary_filename), "%s/alt.asterisk.canary.tweet.tweet.tweet", ast_config_AST_RUN_DIR);
+ /* Don't let the canary child kill Asterisk, if it dies immediately */
+ signal(SIGPIPE, SIG_IGN);
+
canary_pid = fork();
if (canary_pid == 0) {
char canary_binary[128], *lastslash;
@@ -3148,9 +3158,14 @@ int main(int argc, char *argv[])
/* Reset signal handler */
signal(SIGCHLD, SIG_DFL);
+ signal(SIGPIPE, SIG_DFL);
- for (fd = 0; fd < 100; fd++)
+ dup2(cpipe[1], 100);
+ close(cpipe[1]);
+
+ for (fd = 0; fd < 100; fd++) {
close(fd);
+ }
execlp("astcanary", "astcanary", canary_filename, (char *)NULL);
@@ -3165,6 +3180,7 @@ int main(int argc, char *argv[])
_exit(1);
} else if (canary_pid > 0) {
pthread_t dont_care;
+ close(cpipe[1]);
ast_pthread_create_detached(&dont_care, NULL, canary_thread, NULL);
}