From: Tilghman Lesher Date: Mon, 11 Dec 2006 00:33:59 +0000 (+0000) Subject: When doing a fork() and exec(), two problems existed (Issue 8086): X-Git-Tag: 1.2.14~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=983d09bc21484a956472f2befa02df645571dac5;p=thirdparty%2Fasterisk.git When doing a fork() and exec(), two problems existed (Issue 8086): 1) Ignored signals stayed ignored after the exec(). 2) Signals could possibly fire between the fork() and exec(), causing Asterisk signal handlers within the child to execute, which caused nasty race conditions. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@48374 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/apps/app_externalivr.c b/apps/app_externalivr.c index fc5f34082f..068463cec1 100644 --- a/apps/app_externalivr.c +++ b/apps/app_externalivr.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "asterisk.h" @@ -258,9 +259,13 @@ static int app_exec(struct ast_channel *chan, void *data) FILE *child_commands = NULL; FILE *child_errors = NULL; FILE *child_events = NULL; + sigset_t fullset, oldset; LOCAL_USER_ADD(u); - + + sigfillset(&fullset); + pthread_sigmask(SIG_BLOCK, &fullset, &oldset); + AST_LIST_HEAD_INIT(&u->playlist); AST_LIST_HEAD_INIT(&u->finishlist); u->abort_current_sound = 0; @@ -314,6 +319,9 @@ static int app_exec(struct ast_channel *chan, void *data) /* child process */ int i; + signal(SIGPIPE, SIG_DFL); + pthread_sigmask(SIG_UNBLOCK, &fullset, NULL); + if (option_highpriority) ast_set_priority(0); @@ -337,6 +345,8 @@ static int app_exec(struct ast_channel *chan, void *data) int waitfds[2] = { child_errors_fd, child_commands_fd }; struct ast_channel *rchan; + pthread_sigmask(SIG_SETMASK, &oldset, NULL); + close(child_stdin[0]); child_stdin[0] = 0; close(child_stdout[1]); diff --git a/apps/app_festival.c b/apps/app_festival.c index 7c69dc8b98..33f54aaf38 100644 --- a/apps/app_festival.c +++ b/apps/app_festival.c @@ -127,19 +127,26 @@ static int send_waveform_to_fd(char *waveform, int length, int fd) { #ifdef __PPC__ char c; #endif + sigset_t fullset, oldset; + + sigfillset(&fullset); + pthread_sigmask(SIG_BLOCK, &fullset, &oldset); res = fork(); if (res < 0) ast_log(LOG_WARNING, "Fork failed\n"); - if (res) + if (res) { + pthread_sigmask(SIG_SETMASK, &oldset, NULL); return res; + } for (x=0;x<256;x++) { if (x != fd) close(x); } if (option_highpriority) ast_set_priority(0); - + signal(SIGPIPE, SIG_DFL); + pthread_sigmask(SIG_UNBLOCK, &fullset, NULL); /*IAS */ #ifdef __PPC__ for( x=0; xfds[0], STDIN_FILENO); @@ -104,10 +116,6 @@ static pid_t spawn_ras(struct ast_channel *chan, char *args) for (x=STDERR_FILENO + 1;x<1024;x++) close(x); - /* Restore original signal handlers */ - for (x=0;x 2) ast_verbose(VERBOSE_PREFIX_3 "Launched AGI Script %s\n", script); fds[0] = toast[0]; diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index c7f1fff6a2..746fa2d061 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -326,6 +326,7 @@ static int spawn_mp3(struct mohclass *class) int argc = 0; DIR *dir = NULL; struct dirent *de; + sigset_t signal_set, old_set; if (!strcasecmp(class->dir, "nodir")) { @@ -426,6 +427,11 @@ static int spawn_mp3(struct mohclass *class) if (time(NULL) - class->start < respawn_time) { sleep(respawn_time - (time(NULL) - class->start)); } + + /* Block signals during the fork() */ + sigfillset(&signal_set); + pthread_sigmask(SIG_BLOCK, &signal_set, &old_set); + time(&class->start); class->pid = fork(); if (class->pid < 0) { @@ -440,6 +446,10 @@ static int spawn_mp3(struct mohclass *class) if (option_highpriority) ast_set_priority(0); + /* Reset ignored signals back to default */ + signal(SIGPIPE, SIG_DFL); + pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL); + close(fds[0]); /* Stdout goes to pipe */ dup2(fds[1], STDOUT_FILENO); @@ -466,6 +476,7 @@ static int spawn_mp3(struct mohclass *class) _exit(1); } else { /* Parent */ + pthread_sigmask(SIG_SETMASK, &old_set, NULL); close(fds[1]); } return fds[0];