[BB#89] Don't recompile regular expressions

This is a modification of a patch originally written by
John van der Kamp <john@kirika.demon.nl> at
<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579427#12>

The modification was done by the committer.
This commit is contained in:
John van der Kamp 2010-06-01 07:54:25 +05:30 committed by Mukund Sivaraman
parent 5bb184c54d
commit 3127e726d0
3 changed files with 33 additions and 2 deletions

View File

@ -163,6 +163,8 @@ static HANDLE_FUNC (handle_upstream);
static HANDLE_FUNC (handle_upstream_no); static HANDLE_FUNC (handle_upstream_no);
#endif #endif
static void config_free_regex (void);
/* /*
* This macro can be used to make standard directives in the form: * This macro can be used to make standard directives in the form:
* directive arguments [arguments ...] * directive arguments [arguments ...]
@ -317,7 +319,8 @@ static void free_config (struct config_s *conf)
* *
* Returns 0 on success; negative upon failure. * Returns 0 on success; negative upon failure.
*/ */
static int config_compile (void) int
config_compile_regex (void)
{ {
unsigned int i, r; unsigned int i, r;
@ -335,9 +338,30 @@ static int config_compile (void)
if (r) if (r)
return r; return r;
} }
atexit (config_free_regex);
return 0; return 0;
} }
/*
* Frees pre-compiled regular expressions used by the configuration
* file. This function is registered to be automatically called at exit.
*/
static void
config_free_regex (void)
{
unsigned int i;
for (i = 0; i < ndirectives; i++) {
if (directives[i].cre) {
regfree (directives[i].cre);
safefree (directives[i].cre);
directives[i].cre = NULL;
}
}
}
/* /*
* Attempt to match the supplied line with any of the configuration * Attempt to match the supplied line with any of the configuration
* regexes defined above. If a match is found, call the handler * regexes defined above. If a match is found, call the handler
@ -397,7 +421,7 @@ static int load_config_file (const char *config_fname, struct config_s *conf)
goto done; goto done;
} }
if (config_compile () || config_parse (conf, config_file)) { if (config_parse (conf, config_file)) {
fprintf (stderr, "Unable to parse config file. " fprintf (stderr, "Unable to parse config file. "
"Not starting.\n"); "Not starting.\n");
goto done; goto done;

View File

@ -115,4 +115,6 @@ struct config_s {
extern int reload_config_file (const char *config_fname, struct config_s *conf, extern int reload_config_file (const char *config_fname, struct config_s *conf,
struct config_s *defaults); struct config_s *defaults);
int config_compile_regex (void);
#endif #endif

View File

@ -364,6 +364,11 @@ main (int argc, char **argv)
log_message (LOG_INFO, "Initializing " PACKAGE " ..."); log_message (LOG_INFO, "Initializing " PACKAGE " ...");
ret = config_compile_regex();
if (ret != 0) {
exit (EX_SOFTWARE);
}
initialize_config_defaults (&config_defaults); initialize_config_defaults (&config_defaults);
process_cmdline (argc, argv, &config_defaults); process_cmdline (argc, argv, &config_defaults);