diff options
Diffstat (limited to 'src/backend/utils/misc/guc-file.l')
-rw-r--r-- | src/backend/utils/misc/guc-file.l | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l index c5e0fac4671..a04d35d3c98 100644 --- a/src/backend/utils/misc/guc-file.l +++ b/src/backend/utils/misc/guc-file.l @@ -120,6 +120,7 @@ ProcessConfigFile(GucContext context) *head, *tail; int i; + int file_variables_count = 0; /* * Config files are processed on startup (by the postmaster only) @@ -255,6 +256,7 @@ ProcessConfigFile(GucContext context) error = true; ConfFileWithError = item->filename; } + file_variables_count++; } /* @@ -342,6 +344,54 @@ ProcessConfigFile(GucContext context) } /* + * Check if we have allocated the array yet. + * + * If not, allocate it based on the number of file variables we have seen. + */ + if (!guc_file_variables) + { + /* For the first call */ + num_guc_file_variables = file_variables_count; + guc_file_variables = (ConfigFileVariable *) guc_malloc(FATAL, + num_guc_file_variables * sizeof(struct ConfigFileVariable)); + } + else + { + int i; + + /* Free all of the previously allocated entries */ + for (i = 0; i < num_guc_file_variables; i++) + { + free(guc_file_variables[i].name); + free(guc_file_variables[i].value); + free(guc_file_variables[i].filename); + } + + /* Update the global count and realloc based on the new size */ + num_guc_file_variables = file_variables_count; + guc_file_variables = (ConfigFileVariable *) guc_realloc(FATAL, + guc_file_variables, + num_guc_file_variables * sizeof(struct ConfigFileVariable)); + } + + /* + * Copy the settings which came from the files read into the + * guc_file_variables array which backs the pg_show_file_settings() + * function. + */ + for (item = head, i = 0; item && i < num_guc_file_variables; + item = item->next, i++) + { + guc_file_variables[i].name = guc_strdup(FATAL, item->name); + guc_file_variables[i].value = guc_strdup(FATAL, item->value); + guc_file_variables[i].filename = guc_strdup(FATAL, item->filename); + guc_file_variables[i].sourceline = item->sourceline; + } + + /* We had better have made it through the loop above to a clean ending. */ + Assert(!item && i == num_guc_file_variables); + + /* * Now apply the values from the config file. */ for (item = head; item; item = item->next) |