MINOR: config: keep up-to-date current file/line/section in the global struct
Let's add a few fields to the global struct to store information about the current file being processed, the current line number and the current section. This will be used to retrieve them using special variables.
This commit is contained in:
parent
6a2110c717
commit
5150805a5c
@ -159,6 +159,10 @@ struct global {
|
||||
} unix_bind;
|
||||
struct proxy *cli_fe; /* the frontend holding the stats settings */
|
||||
int numa_cpu_mapping;
|
||||
int cfg_curr_line; /* line number currently being parsed */
|
||||
const char *cfg_curr_file; /* config file currently being parsed or NULL */
|
||||
char *cfg_curr_section; /* config section name currently being parsed or NULL */
|
||||
|
||||
/* The info above is config stuff, it doesn't change during the process' life */
|
||||
/* A number of the elements below are updated by all threads in real time and
|
||||
* suffer high contention, so we need to put them in their own cache lines, if
|
||||
|
@ -1685,6 +1685,9 @@ int readcfgfile(const char *file)
|
||||
int non_global_section_parsed = 0;
|
||||
char *errmsg = NULL;
|
||||
|
||||
global.cfg_curr_line = 0;
|
||||
global.cfg_curr_file = file;
|
||||
|
||||
if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
|
||||
ha_alert("Out of memory trying to allocate a buffer for a configuration line.\n");
|
||||
err_code = -1;
|
||||
@ -1720,6 +1723,7 @@ next_line:
|
||||
}
|
||||
|
||||
linenum++;
|
||||
global.cfg_curr_line = linenum;
|
||||
|
||||
if (fatal >= 50) {
|
||||
ha_alert("parsing [%s:%d]: too many fatal errors (%d), stopping now.\n", file, linenum, fatal);
|
||||
@ -2049,6 +2053,8 @@ next_line:
|
||||
cursection = ics->section_name;
|
||||
pcs = cs;
|
||||
cs = ics;
|
||||
free(global.cfg_curr_section);
|
||||
global.cfg_curr_section = strdup(*args[1] ? args[1] : args[0]);
|
||||
|
||||
if (global.mode & MODE_DIAG) {
|
||||
check_section_position(args[0], file, linenum,
|
||||
@ -2095,6 +2101,7 @@ next_line:
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
}
|
||||
|
||||
ha_free(&global.cfg_curr_section);
|
||||
if (cs && cs->post_section_parser)
|
||||
err_code |= cs->post_section_parser();
|
||||
|
||||
@ -2113,6 +2120,9 @@ err:
|
||||
cursection = NULL;
|
||||
free(thisline);
|
||||
free(outline);
|
||||
global.cfg_curr_line = 0;
|
||||
global.cfg_curr_file = NULL;
|
||||
|
||||
if (f)
|
||||
fclose(f);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user