Skip to content
Snippets Groups Projects
Commit 952faabb authored by Martin Pycko's avatar Martin Pycko
Browse files

Make AGI work when ast_waitfor_nands returns without anything because of EINTR

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1699 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent b5ec8ef1
Branches
Tags
No related merge requests found
...@@ -1218,7 +1218,7 @@ static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf) ...@@ -1218,7 +1218,7 @@ static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf)
} }
return 0; return 0;
} }
#define RETRY 3
static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid) static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid)
{ {
struct ast_channel *c; struct ast_channel *c;
...@@ -1228,6 +1228,9 @@ static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid) ...@@ -1228,6 +1228,9 @@ static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid)
struct ast_frame *f; struct ast_frame *f;
char buf[2048]; char buf[2048];
FILE *readf; FILE *readf;
//how many times we'll retry if ast_waitfor_nandfs will return without either channel or file descriptor in case select is interrupted by a system call (EINTR)
int retry = RETRY;
if (!(readf = fdopen(agi->ctrl, "r"))) { if (!(readf = fdopen(agi->ctrl, "r"))) {
ast_log(LOG_WARNING, "Unable to fdopen file descriptor\n"); ast_log(LOG_WARNING, "Unable to fdopen file descriptor\n");
kill(pid, SIGHUP); kill(pid, SIGHUP);
...@@ -1239,6 +1242,7 @@ static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid) ...@@ -1239,6 +1242,7 @@ static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid)
ms = -1; ms = -1;
c = ast_waitfor_nandfds(&chan, 1, &agi->ctrl, 1, NULL, &outfd, &ms); c = ast_waitfor_nandfds(&chan, 1, &agi->ctrl, 1, NULL, &outfd, &ms);
if (c) { if (c) {
retry = RETRY;
/* Idle the channel until we get a command */ /* Idle the channel until we get a command */
f = ast_read(c); f = ast_read(c);
if (!f) { if (!f) {
...@@ -1254,6 +1258,7 @@ static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid) ...@@ -1254,6 +1258,7 @@ static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid)
ast_frfree(f); ast_frfree(f);
} }
} else if (outfd > -1) { } else if (outfd > -1) {
retry = RETRY;
if (!fgets(buf, sizeof(buf), readf)) { if (!fgets(buf, sizeof(buf), readf)) {
/* Program terminated */ /* Program terminated */
if (returnstatus) if (returnstatus)
...@@ -1274,9 +1279,11 @@ static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid) ...@@ -1274,9 +1279,11 @@ static int run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid)
break; break;
} }
} else { } else {
ast_log(LOG_WARNING, "No channel, no fd?\n"); if (--retry <= 0) {
returnstatus = -1; ast_log(LOG_WARNING, "No channel, no fd?\n");
break; returnstatus = -1;
break;
}
} }
} }
/* Notify process */ /* Notify process */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment