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/trunk@178342 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
parent
0dbdfbbfe3
commit
90004ef794
|
@ -274,6 +274,7 @@ static int restartnow;
|
||||||
static pthread_t consolethread = AST_PTHREADT_NULL;
|
static pthread_t consolethread = AST_PTHREADT_NULL;
|
||||||
static int canary_pid = 0;
|
static int canary_pid = 0;
|
||||||
static char canary_filename[128];
|
static char canary_filename[128];
|
||||||
|
static int canary_pipe = -1;
|
||||||
|
|
||||||
static char randompool[256];
|
static char randompool[256];
|
||||||
|
|
||||||
|
@ -3298,8 +3299,17 @@ int main(int argc, char *argv[])
|
||||||
if (isroot) {
|
if (isroot) {
|
||||||
ast_set_priority(ast_opt_high_priority);
|
ast_set_priority(ast_opt_high_priority);
|
||||||
if (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);
|
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();
|
canary_pid = fork();
|
||||||
if (canary_pid == 0) {
|
if (canary_pid == 0) {
|
||||||
char canary_binary[128], *lastslash;
|
char canary_binary[128], *lastslash;
|
||||||
|
@ -3307,9 +3317,14 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* Reset signal handler */
|
/* Reset signal handler */
|
||||||
signal(SIGCHLD, SIG_DFL);
|
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);
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
execlp("astcanary", "astcanary", canary_filename, (char *)NULL);
|
execlp("astcanary", "astcanary", canary_filename, (char *)NULL);
|
||||||
|
|
||||||
|
@ -3324,6 +3339,7 @@ int main(int argc, char *argv[])
|
||||||
_exit(1);
|
_exit(1);
|
||||||
} else if (canary_pid > 0) {
|
} else if (canary_pid > 0) {
|
||||||
pthread_t dont_care;
|
pthread_t dont_care;
|
||||||
|
close(cpipe[1]);
|
||||||
ast_pthread_create_detached(&dont_care, NULL, canary_thread, NULL);
|
ast_pthread_create_detached(&dont_care, NULL, canary_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ int main(int argc, char *argv[])
|
||||||
int fd;
|
int fd;
|
||||||
/* Run at normal priority */
|
/* Run at normal priority */
|
||||||
setpriority(PRIO_PROCESS, 0, 0);
|
setpriority(PRIO_PROCESS, 0, 0);
|
||||||
for (; getppid() != 1;) {
|
for (;;) {
|
||||||
/* Update the modification times (checked from Asterisk) */
|
/* Update the modification times (checked from Asterisk) */
|
||||||
if (utime(argv[1], NULL)) {
|
if (utime(argv[1], NULL)) {
|
||||||
/* Recreate the file if it doesn't exist */
|
/* Recreate the file if it doesn't exist */
|
||||||
|
@ -108,7 +108,7 @@ int main(int argc, char *argv[])
|
||||||
sleep(5);
|
sleep(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reached if asterisk (our parent process) dies - its chldren are inherited by the init process (pid is 1). */
|
/* Never reached */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue