@@ -118,11 +118,11 @@ ProcessConfigFile(GucContext context)
118
118
bool error = false;
119
119
bool apply = false;
120
120
int elevel;
121
+ const char *ConfFileWithError;
121
122
ConfigVariable *item,
122
- *head,
123
- *tail;
123
+ *head,
124
+ *tail;
124
125
int i;
125
- char *ErrorConfFile = ConfigFileName;
126
126
127
127
/*
128
128
* Config files are processed on startup (by the postmaster only)
@@ -138,6 +138,7 @@ ProcessConfigFile(GucContext context)
138
138
elevel = IsUnderPostmaster ? DEBUG2 : LOG;
139
139
140
140
/* Parse the main config file into a list of option names and values */
141
+ ConfFileWithError = ConfigFileName;
141
142
head = tail = NULL;
142
143
143
144
if (!ParseConfigFile(ConfigFileName, NULL, true, 0, elevel, &head, &tail))
@@ -160,25 +161,23 @@ ProcessConfigFile(GucContext context)
160
161
{
161
162
/* Syntax error(s) detected in the file, so bail out */
162
163
error = true ;
163
- ErrorConfFile = PG_AUTOCONF_FILENAME;
164
+ ConfFileWithError = PG_AUTOCONF_FILENAME;
164
165
goto cleanup_list;
165
166
}
166
167
}
167
168
else
168
169
{
169
- ConfigVariable *prev = NULL ;
170
-
171
170
/*
172
- * Pick up only the data_directory if DataDir is not set, which
173
- * means that the configuration file is read for the first time and
174
- * PG_AUTOCONF_FILENAME file cannot be read yet. In this case,
175
- * we shouldn't pick any settings except the data_directory
176
- * from postgresql.conf because they might be overwritten
177
- * with the settings in PG_AUTOCONF_FILENAME file which will be
178
- * read later. OTOH, since it's ensured that data_directory doesn't
179
- * exist in PG_AUTOCONF_FILENAME file, it will never be overwritten
180
- * later.
171
+ * If DataDir is not set, the PG_AUTOCONF_FILENAME file cannot be
172
+ * read. In this case, we don't want to accept any settings but
173
+ * data_directory from postgresql.conf, because they might be
174
+ * overwritten with settings in the PG_AUTOCONF_FILENAME file which
175
+ * will be read later. OTOH, since data_directory isn't allowed in the
176
+ * PG_AUTOCONF_FILENAME file, it will never be overwritten later.
181
177
*/
178
+ ConfigVariable *prev = NULL ;
179
+
180
+ /* Prune all items except "data_directory" from the list */
182
181
for (item = head; item;)
183
182
{
184
183
ConfigVariable *ptr = item;
@@ -189,26 +188,20 @@ ProcessConfigFile(GucContext context)
189
188
if (prev == NULL )
190
189
head = ptr->next ;
191
190
else
192
- {
193
191
prev->next = ptr->next ;
194
- /*
195
- * On removing last item in list, we need to update tail
196
- * to ensure that list will be maintianed.
197
- */
198
- if (prev->next == NULL )
199
- tail = prev;
200
- }
192
+ if (ptr->next == NULL )
193
+ tail = prev;
201
194
FreeConfigVariable (ptr);
202
195
}
203
196
else
204
197
prev = ptr;
205
198
}
206
199
207
200
/*
208
- * Quick exit if data_directory is not present in list .
201
+ * Quick exit if data_directory is not present in file .
209
202
*
210
- * Don't remember when we last successfully loaded the config file in
211
- * this case because that time will be set soon by subsequent load of
203
+ * We need not do any further processing, in particular we don't set
204
+ * PgReloadTime; that will be set soon by subsequent full loading of
212
205
* the config file.
213
206
*/
214
207
if (head == NULL )
@@ -263,7 +256,7 @@ ProcessConfigFile(GucContext context)
263
256
item->name ,
264
257
item->filename , item->sourceline )));
265
258
error = true ;
266
- ErrorConfFile = item->filename ;
259
+ ConfFileWithError = item->filename ;
267
260
}
268
261
}
269
262
@@ -392,7 +385,7 @@ ProcessConfigFile(GucContext context)
392
385
else if (scres == 0 )
393
386
{
394
387
error = true ;
395
- ErrorConfFile = item->filename ;
388
+ ConfFileWithError = item->filename ;
396
389
}
397
390
/* else no error but variable's active value was not changed */
398
391
@@ -421,23 +414,23 @@ ProcessConfigFile(GucContext context)
421
414
ereport (ERROR,
422
415
(errcode (ERRCODE_CONFIG_FILE_ERROR),
423
416
errmsg (" configuration file \" %s\" contains errors" ,
424
- ErrorConfFile )));
417
+ ConfFileWithError )));
425
418
else if (apply)
426
419
ereport (elevel,
427
420
(errcode (ERRCODE_CONFIG_FILE_ERROR),
428
421
errmsg (" configuration file \" %s\" contains errors; unaffected changes were applied" ,
429
- ErrorConfFile )));
422
+ ConfFileWithError )));
430
423
else
431
424
ereport (elevel,
432
425
(errcode (ERRCODE_CONFIG_FILE_ERROR),
433
426
errmsg (" configuration file \" %s\" contains errors; no changes were applied" ,
434
- ErrorConfFile )));
427
+ ConfFileWithError )));
435
428
}
436
429
437
430
/*
438
431
* Calling FreeConfigVariables() any earlier than this can cause problems,
439
- * because ErrorConfFile could be pointing to a string that will be freed
440
- * here.
432
+ * because ConfFileWithError could be pointing to a string that will be
433
+ * freed here.
441
434
*/
442
435
FreeConfigVariables (head);
443
436
}
@@ -477,8 +470,11 @@ AbsoluteConfigLocation(const char *location, const char *calling_file)
477
470
* Read and parse a single configuration file. This function recurses
478
471
* to handle "include" directives.
479
472
*
480
- * See ParseConfigFp for details. This one merely adds opening the
481
- * file rather than working from a caller-supplied file descriptor,
473
+ * If "strict" is true, treat failure to open the config file as an error,
474
+ * otherwise just skip the file.
475
+ *
476
+ * See ParseConfigFp for further details. This one merely adds opening the
477
+ * config file rather than working from a caller-supplied file descriptor,
482
478
* and absolute-ifying the path name if necessary.
483
479
*/
484
480
bool
@@ -516,12 +512,13 @@ ParseConfigFile(const char *config_file, const char *calling_file, bool strict,
516
512
errmsg (" could not open configuration file \" %s\" : %m" ,
517
513
abs_path)));
518
514
OK = false ;
519
- goto cleanup;
520
515
}
521
-
522
- ereport (LOG,
523
- (errmsg (" skipping missing configuration file \" %s\" " ,
524
- abs_path)));
516
+ else
517
+ {
518
+ ereport (LOG,
519
+ (errmsg (" skipping missing configuration file \" %s\" " ,
520
+ abs_path)));
521
+ }
525
522
goto cleanup;
526
523
}
527
524
@@ -616,9 +613,7 @@ ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel,
616
613
{
617
614
char *opt_name = NULL ;
618
615
char *opt_value = NULL ;
619
- ConfigVariable *item,
620
- *cur_item = NULL ,
621
- *prev_item = NULL ;
616
+ ConfigVariable *item;
622
617
623
618
if (token == GUC_EOL) /* empty or comment line */
624
619
continue ;
@@ -701,41 +696,13 @@ ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel,
701
696
}
702
697
else
703
698
{
704
- /*
705
- * ordinary variable, append to list. For multiple items of
706
- * same parameter, retain only which comes later.
707
- */
699
+ /* ordinary variable, append to list */
708
700
item = palloc (sizeof *item);
709
701
item->name = opt_name;
710
702
item->value = opt_value;
711
703
item->filename = pstrdup (config_file);
712
704
item->sourceline = ConfigFileLineno-1 ;
713
705
item->next = NULL ;
714
-
715
- /* Remove the existing item of same parameter from the list */
716
- for (cur_item = *head_p; cur_item; prev_item = cur_item,
717
- cur_item = cur_item->next )
718
- {
719
- if (strcmp (item->name , cur_item->name ) == 0 )
720
- {
721
- if (prev_item == NULL )
722
- *head_p = cur_item->next ;
723
- else
724
- {
725
- prev_item->next = cur_item->next ;
726
- /*
727
- * On removing last item in list, we need to update tail
728
- * to ensure that list will be maintianed.
729
- */
730
- if (prev_item->next == NULL )
731
- *tail_p = prev_item;
732
- }
733
-
734
- FreeConfigVariable (cur_item);
735
- break ;
736
- }
737
- }
738
-
739
706
if (*head_p == NULL )
740
707
*head_p = item;
741
708
else
@@ -911,21 +878,6 @@ cleanup:
911
878
return status;
912
879
}
913
880
914
- /*
915
- * Free a ConfigVariable
916
- */
917
- static void
918
- FreeConfigVariable (ConfigVariable *item)
919
- {
920
- if (item != NULL )
921
- {
922
- pfree (item->name );
923
- pfree (item->value );
924
- pfree (item->filename );
925
- pfree (item);
926
- }
927
- }
928
-
929
881
/*
930
882
* Free a list of ConfigVariables, including the names and the values
931
883
*/
@@ -944,6 +896,18 @@ FreeConfigVariables(ConfigVariable *list)
944
896
}
945
897
}
946
898
899
+ /*
900
+ * Free a single ConfigVariable
901
+ */
902
+ static void
903
+ FreeConfigVariable (ConfigVariable *item)
904
+ {
905
+ pfree (item->name );
906
+ pfree (item->value );
907
+ pfree (item->filename );
908
+ pfree (item);
909
+ }
910
+
947
911
948
912
/*
949
913
* scanstr
0 commit comments