aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-11 00:47:21 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-11 00:47:21 +0000
commit5d5b0ca48b0d770e792cde1fedb041f4c759426e (patch)
tree21af91d1593e4a3a2f2cfd366b1b2914d3ad3bbd /res
parent8b2c905a6c6adbeac57d717fea391beec10c5e3d (diff)
Merged revisions 48374 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2 ........ r48374 | tilghman | 2006-12-10 18:33:59 -0600 (Sun, 10 Dec 2006) | 5 lines 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.4@48375 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r--res/res_agi.c24
-rw-r--r--res/res_musiconhold.c11
2 files changed, 29 insertions, 6 deletions
diff --git a/res/res_agi.c b/res/res_agi.c
index ecac92282..a8417587f 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -240,7 +240,7 @@ static enum agi_result launch_script(char *script, char *argv[], int *fds, int *
int audio[2];
int x;
int res;
- sigset_t signal_set;
+ sigset_t signal_set, old_set;
if (!strncasecmp(script, "agi://", 6))
return launch_netscript(script, argv, fds, efd, opid);
@@ -282,11 +282,14 @@ static enum agi_result launch_script(char *script, char *argv[], int *fds, int *
return AGI_RESULT_FAILURE;
}
}
- ast_replace_sigchld();
+
+ /* Block SIGHUP during the fork - prevents a race */
+ sigfillset(&signal_set);
+ pthread_sigmask(SIG_BLOCK, &signal_set, &old_set);
pid = fork();
if (pid < 0) {
ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno));
- ast_unreplace_sigchld();
+ pthread_sigmask(SIG_SETMASK, &old_set, NULL);
return AGI_RESULT_FAILURE;
}
if (!pid) {
@@ -314,9 +317,18 @@ static enum agi_result launch_script(char *script, char *argv[], int *fds, int *
} else {
close(STDERR_FILENO + 1);
}
-
+
+ /* Before we unblock our signals, return our trapped signals back to the defaults */
+ signal(SIGHUP, SIG_DFL);
+ signal(SIGCHLD, SIG_DFL);
+ signal(SIGINT, SIG_DFL);
+ signal(SIGURG, SIG_DFL);
+ signal(SIGTERM, SIG_DFL);
+ signal(SIGPIPE, SIG_DFL);
+ signal(SIGXFSZ, SIG_DFL);
+
/* unblock important signal handlers */
- if (sigfillset(&signal_set) || pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) {
+ if (pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) {
ast_log(LOG_WARNING, "unable to unblock signals for AGI script: %s\n", strerror(errno));
_exit(1);
}
@@ -332,6 +344,7 @@ static enum agi_result launch_script(char *script, char *argv[], int *fds, int *
fflush(stdout);
_exit(1);
}
+ pthread_sigmask(SIG_SETMASK, &old_set, NULL);
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Launched AGI Script %s\n", script);
fds[0] = toast[0];
@@ -348,7 +361,6 @@ static enum agi_result launch_script(char *script, char *argv[], int *fds, int *
*opid = pid;
return AGI_RESULT_SUCCESS;
-
}
static void setup_env(struct ast_channel *chan, char *request, int fd, int enhanced)
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 267cbc92b..328b099af 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -340,6 +340,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")) {
@@ -424,6 +425,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) {
@@ -438,6 +444,10 @@ static int spawn_mp3(struct mohclass *class)
if (ast_opt_high_priority)
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);
@@ -464,6 +474,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];