The biggest concern that I have with this patch, which is the same concern that I had when I initially added the wildcard support, is how libconfuse is doing the parsing. When libconfuse calls the custom include function, it is in the middle of the lexer. This function turns around and calls a special lexer version of the same include function. Calling cfg_parse_buf() directly from the custom include function does not follow the same path. Hopefully the lexer will not get confused by this switch in code paths. For now it appears to be working, so I will assume that libconfuse is able to handle this context switch.
Brad >>> On 11/29/2008 at 5:15 AM, in message <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: > Revision: 1927 > http://ganglia.svn.sourceforge.net/ganglia/?rev=1927&view=rev > Author: carenas > Date: 2008-11-29 12:15:35 +0000 (Sat, 29 Nov 2008) > > Log Message: > ----------- > libganglia: use cfg_parse_buf to process includes for gmond > > avoid using a temporary file and limitations of cfg_include on the number > levels that are allowed. > > also avoid a segfault when using cfg_include when in buffer context like > when parsing the default configuration. > > Modified Paths: > -------------- > trunk/monitor-core/lib/libgmond.c > > Modified: trunk/monitor-core/lib/libgmond.c > =================================================================== > --- trunk/monitor-core/lib/libgmond.c 2008-11-29 11:27:59 UTC (rev 1926) > +++ trunk/monitor-core/lib/libgmond.c 2008-11-29 12:15:35 UTC (rev 1927) > @@ -22,6 +22,7 @@ > #include <apr_lib.h> > #include <sys/types.h> > #include <sys/stat.h> > +#include <fcntl.h> > #include <dirent.h> > #include <fnmatch.h> > > @@ -699,6 +700,8 @@ > struct stat statbuf; > DIR *dir; > struct dirent *entry; > + char *buff; > + int fd; > > if(argc != 1) > { > @@ -708,7 +711,15 @@ > > if (stat (fname, &statbuf) == 0) > { > - return cfg_include(cfg, opt, argc, argv); > + buff = calloc(statbuf.st_size + 1, 1); > + fd = open(fname, O_RDONLY); > + read(fd, buff, statbuf.st_size); > + close(fd); > + fd = cfg_parse_buf(cfg, buff); > + free(buff); > + if (fd) > + cfg_error(cfg, "error including %s", fname); > + return fd; > } > else if (has_wildcard(fname)) > { > @@ -717,9 +728,7 @@ > char *pattern = NULL; > char *idx = strrchr(fname, '/'); > apr_pool_t *p; > - apr_file_t *ftemp; > char *dirname = NULL; > - char tn[] = "gmond.tmp.XXXXXX"; > > if (idx == NULL) { > idx = strrchr(fname, '\\'); > @@ -735,57 +744,35 @@ > } > > apr_pool_create(&p, NULL); > - if (apr_temp_dir_get((const char**)&dirname, p) != APR_SUCCESS) { > -#ifndef LINUX > - cfg_error(cfg, "failed to determine the temp dir"); > - apr_pool_destroy(p); > - return 1; > -#else > - /* > - * workaround APR BUG46297 by using the POSIX shared memory > - * ramdrive that is available since glibc 2.2 > - */ > - dirname = apr_psprintf(p, "%s", "/dev/shm"); > -#endif > - } > - dirname = apr_psprintf(p, "%s/%s", dirname, tn); > - > - if (apr_file_mktemp(&ftemp, dirname, > - APR_CREATE | APR_READ | APR_WRITE | > APR_DELONCLOSE, > - p) != APR_SUCCESS) { > - cfg_error(cfg, "unable to create a temporary file %s", dirname); > - apr_pool_destroy(p); > - return 1; > - } > - > dir = opendir(path); > > - if(dir != NULL){ > - while((entry = readdir(dir)) != NULL) { > + if (dir != NULL) { > + while ((entry = readdir(dir)) != NULL) { > ret = fnmatch(pattern, entry->d_name, > FNM_PATHNAME|FNM_PERIOD); > if (ret == 0) { > - char *newpath, *line; > + char *newpath; > > newpath = apr_psprintf (p, "%s/%s", path, entry->d_name); > - line = apr_pstrcat(p, "include ('", newpath, "')\n", > NULL); > - apr_file_puts(line, ftemp); > + > + stat(newpath, &statbuf); > + buff = calloc(statbuf.st_size + 1, 1); > + fd = open(newpath, O_RDONLY); > + read(fd, buff, statbuf.st_size); > + close(fd); > + fd = cfg_parse_buf(cfg, buff); > + free(buff); > + if (fd) { > + cfg_error(cfg, "error including %s", newpath); > + return fd; > + } > } > } > closedir(dir); > free (path); > - > - argv[0] = dirname; > - if (cfg_include(cfg, opt, argc, argv)) > - cfg_error(cfg, "failed to process include file %s", fname); > - else > - debug_msg("processed include file %s\n", fname); > } > > - apr_file_close(ftemp); > apr_pool_destroy(p); > - > - argv[0] = fname; > } > else > { > @@ -795,4 +782,3 @@ > > return 0; > } > - > > > 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