Index: apps/app_zapras.c =================================================================== --- apps/app_zapras.c (revision 48373) +++ apps/app_zapras.c (working copy) @@ -87,12 +87,24 @@ char *argv[PPP_MAX_ARGS]; int argc = 0; char *stringp=NULL; + sigset_t fullset, oldset; + sigfillset(&fullset); + pthread_sigmask(SIG_BLOCK, &fullset, &oldset); + /* Start by forking */ pid = fork(); - if (pid) + if (pid) { + pthread_sigmask(SIG_SETMASK, &oldset, NULL); return pid; + } + /* Restore original signal handlers */ + for (x=0;xfds[0], STDIN_FILENO); @@ -104,10 +116,6 @@ for (x=STDERR_FILENO + 1;x<1024;x++) close(x); - /* Restore original signal handlers */ - for (x=0;x #include #include +#include #include "asterisk.h" @@ -258,9 +259,13 @@ 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 @@ /* 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 @@ 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]); Index: res/res_agi.c =================================================================== --- res/res_agi.c (revision 48373) +++ res/res_agi.c (working copy) @@ -234,7 +234,7 @@ 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); @@ -276,6 +276,10 @@ return -1; } } + + /* 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)); @@ -293,9 +297,18 @@ } 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); } @@ -310,6 +323,7 @@ fprintf(stderr, "Failed to execute '%s': %s\n", script, strerror(errno)); _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]; Index: res/res_musiconhold.c =================================================================== --- res/res_musiconhold.c (revision 48373) +++ res/res_musiconhold.c (working copy) @@ -326,6 +326,7 @@ int argc = 0; DIR *dir = NULL; struct dirent *de; + sigset_t signal_set, old_set; if (!strcasecmp(class->dir, "nodir")) { @@ -426,6 +427,11 @@ 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 @@ 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 @@ _exit(1); } else { /* Parent */ + pthread_sigmask(SIG_SETMASK, &old_set, NULL); close(fds[1]); } return fds[0];