Fix Segfault In app_queue When "persistentmembers" Is Enabled And Using Realtime
authorMichael L. Young <elgueromexicano@gmail.com>
Thu, 9 May 2013 03:35:25 +0000 (03:35 +0000)
committerMichael L. Young <elgueromexicano@gmail.com>
Thu, 9 May 2013 03:35:25 +0000 (03:35 +0000)
When the "ignorebusy" setting was deprecated, we added some code to allow us to
be compatible with older setups that are still using the "ignorebusy" setting
instead of "ringinuse".  We set a char *variable with the column name to use,
which helps the realtime functions to use the correct column in their SQL
queries.  When "persistentmembers" is enabled, we are not setting this variable
before the realtime functions were called to load members.  This results in the
variable being NULL and therefore causing a segfault when loading members during
the module's process of loading.

The solution was to move the code that sets that variable to be before these
realtime functions are called during the loading of the module.

(closes issue ASTERISK-21738)
Reported by: JoshE
Tested by: JoshE
Patches:
    asterisk-21738-rt-ringinuse-field-not-set.diff
                                     uploaded by Michael L. Young (license 5026)

Review: https://reviewboard.asterisk.org/r/2499/
........

Merged revisions 388108 from http://svn.asterisk.org/svn/asterisk/branches/11

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

apps/app_queue.c

index 887f8f0..3455cc7 100644 (file)
@@ -9906,6 +9906,31 @@ static int load_module(void)
        if (reload_handler(0, &mask, NULL))
                return AST_MODULE_LOAD_DECLINE;
 
        if (reload_handler(0, &mask, NULL))
                return AST_MODULE_LOAD_DECLINE;
 
+       ast_realtime_require_field("queue_members", "paused", RQ_INTEGER1, 1, "uniqueid", RQ_UINTEGER2, 5, SENTINEL);
+
+       /*
+        * This section is used to determine which name for 'ringinuse' to use in realtime members
+        * Necessary for supporting older setups.
+        */
+       member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name LIKE", "%", SENTINEL);
+       if (!member_config) {
+               realtime_ringinuse_field = "ringinuse";
+       } else {
+               const char *config_val;
+               if ((config_val = ast_variable_retrieve(member_config, NULL, "ringinuse"))) {
+                       ast_log(LOG_NOTICE, "ringinuse field entries found in queue_members table. Using 'ringinuse'\n");
+                       realtime_ringinuse_field = "ringinuse";
+               } else if ((config_val = ast_variable_retrieve(member_config, NULL, "ignorebusy"))) {
+                       ast_log(LOG_NOTICE, "ignorebusy field found in queue_members table with no ringinuse field. Using 'ignorebusy'\n");
+                       realtime_ringinuse_field = "ignorebusy";
+               } else {
+                       ast_log(LOG_NOTICE, "No entries were found for ringinuse/ignorebusy in queue_members table. Using 'ringinuse'\n");
+                       realtime_ringinuse_field = "ringinuse";
+               }
+       }
+
+       ast_config_destroy(member_config);
+
        if (queue_persistent_members)
                reload_queue_members();
 
        if (queue_persistent_members)
                reload_queue_members();
 
@@ -9945,31 +9970,6 @@ static int load_module(void)
 
        ast_extension_state_add(NULL, NULL, extension_state_cb, NULL);
 
 
        ast_extension_state_add(NULL, NULL, extension_state_cb, NULL);
 
-       ast_realtime_require_field("queue_members", "paused", RQ_INTEGER1, 1, "uniqueid", RQ_UINTEGER2, 5, SENTINEL);
-
-       /*
-        * This section is used to determine which name for 'ringinuse' to use in realtime members
-        * Necessary for supporting older setups.
-        */
-       member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name LIKE", "%", SENTINEL);
-       if (!member_config) {
-               realtime_ringinuse_field = "ringinuse";
-       } else {
-               const char *config_val;
-               if ((config_val = ast_variable_retrieve(member_config, NULL, "ringinuse"))) {
-                       ast_log(LOG_NOTICE, "ringinuse field entries found in queue_members table. Using 'ringinuse'\n");
-                       realtime_ringinuse_field = "ringinuse";
-               } else if ((config_val = ast_variable_retrieve(member_config, NULL, "ignorebusy"))) {
-                       ast_log(LOG_NOTICE, "ignorebusy field found in queue_members table with no ringinuse field. Using 'ignorebusy'\n");
-                       realtime_ringinuse_field = "ignorebusy";
-               } else {
-                       ast_log(LOG_NOTICE, "No entries were found for ringinuse/ignorebusy in queue_members table. Using 'ringinuse'\n");
-                       realtime_ringinuse_field = "ringinuse";
-               }
-       }
-
-       ast_config_destroy(member_config);
-
        return res ? AST_MODULE_LOAD_DECLINE : 0;
 }
 
        return res ? AST_MODULE_LOAD_DECLINE : 0;
 }