aboutsummaryrefslogtreecommitdiffstats
path: root/pbx
diff options
context:
space:
mode:
author(no author) <(no author)@f38db490-d61c-443f-a65b-d21fe96a405b>2004-04-13 04:46:23 +0000
committer(no author) <(no author)@f38db490-d61c-443f-a65b-d21fe96a405b>2004-04-13 04:46:23 +0000
commitd46468f42c6762ce7646e773c7d0919ed1f626d4 (patch)
tree5d62a34385385b3485137835b2629174ca0464cf /pbx
parentf38bc8131c9eda8d0b0eabaafbaa53f4247989c4 (diff)
This commit was manufactured by cvs2svn to create tag 'v0_9_0'.
git-svn-id: http://svn.digium.com/svn/asterisk/tags/v0_9_0@2684 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx')
-rwxr-xr-xpbx/pbx_config.c2
-rwxr-xr-xpbx/pbx_spool.c63
2 files changed, 51 insertions, 14 deletions
diff --git a/pbx/pbx_config.c b/pbx/pbx_config.c
index e017be79c..be87fff1c 100755
--- a/pbx/pbx_config.c
+++ b/pbx/pbx_config.c
@@ -1576,7 +1576,7 @@ static int pbx_load_module(void)
}
cxt = ast_category_browse(cfg, NULL);
while(cxt) {
- /* All categories but "general" are considered contexts */
+ /* All categories but "general" or "globals" are considered contexts */
if (!strcasecmp(cxt, "general") || !strcasecmp(cxt, "globals")) {
cxt = ast_category_browse(cfg, cxt);
continue;
diff --git a/pbx/pbx_spool.c b/pbx/pbx_spool.c
index d456810bb..d5e2b960f 100755
--- a/pbx/pbx_spool.c
+++ b/pbx/pbx_spool.c
@@ -50,6 +50,8 @@ struct outgoing {
int retrytime;
/* How long to wait for an answer */
int waittime;
+ /* PID which is currently calling */
+ int callingpid;
/* What to connect to outgoing */
char tech[256];
@@ -157,6 +159,14 @@ static int apply_outgoing(struct outgoing *o, char *fn, FILE *f)
}
} else if (!strcasecmp(buf, "retry")) {
o->retries++;
+ } else if (!strcasecmp(buf, "startretry")) {
+ if (sscanf(c, "%d", &o->callingpid) != 1) {
+ ast_log(LOG_WARNING, "Unable to retrieve calling PID!\n");
+ o->callingpid = 0;
+ }
+ } else if (!strcasecmp(buf, "endretry") || !strcasecmp(buf, "abortretry")) {
+ o->callingpid = 0;
+ o->retries++;
} else if (!strcasecmp(buf, "setvar")) { /* JDG variable support */
strncat(o->variable, c, sizeof(o->variable) - strlen(o->variable) - 1);
strncat(o->variable, "|", sizeof(o->variable) - strlen(o->variable) - 1);
@@ -182,6 +192,21 @@ static int apply_outgoing(struct outgoing *o, char *fn, FILE *f)
return 0;
}
+static void safe_append(struct outgoing *o, time_t now, char *s)
+{
+ int fd;
+ FILE *f;
+ fd = open(o->fn, O_WRONLY|O_APPEND);
+ if (fd > -1) {
+ f = fdopen(fd, "a");
+ if (f) {
+ fprintf(f, "%s: %d (%ld) (%ld)\n", s, o->retries, (long)ast_mainpid, (long) now);
+ fclose(f);
+ } else
+ close(fd);
+ }
+}
+
static void *attempt_thread(void *data)
{
struct outgoing *o = data;
@@ -201,6 +226,9 @@ static void *attempt_thread(void *data)
/* Max retries exceeded */
ast_log(LOG_EVENT, "Queued call to %s/%s expired without completion after %d attempt(s)\n", o->tech, o->dest, o->retries - 1);
unlink(o->fn);
+ } else {
+ /* Notate that the call is still active */
+ safe_append(o, time(NULL), "EndRetry");
}
} else {
ast_log(LOG_NOTICE, "Call completed to %s/%s\n", o->tech, o->dest);
@@ -234,23 +262,32 @@ static int scan_service(char *fn, time_t now, time_t atime)
f = fopen(fn, "r+");
if (f) {
if (!apply_outgoing(o, fn, f)) {
- /* Update the file time */
- tbuf.actime = atime;
- tbuf.modtime = now + o->retrytime;
- if (utime(o->fn, &tbuf))
- ast_log(LOG_WARNING, "Unable to set utime on %s: %s\n", fn, strerror(errno));
- /* Increment retries */
- o->retries++;
#if 0
printf("Retries: %d, max: %d\n", o->retries, o->maxretries);
#endif
- if (o->retries <= o->maxretries + 1) {
- /* Add a retry line at the end */
- fseek(f, 0L, SEEK_END);
- fprintf(f, "Retry: %d (%ld)\n", o->retries, (long) now);
- fclose(f);
+ if (o->retries <= o->maxretries) {
+ if (o->callingpid && (o->callingpid == ast_mainpid)) {
+ ast_log(LOG_DEBUG, "Delaying retry since we're currently running '%s'\n", o->fn);
+ } else {
+ /* Increment retries */
+ o->retries++;
+ /* If someone else was calling, they're presumably gone now
+ so abort their retry and continue as we were... */
+ if (o->callingpid)
+ safe_append(o, time(NULL), "AbortRetry");
+
+ /* Add a retry line at the end */
+ fseek(f, 0L, SEEK_END);
+ fprintf(f, "StartRetry: %d %d (%ld)\n", ast_mainpid, o->retries, (long) now);
+ fclose(f);
+ launch_service(o);
+ }
+ /* Update the file time */
+ tbuf.actime = atime;
+ tbuf.modtime = now + o->retrytime;
+ if (utime(o->fn, &tbuf))
+ ast_log(LOG_WARNING, "Unable to set utime on %s: %s\n", fn, strerror(errno));
now += o->retrytime;
- launch_service(o);
return now;
} else {
ast_log(LOG_EVENT, "Queued call to %s/%s expired without completion after %d attempt(s)\n", o->tech, o->dest, o->retries - 1);