2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2010, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Full-featured outgoing call spool support
26 <support_level>core</support_level>
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
38 #include <sys/inotify.h>
39 #elif defined(HAVE_KQUEUE)
40 #include <sys/types.h>
42 #include <sys/event.h>
46 #include "asterisk/paths.h" /* use ast_config_AST_SPOOL_DIR */
47 #include "asterisk/lock.h"
48 #include "asterisk/file.h"
49 #include "asterisk/logger.h"
50 #include "asterisk/channel.h"
51 #include "asterisk/callerid.h"
52 #include "asterisk/pbx.h"
53 #include "asterisk/module.h"
54 #include "asterisk/utils.h"
55 #include "asterisk/options.h"
58 * pbx_spool is similar in spirit to qcall, but with substantially enhanced functionality...
59 * The spool file contains a header
63 /*! Always delete the call file after a call succeeds or the
64 * maximum number of retries is exceeded, even if the
65 * modification time of the call file is in the future.
67 SPOOL_FLAG_ALWAYS_DELETE = (1 << 0),
68 /* Don't unlink the call file after processing, move in qdonedir */
69 SPOOL_FLAG_ARCHIVE = (1 << 1),
72 static char qdir[255];
73 static char qdonedir[255];
76 int retries; /*!< Current number of retries */
77 int maxretries; /*!< Maximum number of retries permitted */
78 int retrytime; /*!< How long to wait between retries (in seconds) */
79 int waittime; /*!< How long to wait for an answer */
80 long callingpid; /*!< PID which is currently calling */
81 struct ast_format_cap *capabilities; /*!< Formats (codecs) for this call */
82 AST_DECLARE_STRING_FIELDS (
83 AST_STRING_FIELD(fn); /*!< File name of call file */
84 AST_STRING_FIELD(tech); /*!< Which channel technology to use for outgoing call */
85 AST_STRING_FIELD(dest); /*!< Which device/line to use for outgoing call */
86 AST_STRING_FIELD(app); /*!< If application: Application name */
87 AST_STRING_FIELD(data); /*!< If application: Application data */
88 AST_STRING_FIELD(exten); /*!< If extension/context/priority: Extension in dialplan */
89 AST_STRING_FIELD(context); /*!< If extension/context/priority: Dialplan context */
90 AST_STRING_FIELD(cid_num); /*!< CallerID Information: Number/extension */
91 AST_STRING_FIELD(cid_name); /*!< CallerID Information: Name */
92 AST_STRING_FIELD(account); /*!< account code */
94 int priority; /*!< If extension/context/priority: Dialplan priority */
95 struct ast_variable *vars; /*!< Variables and Functions */
96 int maxlen; /*!< Maximum length of call */
97 struct ast_flags options; /*!< options */
100 #if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
101 static void queue_file(const char *filename, time_t when);
104 static int init_outgoing(struct outgoing *o)
106 struct ast_format tmpfmt;
111 if (!(o->capabilities = ast_format_cap_alloc_nolock())) {
114 ast_format_cap_add(o->capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
116 ast_set_flag(&o->options, SPOOL_FLAG_ALWAYS_DELETE);
117 if (ast_string_field_init(o, 128)) {
123 static void free_outgoing(struct outgoing *o)
126 ast_variables_destroy(o->vars);
128 ast_string_field_free_memory(o);
129 o->capabilities = ast_format_cap_destroy(o->capabilities);
133 static int apply_outgoing(struct outgoing *o, const char *fn, FILE *f)
138 struct ast_variable *var, *last = o->vars;
140 while (last && last->next) {
144 while(fgets(buf, sizeof(buf), f)) {
148 while ((c = strchr(c, '#'))) {
149 if ((c == buf) || (*(c-1) == ' ') || (*(c-1) == '\t'))
156 while ((c = strchr(c, ';'))) {
157 if ((c > buf) && (c[-1] == '\\')) {
158 memmove(c - 1, c, strlen(c) + 1);
166 /* Trim trailing white space */
167 while(!ast_strlen_zero(buf) && buf[strlen(buf) - 1] < 33)
168 buf[strlen(buf) - 1] = '\0';
169 if (!ast_strlen_zero(buf)) {
170 c = strchr(buf, ':');
174 while ((*c) && (*c < 33))
177 printf("'%s' is '%s' at line %d\n", buf, c, lineno);
179 if (!strcasecmp(buf, "channel")) {
180 if ((c2 = strchr(c, '/'))) {
183 ast_string_field_set(o, tech, c);
184 ast_string_field_set(o, dest, c2);
186 ast_log(LOG_NOTICE, "Channel should be in form Tech/Dest at line %d of %s\n", lineno, fn);
188 } else if (!strcasecmp(buf, "callerid")) {
189 char cid_name[80] = {0}, cid_num[80] = {0};
190 ast_callerid_split(c, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
191 ast_string_field_set(o, cid_num, cid_num);
192 ast_string_field_set(o, cid_name, cid_name);
193 } else if (!strcasecmp(buf, "application")) {
194 ast_string_field_set(o, app, c);
195 } else if (!strcasecmp(buf, "data")) {
196 ast_string_field_set(o, data, c);
197 } else if (!strcasecmp(buf, "maxretries")) {
198 if (sscanf(c, "%30d", &o->maxretries) != 1) {
199 ast_log(LOG_WARNING, "Invalid max retries at line %d of %s\n", lineno, fn);
202 } else if (!strcasecmp(buf, "codecs")) {
203 ast_parse_allow_disallow(NULL, o->capabilities, c, 1);
204 } else if (!strcasecmp(buf, "context")) {
205 ast_string_field_set(o, context, c);
206 } else if (!strcasecmp(buf, "extension")) {
207 ast_string_field_set(o, exten, c);
208 } else if (!strcasecmp(buf, "priority")) {
209 if ((sscanf(c, "%30d", &o->priority) != 1) || (o->priority < 1)) {
210 ast_log(LOG_WARNING, "Invalid priority at line %d of %s\n", lineno, fn);
213 } else if (!strcasecmp(buf, "retrytime")) {
214 if ((sscanf(c, "%30d", &o->retrytime) != 1) || (o->retrytime < 1)) {
215 ast_log(LOG_WARNING, "Invalid retrytime at line %d of %s\n", lineno, fn);
218 } else if (!strcasecmp(buf, "waittime")) {
219 if ((sscanf(c, "%30d", &o->waittime) != 1) || (o->waittime < 1)) {
220 ast_log(LOG_WARNING, "Invalid waittime at line %d of %s\n", lineno, fn);
223 } else if (!strcasecmp(buf, "retry")) {
225 } else if (!strcasecmp(buf, "startretry")) {
226 if (sscanf(c, "%30ld", &o->callingpid) != 1) {
227 ast_log(LOG_WARNING, "Unable to retrieve calling PID!\n");
230 } else if (!strcasecmp(buf, "endretry") || !strcasecmp(buf, "abortretry")) {
233 } else if (!strcasecmp(buf, "delayedretry")) {
234 } else if (!strcasecmp(buf, "setvar") || !strcasecmp(buf, "set")) {
238 var = ast_variable_new(c, c2, fn);
240 /* Always insert at the end, because some people want to treat the spool file as a script */
249 ast_log(LOG_WARNING, "Malformed \"%s\" argument. Should be \"%s: variable=value\"\n", buf, buf);
250 } else if (!strcasecmp(buf, "account")) {
251 ast_string_field_set(o, account, c);
252 } else if (!strcasecmp(buf, "alwaysdelete")) {
253 ast_set2_flag(&o->options, ast_true(c), SPOOL_FLAG_ALWAYS_DELETE);
254 } else if (!strcasecmp(buf, "archive")) {
255 ast_set2_flag(&o->options, ast_true(c), SPOOL_FLAG_ARCHIVE);
257 ast_log(LOG_WARNING, "Unknown keyword '%s' at line %d of %s\n", buf, lineno, fn);
260 ast_log(LOG_NOTICE, "Syntax error at line %d of %s\n", lineno, fn);
263 ast_string_field_set(o, fn, fn);
264 if (ast_strlen_zero(o->tech) || ast_strlen_zero(o->dest) || (ast_strlen_zero(o->app) && ast_strlen_zero(o->exten))) {
265 ast_log(LOG_WARNING, "At least one of app or extension must be specified, along with tech and dest in file %s\n", fn);
271 static void safe_append(struct outgoing *o, time_t now, char *s)
274 struct utimbuf tbuf = { .actime = now, .modtime = now + o->retrytime };
276 ast_debug(1, "Outgoing %s/%s: %s\n", o->tech, o->dest, s);
278 if ((f = fopen(o->fn, "a"))) {
279 fprintf(f, "\n%s: %ld %d (%ld)\n", s, (long)ast_mainpid, o->retries, (long) now);
283 /* Update the file time */
284 if (utime(o->fn, &tbuf)) {
285 ast_log(LOG_WARNING, "Unable to set utime on %s: %s\n", o->fn, strerror(errno));
290 * \brief Remove a call file from the outgoing queue optionally moving it in the archive dir
292 * \param o the pointer to outgoing struct
293 * \param status the exit status of the call. Can be "Completed", "Failed" or "Expired"
295 static int remove_from_queue(struct outgoing *o, const char *status)
301 if (!ast_test_flag(&o->options, SPOOL_FLAG_ALWAYS_DELETE)) {
302 struct stat current_file_status;
304 if (!stat(o->fn, ¤t_file_status)) {
305 if (time(NULL) < current_file_status.st_mtime) {
311 if (!ast_test_flag(&o->options, SPOOL_FLAG_ARCHIVE)) {
316 if (ast_mkdir(qdonedir, 0777)) {
317 ast_log(LOG_WARNING, "Unable to create queue directory %s -- outgoing spool archiving disabled\n", qdonedir);
322 if (!(bname = strrchr(o->fn, '/'))) {
328 snprintf(newfn, sizeof(newfn), "%s/%s", qdonedir, bname);
329 /* a existing call file the archive dir is overwritten */
331 if (rename(o->fn, newfn) != 0) {
336 /* Only append to the file AFTER we move it out of the watched directory,
337 * otherwise the fclose() causes another event for inotify(7) */
338 if ((f = fopen(newfn, "a"))) {
339 fprintf(f, "Status: %s\n", status);
346 static void *attempt_thread(void *data)
348 struct outgoing *o = data;
350 if (!ast_strlen_zero(o->app)) {
351 ast_verb(3, "Attempting call on %s/%s for application %s(%s) (Retry %d)\n", o->tech, o->dest, o->app, o->data, o->retries);
352 res = ast_pbx_outgoing_app(o->tech, o->capabilities, o->dest, o->waittime * 1000,
353 o->app, o->data, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name,
354 o->vars, o->account, NULL);
357 ast_verb(3, "Attempting call on %s/%s for %s@%s:%d (Retry %d)\n", o->tech, o->dest, o->exten, o->context,o->priority, o->retries);
358 res = ast_pbx_outgoing_exten(o->tech, o->capabilities, o->dest,
359 o->waittime * 1000, o->context, o->exten, o->priority, &reason,
360 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL);
364 ast_log(LOG_NOTICE, "Call failed to go through, reason (%d) %s\n", reason, ast_channel_reason2str(reason));
365 if (o->retries >= o->maxretries + 1) {
366 /* Max retries exceeded */
367 ast_log(LOG_NOTICE, "Queued call to %s/%s expired without completion after %d attempt%s\n", o->tech, o->dest, o->retries - 1, ((o->retries - 1) != 1) ? "s" : "");
368 remove_from_queue(o, "Expired");
370 /* Notate that the call is still active */
371 safe_append(o, time(NULL), "EndRetry");
372 #if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
373 queue_file(o->fn, time(NULL) + o->retrytime);
377 ast_log(LOG_NOTICE, "Call completed to %s/%s\n", o->tech, o->dest);
378 remove_from_queue(o, "Completed");
384 static void launch_service(struct outgoing *o)
389 if ((ret = ast_pthread_create_detached(&t, NULL, attempt_thread, o))) {
390 ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
395 /* Called from scan_thread or queue_file */
396 static int scan_service(const char *fn, time_t now)
398 struct outgoing *o = NULL;
402 if (!(o = ast_calloc(1, sizeof(*o)))) {
403 ast_log(LOG_WARNING, "Out of memory ;(\n");
407 if (init_outgoing(o)) {
408 /* No need to call free_outgoing here since we know the failure
409 * was to allocate string fields and no variables have been allocated
416 /* Attempt to open the file */
417 if (!(f = fopen(fn, "r"))) {
418 remove_from_queue(o, "Failed");
420 #if !defined(HAVE_INOTIFY) && !defined(HAVE_KQUEUE)
421 ast_log(LOG_WARNING, "Unable to open %s: %s, deleting\n", fn, strerror(errno));
426 /* Read in and verify the contents */
427 if (apply_outgoing(o, fn, f)) {
428 remove_from_queue(o, "Failed");
430 ast_log(LOG_WARNING, "Invalid file contents in %s, deleting\n", fn);
436 printf("Filename: %s, Retries: %d, max: %d\n", fn, o->retries, o->maxretries);
439 if (o->retries <= o->maxretries) {
441 if (o->callingpid && (o->callingpid == ast_mainpid)) {
442 safe_append(o, time(NULL), "DelayedRetry");
443 ast_debug(1, "Delaying retry since we're currently running '%s'\n", o->fn);
446 /* Increment retries */
448 /* If someone else was calling, they're presumably gone now
449 so abort their retry and continue as we were... */
451 safe_append(o, time(NULL), "AbortRetry");
453 safe_append(o, now, "StartRetry");
458 ast_log(LOG_NOTICE, "Queued call to %s/%s expired without completion after %d attempt%s\n", o->tech, o->dest, o->retries - 1, ((o->retries - 1) != 1) ? "s" : "");
459 remove_from_queue(o, "Expired");
466 #if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
468 AST_LIST_ENTRY(direntry) list;
473 static AST_LIST_HEAD_STATIC(dirlist, direntry);
475 #if defined(HAVE_INOTIFY)
476 /* Only one thread is accessing this list, so no lock is necessary */
477 static AST_LIST_HEAD_NOLOCK_STATIC(createlist, direntry);
478 static AST_LIST_HEAD_NOLOCK_STATIC(openlist, direntry);
481 static void queue_file(const char *filename, time_t when)
484 struct direntry *cur, *new;
486 time_t now = time(NULL);
488 if (filename[0] != '/') {
489 char *fn = alloca(strlen(qdir) + strlen(filename) + 2);
490 sprintf(fn, "%s/%s", qdir, filename); /* SAFE */
495 if (stat(filename, &st)) {
496 ast_log(LOG_WARNING, "Unable to stat %s: %s\n", filename, strerror(errno));
500 if (!S_ISREG(st.st_mode)) {
507 /* Need to check the existing list in order to avoid duplicates. */
508 AST_LIST_LOCK(&dirlist);
509 AST_LIST_TRAVERSE(&dirlist, cur, list) {
510 if (cur->mtime == when && !strcmp(filename, cur->name)) {
511 AST_LIST_UNLOCK(&dirlist);
516 if ((res = when) > now || (res = scan_service(filename, now)) > 0) {
517 if (!(new = ast_calloc(1, sizeof(*new) + strlen(filename) + 1))) {
518 AST_LIST_UNLOCK(&dirlist);
522 strcpy(new->name, filename);
523 /* List is ordered by mtime */
524 if (AST_LIST_EMPTY(&dirlist)) {
525 AST_LIST_INSERT_HEAD(&dirlist, new, list);
528 AST_LIST_TRAVERSE_SAFE_BEGIN(&dirlist, cur, list) {
529 if (cur->mtime > new->mtime) {
530 AST_LIST_INSERT_BEFORE_CURRENT(new, list);
535 AST_LIST_TRAVERSE_SAFE_END
537 AST_LIST_INSERT_TAIL(&dirlist, new, list);
541 AST_LIST_UNLOCK(&dirlist);
545 static void queue_file_create(const char *filename)
547 struct direntry *cur;
549 AST_LIST_TRAVERSE(&createlist, cur, list) {
550 if (!strcmp(cur->name, filename)) {
555 if (!(cur = ast_calloc(1, sizeof(*cur) + strlen(filename) + 1))) {
558 strcpy(cur->name, filename);
559 /* We'll handle this file unless an IN_OPEN event occurs within 2 seconds */
560 cur->mtime = time(NULL) + 2;
561 AST_LIST_INSERT_TAIL(&createlist, cur, list);
564 static void queue_file_open(const char *filename)
566 struct direntry *cur;
568 AST_LIST_TRAVERSE_SAFE_BEGIN(&createlist, cur, list) {
569 if (!strcmp(cur->name, filename)) {
570 AST_LIST_REMOVE_CURRENT(list);
571 AST_LIST_INSERT_TAIL(&openlist, cur, list);
575 AST_LIST_TRAVERSE_SAFE_END
578 static void queue_created_files(void)
580 struct direntry *cur;
581 time_t now = time(NULL);
583 AST_LIST_TRAVERSE_SAFE_BEGIN(&createlist, cur, list) {
584 if (cur->mtime > now) {
588 AST_LIST_REMOVE_CURRENT(list);
589 queue_file(cur->name, 0);
592 AST_LIST_TRAVERSE_SAFE_END
595 static void queue_file_write(const char *filename)
597 struct direntry *cur;
598 /* Only queue entries where an IN_CREATE preceded the IN_CLOSE_WRITE */
599 AST_LIST_TRAVERSE_SAFE_BEGIN(&openlist, cur, list) {
600 if (!strcmp(cur->name, filename)) {
601 AST_LIST_REMOVE_CURRENT(list);
603 queue_file(filename, 0);
607 AST_LIST_TRAVERSE_SAFE_END
611 static void *scan_thread(void *unused)
616 struct timespec ts = { .tv_sec = 1 };
619 int inotify_fd = inotify_init();
620 struct inotify_event *iev;
621 char buf[8192] __attribute__((aligned (sizeof(int))));
622 struct pollfd pfd = { .fd = inotify_fd, .events = POLLIN };
624 struct timespec nowait = { 0, 1 };
625 int inotify_fd = kqueue();
628 struct direntry *cur;
630 while (!ast_fully_booted) {
631 nanosleep(&ts, NULL);
634 if (inotify_fd < 0) {
635 ast_log(LOG_ERROR, "Unable to initialize "
646 inotify_add_watch(inotify_fd, qdir, IN_CREATE | IN_OPEN | IN_CLOSE_WRITE | IN_MOVED_TO);
649 /* First, run through the directory and clear existing entries */
650 if (!(dir = opendir(qdir))) {
651 ast_log(LOG_ERROR, "Unable to open directory %s: %s\n", qdir, strerror(errno));
656 EV_SET(&kev, dirfd(dir), EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_WRITE, 0, NULL);
657 if (kevent(inotify_fd, &kev, 1, NULL, 0, &nowait) < 0 && errno != 0) {
658 ast_log(LOG_ERROR, "Unable to watch directory %s: %s\n", qdir, strerror(errno));
662 while ((de = readdir(dir))) {
663 queue_file(de->d_name, 0);
667 /* Directory needs to remain open for kqueue(2) */
671 /* Wait for either a) next timestamp to occur, or b) a change to happen */
673 time_t next = AST_LIST_EMPTY(&dirlist) ? INT_MAX : AST_LIST_FIRST(&dirlist)->mtime;
679 /* Convert from seconds to milliseconds, unless there's nothing
680 * in the queue already, in which case, we wait forever. */
681 int waittime = next == INT_MAX ? -1 : (next - now) * 1000;
682 if (!AST_LIST_EMPTY(&createlist)) {
685 /* When a file arrives, add it to the queue, in mtime order. */
686 if ((res = poll(&pfd, 1, waittime)) > 0 && (stage = 1) &&
687 (res = read(inotify_fd, &buf, sizeof(buf))) >= sizeof(*iev)) {
689 /* File(s) added to directory, add them to my list */
690 for (iev = (void *) buf; res >= sizeof(*iev); iev = (struct inotify_event *) (((char *) iev) + len)) {
691 /* For an IN_MOVED_TO event, simply process the file. However, if
692 * we get an IN_CREATE event it *might* be an open(O_CREAT) or it
693 * might be a hardlink (like smsq does, since rename() might
694 * overwrite an existing file). So we have to see if we get a
695 * subsequent IN_OPEN event on the same file. If we do, keep it
696 * on the openlist and wait for the corresponding IN_CLOSE_WRITE.
697 * If we *don't* see an IN_OPEN event, then it was a hard link so
698 * it can be processed immediately.
700 * Unfortunately, although open(O_CREAT) is an atomic file system
701 * operation, the inotify subsystem doesn't give it to us in a
702 * single event with both IN_CREATE|IN_OPEN set. It's two separate
703 * events, and the kernel doesn't even give them to us at the same
704 * time. We can read() from inotify_fd after the IN_CREATE event,
705 * and get *nothing* from it. The IN_OPEN arrives only later! So
706 * we have a very short timeout of 2 seconds. */
707 if (iev->mask & IN_CREATE) {
708 queue_file_create(iev->name);
709 } else if (iev->mask & IN_OPEN) {
710 queue_file_open(iev->name);
711 } else if (iev->mask & IN_CLOSE_WRITE) {
712 queue_file_write(iev->name);
713 } else if (iev->mask & IN_MOVED_TO) {
714 queue_file(iev->name, 0);
716 ast_log(LOG_ERROR, "Unexpected event %d for file '%s'\n", (int) iev->mask, iev->name);
719 len = sizeof(*iev) + iev->len;
722 } else if (res < 0 && errno != EINTR && errno != EAGAIN) {
723 ast_debug(1, "Got an error back from %s(2): %s\n", stage ? "read" : "poll", strerror(errno));
727 queue_created_files();
729 struct timespec ts2 = { next - now, 0 };
730 if (kevent(inotify_fd, NULL, 0, &kev, 1, &ts2) <= 0) {
731 /* Interrupt or timeout, restart calculations */
734 /* Directory changed, rescan */
736 while ((de = readdir(dir))) {
737 queue_file(de->d_name, 0);
744 /* Empty the list of all entries ready to be processed */
745 AST_LIST_LOCK(&dirlist);
746 while (!AST_LIST_EMPTY(&dirlist) && AST_LIST_FIRST(&dirlist)->mtime <= now) {
747 cur = AST_LIST_REMOVE_HEAD(&dirlist, list);
748 queue_file(cur->name, cur->mtime);
751 AST_LIST_UNLOCK(&dirlist);
757 static void *scan_thread(void *unused)
764 time_t last = 0, next = 0, now;
765 struct timespec ts = { .tv_sec = 1 };
767 while (!ast_fully_booted) {
768 nanosleep(&ts, NULL);
773 nanosleep(&ts, NULL);
776 if (stat(qdir, &st)) {
777 ast_log(LOG_WARNING, "Unable to stat %s\n", qdir);
781 /* Make sure it is time for us to execute our check */
782 if ((st.st_mtime == last) && (next && (next > now)))
786 printf("atime: %ld, mtime: %ld, ctime: %ld\n", st.st_atime, st.st_mtime, st.st_ctime);
787 printf("Ooh, something changed / timeout\n");
792 if (!(dir = opendir(qdir))) {
793 ast_log(LOG_WARNING, "Unable to open directory %s: %s\n", qdir, strerror(errno));
797 while ((de = readdir(dir))) {
798 snprintf(fn, sizeof(fn), "%s/%s", qdir, de->d_name);
800 ast_log(LOG_WARNING, "Unable to stat %s: %s\n", fn, strerror(errno));
803 if (!S_ISREG(st.st_mode))
805 if (st.st_mtime <= now) {
806 res = scan_service(fn, now);
808 /* Update next service time */
809 if (!next || (res < next)) {
813 ast_log(LOG_WARNING, "Failed to scan service '%s'\n", fn);
815 /* Expired entry: must recheck on the next go-around */
819 /* Update "next" update if necessary */
820 if (!next || (st.st_mtime < next))
830 static int unload_module(void)
835 static int load_module(void)
839 snprintf(qdir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "outgoing");
840 if (ast_mkdir(qdir, 0777)) {
841 ast_log(LOG_WARNING, "Unable to create queue directory %s -- outgoing spool disabled\n", qdir);
842 return AST_MODULE_LOAD_DECLINE;
844 snprintf(qdonedir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "outgoing_done");
846 if ((ret = ast_pthread_create_detached_background(&thread, NULL, scan_thread, NULL))) {
847 ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
848 return AST_MODULE_LOAD_FAILURE;
851 return AST_MODULE_LOAD_SUCCESS;
854 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Outgoing Spool Support");