Carlo,
    I don't understand what you are trying to do with this patch.  Once 
libconfuse has finished reading and parsingn the entire configuration file 
along with all of the individual modules sections, it automatically 
consolidates them into a single section.  There is no need to try to scan 
individual modules sections.  This code was working correctly as it was.  
Please revert this patch.

Also, in libgmond.c I intentionally used malloc because I knew that the memory 
allocation was temporary.  By using apr functions to allocate the memory, the 
memory will never be freed for the lifetime of the process.  Any memory 
allocated to an apr pool will remain allocated until the pool is cleared or 
destroyed.  The pool that is being used is never cleared or destroyed.  
Therefore I used malloc and free to make sure that memory wasn't remaining 
allocated needlessly.  Please revert this patch also.

Brad

>>> On 11/29/2008 at 3:27 AM, in message
<[EMAIL PROTECTED]>,
<[EMAIL PROTECTED]> wrote:
> Revision: 1925
>           http://ganglia.svn.sourceforge.net/ganglia/?rev=1925&view=rev 
> Author:   carenas
> Date:     2008-11-29 10:27:35 +0000 (Sat, 29 Nov 2008)
> 
> Log Message:
> -----------
> gmond: modules section is used multiple times in the configuration
> 
> scans all configured multiple sections for "modules" when looking
> for module definitions in gmond or module configuration in modpython
> 
> Modified Paths:
> --------------
>     trunk/monitor-core/gmond/gmond.c
>     trunk/monitor-core/gmond/modules/python/mod_python.c
>     trunk/monitor-core/lib/libgmond.c
> 
> Modified: trunk/monitor-core/gmond/gmond.c
> ===================================================================
> --- trunk/monitor-core/gmond/gmond.c  2008-11-27 05:28:54 UTC (rev 1924)
> +++ trunk/monitor-core/gmond/gmond.c  2008-11-29 10:27:35 UTC (rev 1925)
> @@ -1726,125 +1726,131 @@
>  load_metric_modules( void )
>  {
>      cfg_t *tmp;
> -    int j;
> +    unsigned int m, j;
>  
> -    tmp = cfg_getsec( config_file, "modules");
> -    for (j = 0; j < cfg_size(tmp, "module"); j++) 
> -      {
> -        apr_dso_handle_t *modHandle = NULL;
> -        apr_dso_handle_sym_t modSym;
> -        mmodule *modp;
> -        char *modPath=NULL, *modName=NULL, *modparams=NULL, 
> *modLanguage=NULL;
> -        apr_array_header_t *modParams_list = NULL;
> -        int k, modEnabled;
> -        apr_status_t merge_ret;
> +    for (m = 0; m < cfg_size(config_file, "modules"); m++) {
> +        tmp = cfg_getnsec( config_file, "modules", m);
> +        for (j = 0; j < cfg_size(tmp, "module"); j++) {
> +            apr_dso_handle_t *modHandle = NULL;
> +            apr_dso_handle_sym_t modSym;
> +            mmodule *modp;
> +            char *modPath=NULL, *modName=NULL, *modparams=NULL, 
> *modLanguage=NULL;
> +            apr_array_header_t *modParams_list = NULL;
> +            int k, modEnabled;
> +            apr_status_t merge_ret;
>  
> -        cfg_t *module = cfg_getnsec(tmp, "module", j);
> +            cfg_t *module = cfg_getnsec(tmp, "module", j);
>  
> -        /* Check the module language to make sure that
> -           the module is loaded correctly or should be
> -           delegated to an alternate module interface
> -        */
> -        modLanguage = cfg_getstr(module, "language");
> -        if (modLanguage && strcasecmp(modLanguage, "C/C++")) 
> -            continue;
> +            /*
> +             * Check the module language to make sure that
> +             * the module is loaded correctly or should be
> +             * delegated to an alternate module interface
> +             */
> +            modLanguage = cfg_getstr(module, "language");
> +            if (modLanguage && strcasecmp(modLanguage, "C/C++")) 
> +                continue;
>  
> -        /* Check to make sure that the module is enabled.
> -        */
> -        modEnabled = cfg_getbool(module, "enabled");
> -        if (!modEnabled) 
> -            continue;
> +            /*
> +             * Check to make sure that the module is enabled.
> +             */
> +            modEnabled = cfg_getbool(module, "enabled");
> +            if (!modEnabled) 
> +                continue;
>  
> -        modPath = cfg_getstr(module, "path");
> -        if(modPath && *modPath != '/' && *modPath != '.')
> -          {
> -            if (module_dir)
> -                merge_ret = apr_filepath_merge(&modPath, module_dir,
> +            modPath = cfg_getstr(module, "path");
> +            if (modPath && *modPath != '/' && *modPath != '.') {
> +                if (module_dir)
> +                    merge_ret = apr_filepath_merge(&modPath, module_dir,
>                                  modPath,
>                                  APR_FILEPATH_NOTRELATIVE | 
> APR_FILEPATH_NATIVE,
>                                  global_context);
> -            else
> -                merge_ret = apr_filepath_merge(&modPath, GANGLIA_MODULE_DIR,
> +                else
> +                    merge_ret = apr_filepath_merge(&modPath, 
> GANGLIA_MODULE_DIR,
>                                  modPath,
>                                  APR_FILEPATH_NOTRELATIVE | 
> APR_FILEPATH_NATIVE,
>                                  global_context);
>  
> -            if (merge_ret != APR_SUCCESS) 
> -                modPath = cfg_getstr(module, "path");
> -          }
> -        modName = cfg_getstr(module, "name");
> -        modparams = cfg_getstr(module, "params");
> -        modParams_list = apr_array_make(global_context, 2, sizeof(mmparam));
> +                if (merge_ret != APR_SUCCESS) 
> +                    modPath = cfg_getstr(module, "path");
> +            }
> +            modName = cfg_getstr(module, "name");
> +            modparams = cfg_getstr(module, "params");
> +            modParams_list = apr_array_make(global_context, 2, 
> sizeof(mmparam));
>  
> -        for (k = 0; k < cfg_size(module, "param"); k++) 
> -          {
> -            cfg_t *param;
> -            mmparam *node = apr_array_push(modParams_list);
> +            for (k = 0; k < cfg_size(module, "param"); k++) {
> +                cfg_t *param;
> +                mmparam *node = apr_array_push(modParams_list);
>  
> -            param = cfg_getnsec(module, "param", k);
> -            node->name = apr_pstrdup(global_context, param->title);
> -            node->value = apr_pstrdup(global_context, cfg_getstr(param, 
> "value"));
> -          }
> +                param = cfg_getnsec(module, "param", k);
> +                node->name = apr_pstrdup(global_context, param->title);
> +                node->value = apr_pstrdup(global_context,
> +                                          cfg_getstr(param, "value"));
> +            }
>  
> -        /*
> -         * Load the file into the gmond address space
> -         */
> -        if (apr_dso_load(&modHandle, modPath, global_context) != 
> APR_SUCCESS) 
> 
> -          {
> -            char my_error[256];
> +            /*
> +             * Load the file into the gmond address space
> +             */
> +            if (apr_dso_load(&modHandle, modPath, global_context) != 
> APR_SUCCESS) {
> +                char my_error[256];
>  
> -            err_msg("Cannot load %s metric module: %s", modPath,
> -                     apr_dso_error(modHandle, my_error, sizeof(my_error)));
> -            if (!modPath) 
> -                err_msg("No load path specified for module: %s or incorrect 
> module language designation [%s].\n", 
> -                        modName, modLanguage);
> -            continue;
> -          }
> -        debug_msg("loaded module: %s", modName);
> +                err_msg("Cannot load %s metric module: %s", modPath,
> +                        apr_dso_error(modHandle, my_error, 
> sizeof(my_error)));
> +                if (!modPath) 
> +                    err_msg("No load path specified for module: %s or 
> incorrect module language designation [%s].\n", 
> +                            modName, modLanguage);
> +                continue;
> +            }
> +            debug_msg("loaded module: %s", modName);
>  
> -        /*
> -         * Retrieve the pointer to the module structure through the module 
> name.
> -         */
> -        if (apr_dso_sym(&modSym, modHandle, modName) != APR_SUCCESS) 
> -          {
> -            char my_error[256];
> +            /*
> +             * Retrieve the pointer to the module structure through
> +             * the module name.
> +             */
> +            if (apr_dso_sym(&modSym, modHandle, modName) != APR_SUCCESS) {
> +                char my_error[256];
>  
> -            err_msg("Cannot locate internal module structure '%s' in file 
> %s: %s\nPossibly an incorrect module language designation [%s].\n", 
> -                     modName, modPath, apr_dso_error(modHandle, my_error, 
> sizeof(my_error)), modLanguage);
> -            continue;
> -          }
> +                err_msg("Cannot locate internal module structure '%s' in 
> file %s: %s\nPossibly an incorrect module language designation [%s].\n", 
> +                        modName, modPath,
> +                        apr_dso_error(modHandle, my_error, 
> sizeof(my_error)),
> +                        modLanguage);
> +                continue;
> +            }
>  
> -        modp = (mmodule*) modSym;
> -        modp->dynamic_load_handle = (apr_dso_handle_t *)modHandle;
> -        modp->module_name = apr_pstrdup (global_context, modName);
> -        modp->module_params = apr_pstrdup (global_context, modparams);
> -        modp->module_params_list = modParams_list;
> -        modp->config_file = config_file;
> +            modp = (mmodule*) modSym;
> +            modp->dynamic_load_handle = (apr_dso_handle_t *)modHandle;
> +            modp->module_name = apr_pstrdup (global_context, modName);
> +            modp->module_params = apr_pstrdup (global_context, modparams);
> +            modp->module_params_list = modParams_list;
> +            modp->config_file = config_file;
>  
> -        /*
> -         * Make sure the found module structure is really a module structure
> -         *
> -         */
> -        if (modp->magic != MMODULE_MAGIC_COOKIE) {
> -            err_msg("Internal module structure '%s' in file %s is not 
> compatible -"
> -                     "perhaps this is not a metric module.\n", 
> -                     modName, modPath);
> -            continue;
> -        }
> +            /*
> +             * Make sure the found module structure is really
> +             * a module structure
> +             */
> +            if (modp->magic != MMODULE_MAGIC_COOKIE) {
> +                err_msg("Internal module structure '%s' in file %s is not 
> compatible -"
> +                        "perhaps this is not a metric module.\n", 
> +                        modName, modPath);
> +                continue;
> +            }
>  
> -        /* Validate that the module was built against a compatible module 
> interface API. */
> -        if (modp->version != MMODULE_MAGIC_NUMBER_MAJOR) {
> -            err_msg("Module \"%s\" is not compatible with this "
> -                    "version of Gmond (found %d, need %d).",
> -                    modName, modp->version, MMODULE_MAGIC_NUMBER_MAJOR);
> -            continue;
> -        }
> +            /*
> +             * Validate that the module was built against a compatible
> +             * module interface API.
> +             */
> +            if (modp->version != MMODULE_MAGIC_NUMBER_MAJOR) {
> +                err_msg("Module \"%s\" is not compatible with this "
> +                        "version of Gmond (found %d, need %d).",
> +                        modName, modp->version, MMODULE_MAGIC_NUMBER_MAJOR);
> +                continue;
> +            }
>  
> -        if (metric_modules != NULL) {
> -            modp->next = metric_modules;
> +            if (metric_modules != NULL)
> +                modp->next = metric_modules;
> +
> +            metric_modules = modp;
>          }
> -        metric_modules = modp;
> -      }
> +    }
>      return;
>  }
>  
> @@ -1871,7 +1877,7 @@
>            apr_pool_cleanup_register(global_context, modp,
>                                      modular_metric_cleanup,
>                                      apr_pool_cleanup_null);
> -  
> +
>            metric_info = modp->metrics_info;
>            for (i = 0; metric_info[i].name != NULL; i++) 
>              {
> 
> Modified: trunk/monitor-core/gmond/modules/python/mod_python.c
> ===================================================================
> --- trunk/monitor-core/gmond/modules/python/mod_python.c      2008-11-27 
> 05:28:54 UTC 
> (rev 1924)
> +++ trunk/monitor-core/gmond/modules/python/mod_python.c      2008-11-29 
> 10:27:35 UTC 
> (rev 1925)
> @@ -473,34 +473,37 @@
>  static cfg_t* find_module_config(char *modname)
>  {
>      cfg_t *modules_cfg;
> -    int j;
> +    unsigned int m, j;
>  
> -    modules_cfg = cfg_getsec(python_module.config_file, "modules");
> -    for (j = 0; j < cfg_size(modules_cfg, "module"); j++) {
> -        char *modName, *modLanguage;
> -        int modEnabled;
> +    for (m = 0; m < cfg_size(python_module.config_file, "modules"); m++) {
> +        modules_cfg = cfg_getnsec(python_module.config_file, "modules", m);
> +        for (j = 0; j < cfg_size(modules_cfg, "module"); j++) {
> +            char *modName, *modLanguage;
> +            int modEnabled;
>  
> -        cfg_t *pymodule = cfg_getnsec(modules_cfg, "module", j);
> +            cfg_t *pymodule = cfg_getnsec(modules_cfg, "module", j);
>  
> -        /* Check the module language to make sure that
> -           the language designation is python.
> -        */
> -        modLanguage = cfg_getstr(pymodule, "language");
> -        if (!modLanguage || strcasecmp(modLanguage, "python")) 
> -            continue;
> +            /*
> +             * Check the module language to make sure that
> +             * the language designation is python.
> +             */
> +            modLanguage = cfg_getstr(pymodule, "language");
> +            if (!modLanguage || strcasecmp(modLanguage, "python")) 
> +                continue;
>  
> -        modName = cfg_getstr(pymodule, "name");
> -        if (strcasecmp(modname, modName)) {
> -            continue;
> -        }
> +            modName = cfg_getstr(pymodule, "name");
> +            if (strcasecmp(modname, modName))
> +                continue;
>  
> -        /* Check to make sure that the module is enabled.
> -        */
> -        modEnabled = cfg_getbool(pymodule, "enabled");
> -        if (!modEnabled) 
> -            continue;
> +            /*
> +             * Check to make sure that the module is enabled.
> +             */
> +            modEnabled = cfg_getbool(pymodule, "enabled");
> +            if (!modEnabled) 
> +                continue;
>  
> -        return pymodule;
> +            return pymodule;
> +        }
>      }
>      return NULL; 
>  }
> @@ -515,7 +518,7 @@
>              cfg_t *param;
>              char *name, *value;
>              PyObject *pyvalue;
> -    
> +
>              param = cfg_getnsec(pymodule, "param", k);
>              name = apr_pstrdup(pool, param->title);
>              value = apr_pstrdup(pool, cfg_getstr(param, "value"));
> 
> Modified: trunk/monitor-core/lib/libgmond.c
> ===================================================================
> --- trunk/monitor-core/lib/libgmond.c 2008-11-27 05:28:54 UTC (rev 1924)
> +++ trunk/monitor-core/lib/libgmond.c 2008-11-29 10:27:35 UTC (rev 1925)
> @@ -154,7 +154,7 @@
>    CFG_SEC("tcp_accept_channel", tcp_accept_channel_opts, CFGF_MULTI),
>    CFG_SEC("collection_group",  collection_group_opts, CFGF_MULTI),
>    CFG_FUNC("include", Ganglia_cfg_include),
> -  CFG_SEC("modules",  metric_modules_opts, CFGF_NONE),
> +  CFG_SEC("modules",  metric_modules_opts, CFGF_MULTI),
>    CFG_END()
>  }; 
>  
> 
> 
> This was sent by the SourceForge.net collaborative development platform, the 
> world's largest Open Source development site.
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/ 
> _______________________________________________
> Ganglia-svn mailing list
> [EMAIL PROTECTED] 
> https://lists.sourceforge.net/lists/listinfo/ganglia-svn 



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ganglia-developers mailing list
Ganglia-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ganglia-developers

Reply via email to