aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_nbscat.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 /apps/app_nbscat.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 'apps/app_nbscat.c')
-rw-r--r--apps/app_nbscat.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/apps/app_nbscat.c b/apps/app_nbscat.c
index 4e7203319..f47129674 100644
--- a/apps/app_nbscat.c
+++ b/apps/app_nbscat.c
@@ -41,6 +41,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
+#include "asterisk/app.h"
#define LOCAL_NBSCAT "/usr/local/bin/nbscat8k"
#define NBSCAT "/usr/bin/nbscat8k"
@@ -61,34 +62,25 @@ static char *descrip =
static int NBScatplay(int fd)
{
int res;
- int x;
- sigset_t fullset, oldset;
- sigfillset(&fullset);
- pthread_sigmask(SIG_BLOCK, &fullset, &oldset);
-
- res = fork();
- if (res < 0)
+ res = ast_safe_fork(0);
+ if (res < 0) {
ast_log(LOG_WARNING, "Fork failed\n");
+ }
+
if (res) {
- pthread_sigmask(SIG_SETMASK, &oldset, NULL);
return res;
}
- signal(SIGPIPE, SIG_DFL);
- pthread_sigmask(SIG_UNBLOCK, &fullset, NULL);
if (ast_opt_high_priority)
ast_set_priority(0);
dup2(fd, STDOUT_FILENO);
- for (x = STDERR_FILENO + 1; x < 1024; x++) {
- if (x != STDOUT_FILENO)
- close(x);
- }
+ ast_close_fds_above_n(STDERR_FILENO);
/* Most commonly installed in /usr/local/bin */
execl(NBSCAT, "nbscat8k", "-d", (char *)NULL);
execl(LOCAL_NBSCAT, "nbscat8k", "-d", (char *)NULL);
- ast_log(LOG_WARNING, "Execute of nbscat8k failed\n");
+ fprintf(stderr, "Execute of nbscat8k failed\n");
_exit(0);
}