Merged revisions 80360 via svnmerge from
authorRussell Bryant <russell@russellbryant.com>
Wed, 22 Aug 2007 19:54:52 +0000 (19:54 +0000)
committerRussell Bryant <russell@russellbryant.com>
Wed, 22 Aug 2007 19:54:52 +0000 (19:54 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r80360 | russell | 2007-08-22 14:53:30 -0500 (Wed, 22 Aug 2007) | 5 lines

Juggie in #asterisk-dev was reporting problems where fgets would return
without reading  the whole line when using fastagi.  When this happens,
errno was set to EINTR or EAGAIN.  This patch accounts for the possibility
and lets fgets continue in that case.

........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@80361 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/res_agi.c

index 076c7e3..fffbc93 100644 (file)
@@ -1902,8 +1902,14 @@ static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi
                                ast_frfree(f);
                        }
                } else if (outfd > -1) {
                                ast_frfree(f);
                        }
                } else if (outfd > -1) {
+                       size_t len;
                        retry = RETRY;
                        retry = RETRY;
-                       if (!fgets(buf, sizeof(buf), readf)) {
+                       buf[0] = '\0';
+retry_fgets:
+                       len = strlen(buf);
+                       if (!fgets(buf + len, sizeof(buf) - len, readf)) {
+                               if (!feof(readf) && (errno == EINTR || errno == EAGAIN))
+                                       goto retry_fgets;
                                /* Program terminated */
                                if (returnstatus && returnstatus != AST_PBX_KEEPALIVE)
                                        returnstatus = -1;
                                /* Program terminated */
                                if (returnstatus && returnstatus != AST_PBX_KEEPALIVE)
                                        returnstatus = -1;
@@ -1914,6 +1920,8 @@ static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi
                                pid = -1;
                                break;
                        }
                                pid = -1;
                                break;
                        }
+                       if (errno == EINTR || errno == EAGAIN)
+                               goto retry_fgets;
                        /* get rid of trailing newline, if any */
                        if (*buf && buf[strlen(buf) - 1] == '\n')
                                buf[strlen(buf) - 1] = 0;
                        /* get rid of trailing newline, if any */
                        if (*buf && buf[strlen(buf) - 1] == '\n')
                                buf[strlen(buf) - 1] = 0;