mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-18 10:44:28 +00:00
Standardized routines for forking processes (keeps all the specialized code in one place).
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114188 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -50,6 +50,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#include "asterisk/channel.h"
|
||||
#include "asterisk/pbx.h"
|
||||
#include "asterisk/module.h"
|
||||
#include "asterisk/app.h"
|
||||
|
||||
static char *app = "ZapRAS";
|
||||
|
||||
@@ -69,30 +70,18 @@ static char *descrip =
|
||||
static pid_t spawn_ras(struct ast_channel *chan, char *args)
|
||||
{
|
||||
pid_t pid;
|
||||
int x;
|
||||
char *c;
|
||||
|
||||
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();
|
||||
pid = ast_safe_fork(1);
|
||||
if (pid) {
|
||||
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
||||
return pid;
|
||||
}
|
||||
|
||||
/* Restore original signal handlers */
|
||||
for (x=0;x<NSIG;x++)
|
||||
signal(x, SIG_DFL);
|
||||
|
||||
pthread_sigmask(SIG_UNBLOCK, &fullset, NULL);
|
||||
|
||||
/* Execute RAS on File handles */
|
||||
dup2(chan->fds[0], STDIN_FILENO);
|
||||
|
||||
@@ -101,8 +90,7 @@ static pid_t spawn_ras(struct ast_channel *chan, char *args)
|
||||
ast_set_priority(0);
|
||||
|
||||
/* Close other file descriptors */
|
||||
for (x=STDERR_FILENO + 1;x<1024;x++)
|
||||
close(x);
|
||||
ast_close_fds_above_n(STDERR_FILENO);
|
||||
|
||||
/* Reset all arguments */
|
||||
memset(argv, 0, sizeof(argv));
|
||||
@@ -185,6 +173,7 @@ static void run_ras(struct ast_channel *chan, char *args)
|
||||
break;
|
||||
}
|
||||
}
|
||||
ast_safe_fork_cleanup();
|
||||
}
|
||||
|
||||
static int zapras_exec(struct ast_channel *chan, void *data)
|
||||
|
Reference in New Issue
Block a user