Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9d522cb

Browse files
committed
Fix another oversight in logging of changes in postgresql.conf settings.
We were using GetConfigOption to collect the old value of each setting, overlooking the possibility that it didn't exist yet. This does happen in the case of adding a new entry within a custom variable class, as exhibited in bug #6097 from Maxim Boguk. To fix, add a missing_ok parameter to GetConfigOption, but only in 9.1 and HEAD --- it seems possible that some third-party code is using that function, so changing its API in a minor release would cause problems. In 9.0, create a near-duplicate function instead.
1 parent 89fd72c commit 9d522cb

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

src/backend/commands/extension.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -814,14 +814,14 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
814814
* error.
815815
*/
816816
save_client_min_messages =
817-
pstrdup(GetConfigOption("client_min_messages", false));
817+
pstrdup(GetConfigOption("client_min_messages", false, false));
818818
if (client_min_messages < WARNING)
819819
(void) set_config_option("client_min_messages", "warning",
820820
PGC_USERSET, PGC_S_SESSION,
821821
GUC_ACTION_LOCAL, true);
822822

823823
save_log_min_messages =
824-
pstrdup(GetConfigOption("log_min_messages", false));
824+
pstrdup(GetConfigOption("log_min_messages", false, false));
825825
if (log_min_messages < WARNING)
826826
(void) set_config_option("log_min_messages", "warning",
827827
PGC_SUSET, PGC_S_SESSION,
@@ -836,7 +836,7 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
836836
* but we cannot do that. We have to actually set the search_path GUC in
837837
* case the extension script examines or changes it.
838838
*/
839-
save_search_path = pstrdup(GetConfigOption("search_path", false));
839+
save_search_path = pstrdup(GetConfigOption("search_path", false, false));
840840

841841
initStringInfo(&pathbuf);
842842
appendStringInfoString(&pathbuf, quote_identifier(schemaName));

src/backend/utils/misc/guc-file.l

+3-3
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ ProcessConfigFile(GucContext context)
306306
/* In SIGHUP cases in the postmaster, report changes */
307307
if (context == PGC_SIGHUP && !IsUnderPostmaster)
308308
{
309-
const char *preval = GetConfigOption(item->name, false);
309+
const char *preval = GetConfigOption(item->name, true, false);
310310

311-
/* string variables could be NULL; treat that as empty */
311+
/* If option doesn't exist yet or is NULL, treat as empty string */
312312
if (!preval)
313313
preval = "";
314314
/* must dup, else might have dangling pointer below */
@@ -323,7 +323,7 @@ ProcessConfigFile(GucContext context)
323323

324324
if (pre_value)
325325
{
326-
const char *post_value = GetConfigOption(item->name, false);
326+
const char *post_value = GetConfigOption(item->name, true, false);
327327

328328
if (!post_value)
329329
post_value = "";

src/backend/utils/misc/guc.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -5828,8 +5828,11 @@ SetConfigOption(const char *name, const char *value,
58285828

58295829

58305830
/*
5831-
* Fetch the current value of the option `name'. If the option doesn't exist,
5832-
* throw an ereport and don't return.
5831+
* Fetch the current value of the option `name', as a string.
5832+
*
5833+
* If the option doesn't exist, return NULL if missing_ok is true (NOTE that
5834+
* this cannot be distinguished from a string variable with a NULL value!),
5835+
* otherwise throw an ereport and don't return.
58335836
*
58345837
* If restrict_superuser is true, we also enforce that only superusers can
58355838
* see GUC_SUPERUSER_ONLY variables. This should only be passed as true
@@ -5839,16 +5842,21 @@ SetConfigOption(const char *name, const char *value,
58395842
* valid until the next call to configuration related functions.
58405843
*/
58415844
const char *
5842-
GetConfigOption(const char *name, bool restrict_superuser)
5845+
GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
58435846
{
58445847
struct config_generic *record;
58455848
static char buffer[256];
58465849

58475850
record = find_option(name, false, ERROR);
58485851
if (record == NULL)
5852+
{
5853+
if (missing_ok)
5854+
return NULL;
58495855
ereport(ERROR,
58505856
(errcode(ERRCODE_UNDEFINED_OBJECT),
5851-
errmsg("unrecognized configuration parameter \"%s\"", name)));
5857+
errmsg("unrecognized configuration parameter \"%s\"",
5858+
name)));
5859+
}
58525860
if (restrict_superuser &&
58535861
(record->flags & GUC_SUPERUSER_ONLY) &&
58545862
!superuser())

src/include/utils/guc.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ extern void DefineCustomEnumVariable(
296296

297297
extern void EmitWarningsOnPlaceholders(const char *className);
298298

299-
extern const char *GetConfigOption(const char *name, bool restrict_superuser);
299+
extern const char *GetConfigOption(const char *name, bool missing_ok,
300+
bool restrict_superuser);
300301
extern const char *GetConfigOptionResetString(const char *name);
301302
extern void ProcessConfigFile(GucContext context);
302303
extern void InitializeGUCOptions(void);

0 commit comments

Comments
 (0)