aboutsummaryrefslogtreecommitdiffstats
path: root/asterisk.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-25 18:31:19 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-25 18:31:19 +0000
commit04a4a825d5e8df3e1e49df6a989a798da16e9064 (patch)
tree708ea01afbf6bf30580cf15a2baa4b615bfb86c2 /asterisk.c
parentbe0f7def4ca50cac92b73811654c339450cacb2b (diff)
Add the ability to retrieve the exit code of the forked AGI process. If there
is an error executing the AGI script, or the AGI script itself returns a non-zero value, the AGISTATUS variable will now be set to FAILURE instead of SUCCESS. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@30328 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'asterisk.c')
-rw-r--r--asterisk.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/asterisk.c b/asterisk.c
index 5c1807f86..2ab474ed8 100644
--- a/asterisk.c
+++ b/asterisk.c
@@ -608,21 +608,15 @@ static void null_sig_handler(int signal)
}
AST_MUTEX_DEFINE_STATIC(safe_system_lock);
+/*! Keep track of how many threads are currently trying to wait*() on
+ * a child process */
static unsigned int safe_system_level = 0;
static void *safe_system_prev_handler;
-int ast_safe_system(const char *s)
+void ast_replace_sigchld(void)
{
- pid_t pid;
- int x;
- int res;
- struct rusage rusage;
- int status;
unsigned int level;
- /* keep track of how many ast_safe_system() functions
- are running at this moment
- */
ast_mutex_lock(&safe_system_lock);
level = safe_system_level++;
@@ -631,6 +625,31 @@ int ast_safe_system(const char *s)
safe_system_prev_handler = signal(SIGCHLD, null_sig_handler);
ast_mutex_unlock(&safe_system_lock);
+}
+
+void ast_unreplace_sigchld(void)
+{
+ unsigned int level;
+
+ ast_mutex_lock(&safe_system_lock);
+ level = --safe_system_level;
+
+ /* only restore the handler if we are the last one */
+ if (level == 0)
+ signal(SIGCHLD, safe_system_prev_handler);
+
+ ast_mutex_unlock(&safe_system_lock);
+}
+
+int ast_safe_system(const char *s)
+{
+ pid_t pid;
+ int x;
+ int res;
+ struct rusage rusage;
+ int status;
+
+ ast_replace_sigchld();
pid = fork();
@@ -656,14 +675,7 @@ int ast_safe_system(const char *s)
res = -1;
}
- ast_mutex_lock(&safe_system_lock);
- level = --safe_system_level;
-
- /* only restore the handler if we are the last one */
- if (level == 0)
- signal(SIGCHLD, safe_system_prev_handler);
-
- ast_mutex_unlock(&safe_system_lock);
+ ast_unreplace_sigchld();
return res;
}