diff --git a/src/libpcp/src/connectlocal.c b/src/libpcp/src/connectlocal.c index de84213..aa39407 100644 --- a/src/libpcp/src/connectlocal.c +++ b/src/libpcp/src/connectlocal.c @@ -39,12 +39,11 @@ build_dsotab(void) * mmv 70 dso mmv_init /var/lib/pcp/pmdas/mmv/pmda_mmv.so * */ - char configFileName[MAXPATHLEN]; - FILE *configFile; char *config; char *p; char *q; struct stat sbuf; + int configfd; int lineno = 1; int domain; char *init; @@ -54,23 +53,23 @@ build_dsotab(void) numdso = 0; dsotab = NULL; - strcpy(configFileName, pmGetConfig("PCP_PMCDCONF_PATH")); #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_CONTEXT) { - fprintf(stderr, "build_dsotab: parsing %s\n", configFileName); + fprintf(stderr, "build_dsotab: parsing %s\n", pmGetConfig("PCP_PMCDCONF_PATH")); } #endif - if (stat(configFileName, &sbuf) < 0) { + + if ((configfd = open(pmGetConfig("PCP_PMCDCONF_PATH"), O_RDONLY)) < 0) return -errno; - } - configFile = fopen(configFileName, "r"); - if (configFile == NULL) { + if (fstat(configfd, &sbuf) < 0) { + close(configfd); return -errno; } - if ((config = mmap(NULL, sbuf.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(configFile), 0)) == MAP_FAILED) { - fclose(configFile); + + config = __pmMemoryMap(configfd, sbuf.st_size, 0); + close(configfd); + if (config == NULL) return -errno; - } p = config; while (*p != '\0') { @@ -136,8 +135,7 @@ eatline: } } - fclose(configFile); - munmap(config, sbuf.st_size); + __pmMemoryUnmap(config, sbuf.st_size); return 0; }