]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
unmask SIGHUP before exec'ing AGI scripts (bug #4854)
authorRussell Bryant <russell@russellbryant.com>
Thu, 4 Aug 2005 22:52:15 +0000 (22:52 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 4 Aug 2005 22:52:15 +0000 (22:52 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/v1-0@6283 65c4cc65-6c06-0410-ace0-fbb531ad65f3

CHANGES
res/res_agi.c

diff --git a/CHANGES b/CHANGES
index 1882b4b38bf0c8aa842efe337394371aee244a39..ed2e926a8d3384e6bdc4d6f76258c111a7f41914 100755 (executable)
--- a/CHANGES
+++ b/CHANGES
     -- We now ensure buffer policy is restored after RAS is done with a channel.
        This could cause audio problems on the channel after zapras is done
        with it. 
+ -- res_agi
+    -- We now unmask the SIGHUP signal before executing an AGI script.  This
+       fixes problems where some AGI scripts would continue running long after
+       the call is over.
  -- extensions
     -- A potential crash has been fixed when calling LEN() to get the length of
        a string that was 80 characters or larger.
index 71c636ff8d0ee3e1c2561b3c8fd46821cc4a3fc3..819470b1335d7578ae63976a57465f8e6e6b0569 100755 (executable)
@@ -203,6 +203,7 @@ static int launch_script(char *script, char *argv[], int *fds, int *efd, int *op
        int audio[2];
        int x;
        int res;
+       sigset_t signal_set;
        
        if (!strncasecmp(script, "agi://", 6))
                return launch_netscript(script, argv, fds, efd, opid);
@@ -258,9 +259,17 @@ static int launch_script(char *script, char *argv[], int *fds, int *efd, int *op
                } else {
                        close(STDERR_FILENO + 1);
                }
+               
+               /* unblock important signal handlers */
+               if (sigfillset(&signal_set) || pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) {
+                       ast_log(LOG_WARNING, "unable to unblock signals for AGI script: %s\n", strerror(errno));
+                       exit(1);
+               }
+
                /* Close everything but stdin/out/error */
                for (x=STDERR_FILENO + 2;x<1024;x++) 
                        close(x);
+
                /* Execute script */
                execv(script, argv);
                /* Can't use ast_log since FD's are closed */
@@ -433,7 +442,7 @@ static int handle_streamfile(struct ast_channel *chan, AGI *agi, int argc, char
                return RESULT_SHOWUSAGE;
        
        fs = ast_openstream(chan, argv[2], chan->language);
-       if(!fs){
+       if (!fs){
                fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
                return RESULT_SUCCESS;
        }
@@ -1542,8 +1551,10 @@ static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, i
                }
        }
        /* Notify process */
-       if (pid > -1)
-               kill(pid, SIGHUP);
+       if (pid > -1) {
+               if (kill(pid, SIGHUP))
+                       ast_log(LOG_WARNING, "unable to send SIGHUP to AGI process %d: %s\n", pid, strerror(errno));
+       }
        fclose(readf);
        return returnstatus;
 }