From 5125deb3148e6711a6855de8430c4958ed77eaa1 Mon Sep 17 00:00:00 2001 From: tilghman Date: Mon, 11 Dec 2006 00:33:59 +0000 Subject: 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: http://svn.digium.com/svn/asterisk/branches/1.2@48374 f38db490-d61c-443f-a65b-d21fe96a405b --- apps/app_externalivr.c | 12 +++++++++++- apps/app_festival.c | 11 +++++++++-- apps/app_ices.c | 18 +++++++++++++++--- apps/app_mp3.c | 16 +++++++++++++--- apps/app_nbscat.c | 16 +++++++++++++--- apps/app_zapras.c | 18 +++++++++++++----- 6 files changed, 74 insertions(+), 17 deletions(-) (limited to 'apps') diff --git a/apps/app_externalivr.c b/apps/app_externalivr.c index fc5f34082..068463cec 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 7c69dc8b9..33f54aaf3 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