Merge "vector: Add REMOVE, ADD_SORTED and RESET macros"
authorJoshua Colp <jcolp@digium.com>
Tue, 12 May 2015 10:39:08 +0000 (05:39 -0500)
committerGerrit Code Review <gerrit2@gerrit.digium.api>
Tue, 12 May 2015 10:39:08 +0000 (05:39 -0500)
main/dns_srv.c
pbx/pbx_spool.c

index f5d038a..e4a3d8b 100644 (file)
@@ -112,13 +112,15 @@ void dns_srv_sort(struct ast_dns_result *result)
        struct dns_records newlist = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
 
        while (AST_LIST_FIRST(&result->records)) {
-               unsigned short cur_priority = 0;
+               unsigned short cur_priority = ((struct ast_dns_srv_record *)(AST_LIST_FIRST(&result->records)))->priority;
                struct dns_records temp_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
 
-               /* Find the lowest current priority to work on */
-               AST_LIST_TRAVERSE(&result->records, current, list) {
-                       if (!cur_priority || ((struct ast_dns_srv_record *)current)->priority < cur_priority) {
-                               cur_priority = ((struct ast_dns_srv_record *)current)->priority;
+               /* Find the lowest current priority to work on, but if the priority is already zero there is no lower priority */
+               if (cur_priority) {
+                       AST_LIST_TRAVERSE(&result->records, current, list) {
+                               if (((struct ast_dns_srv_record *)current)->priority < cur_priority) {
+                                       cur_priority = ((struct ast_dns_srv_record *)current)->priority;
+                               }
                        }
                }
 
index 0dad606..c858ed2 100644 (file)
@@ -102,6 +102,14 @@ struct outgoing {
 };
 
 #if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
+struct direntry {
+       AST_LIST_ENTRY(direntry) list;
+       time_t mtime;
+       char name[0];
+};
+
+static AST_LIST_HEAD_STATIC(dirlist, direntry);
+
 static void queue_file(const char *filename, time_t when);
 #endif
 
@@ -323,6 +331,10 @@ static int remove_from_queue(struct outgoing *o, const char *status)
        char newfn[256];
        const char *bname;
 
+#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
+       struct direntry *cur;
+#endif
+
        if (!ast_test_flag(&o->options, SPOOL_FLAG_ALWAYS_DELETE)) {
                struct stat current_file_status;
 
@@ -333,6 +345,19 @@ static int remove_from_queue(struct outgoing *o, const char *status)
                }
        }
 
+#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
+       AST_LIST_LOCK(&dirlist);
+       AST_LIST_TRAVERSE_SAFE_BEGIN(&dirlist, cur, list) {
+               if (!strcmp(cur->name, o->fn)) {
+                       AST_LIST_REMOVE_CURRENT(list);
+                       ast_free(cur);
+                       break;
+               }
+       }
+       AST_LIST_TRAVERSE_SAFE_END;
+       AST_LIST_UNLOCK(&dirlist);
+#endif
+
        if (!ast_test_flag(&o->options, SPOOL_FLAG_ARCHIVE)) {
                unlink(o->fn);
                return 0;
@@ -486,14 +511,6 @@ static int scan_service(const char *fn, time_t now)
        return 0;
 }
 
-#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
-struct direntry {
-       AST_LIST_ENTRY(direntry) list;
-       time_t mtime;
-       char name[0];
-};
-
-static AST_LIST_HEAD_STATIC(dirlist, direntry);
 
 #if defined(HAVE_INOTIFY)
 /* Only one thread is accessing this list, so no lock is necessary */
@@ -501,6 +518,8 @@ static AST_LIST_HEAD_NOLOCK_STATIC(createlist, direntry);
 static AST_LIST_HEAD_NOLOCK_STATIC(openlist, direntry);
 #endif
 
+#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
+
 static void queue_file(const char *filename, time_t when)
 {
        struct stat st;