aboutsummaryrefslogtreecommitdiffstats
path: root/res/res_musiconhold.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-04-16 22:57:54 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-04-16 22:57:54 +0000
commitd9fc402428c10315d158f7cf960c9592276b3c82 (patch)
tree6dea5b8c8d8bb81a47195b75172db608ff217382 /res/res_musiconhold.c
parentc99aa3db824dfb5a6eddf4d7d96685e8eb1767d6 (diff)
Standardized routines for forking processes (keeps all the specialized code in one place).
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@114188 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res/res_musiconhold.c')
-rw-r--r--res/res_musiconhold.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index e7044eff9..e456b3c7e 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -404,7 +404,6 @@ 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")) {
@@ -490,12 +489,8 @@ static int spawn_mp3(struct mohclass *class)
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();
+ class->pid = ast_safe_fork(0);
if (class->pid < 0) {
close(fds[0]);
close(fds[1]);
@@ -503,24 +498,16 @@ static int spawn_mp3(struct mohclass *class)
return -1;
}
if (!class->pid) {
- int x;
-
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);
- /* Close unused file descriptors */
- for (x=3;x<8192;x++) {
- if (-1 != fcntl(x, F_GETFL)) {
- close(x);
- }
- }
+
+ /* Close everything else */
+ ast_close_fds_above_n(STDERR_FILENO);
+
/* Child */
chdir(class->dir);
if (ast_test_flag(class, MOH_CUSTOM)) {
@@ -533,12 +520,12 @@ static int spawn_mp3(struct mohclass *class)
/* Check PATH as a last-ditch effort */
execvp("mpg123", argv);
}
- ast_log(LOG_WARNING, "Exec failed: %s\n", strerror(errno));
+ /* Can't use logger, since log FDs are closed */
+ fprintf(stderr, "MOH: exec failed: %s\n", strerror(errno));
close(fds[1]);
_exit(1);
} else {
/* Parent */
- pthread_sigmask(SIG_SETMASK, &old_set, NULL);
close(fds[1]);
}
return fds[0];