Skip to content

Commit

Permalink
Fixing glob implementation. No idea what I was thinking there before.
Browse files Browse the repository at this point in the history
Globbing /var/log/httpd/*.access.log on a directory with 5k sites, just went
from 4 minutes (yes, 4 minutes) to 1 second.
  • Loading branch information
dcid committed Feb 23, 2016
1 parent 64a2269 commit 6264ce9
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions src/config/localfile-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,54 +196,53 @@ int Read_Localfile(XML_NODE node, void *d1, void *d2)
continue;
}


/* Checking for strftime on globs too. */
if(strchr(g.gl_pathv[glob_offset], '%'))
while(g.gl_pathv[glob_offset] != NULL)
{
struct tm *p;
time_t l_time = time(0);
char lfile[OS_FLSIZE + 1];
size_t ret;

p = localtime(&l_time);

lfile[OS_FLSIZE] = '\0';
ret = strftime(lfile, OS_FLSIZE, g.gl_pathv[glob_offset], p);
if(ret == 0)
/* Checking for strftime on globs too. */
if(strchr(g.gl_pathv[glob_offset], '%'))
{
merror(PARSE_ERROR, ARGV0, g.gl_pathv[glob_offset]);
return(OS_INVALID);
struct tm *p;
time_t l_time = time(0);
char lfile[OS_FLSIZE + 1];
size_t ret;

p = localtime(&l_time);

lfile[OS_FLSIZE] = '\0';
ret = strftime(lfile, OS_FLSIZE, g.gl_pathv[glob_offset], p);
if(ret == 0)
{
merror(PARSE_ERROR, ARGV0, g.gl_pathv[glob_offset]);
return(OS_INVALID);
}

os_strdup(g.gl_pathv[glob_offset], logf[pl].ffile);
os_strdup(g.gl_pathv[glob_offset], logf[pl].file);
}
else
{
os_strdup(g.gl_pathv[glob_offset], logf[pl].file);
}

os_strdup(g.gl_pathv[glob_offset], logf[pl].ffile);
os_strdup(g.gl_pathv[glob_offset], logf[pl].file);
}
else
{
os_strdup(g.gl_pathv[glob_offset], logf[pl].file);
}


glob_offset++;
globfree(&g);
glob_offset++;

/* Now we need to create another file entry */
pl++;
os_realloc(logf, (pl +2)*sizeof(logreader), log_config->config);
logf = log_config->config;
/* Now we need to create another file entry */
pl++;
os_realloc(logf, (pl +2)*sizeof(logreader), log_config->config);
logf = log_config->config;

logf[pl].file = NULL;
logf[pl].alias = NULL;
logf[pl].logformat = NULL;
logf[pl].fp = NULL;
logf[pl].ffile = NULL;
logf[pl].file = NULL;
logf[pl].alias = NULL;
logf[pl].logformat = NULL;
logf[pl].fp = NULL;
logf[pl].ffile = NULL;

logf[pl +1].file = NULL;
logf[pl +1].alias = NULL;
logf[pl +1].logformat = NULL;
logf[pl +1].file = NULL;
logf[pl +1].alias = NULL;
logf[pl +1].logformat = NULL;
}

/* We can not increment the file count in here */
continue;
globfree(&g);
}
else if(strchr(node[i]->content, '%'))
#else
Expand Down

0 comments on commit 6264ce9

Please sign in to comment.