]> granicus.if.org Git - postgresql/commitdiff
Fix another oversight in logging of changes in postgresql.conf settings.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Jul 2011 21:03:06 +0000 (17:03 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Jul 2011 21:03:06 +0000 (17:03 -0400)
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.

src/backend/commands/extension.c
src/backend/utils/misc/guc-file.l
src/backend/utils/misc/guc.c
src/include/utils/guc.h

index 58695690500e69c2ddabef9c3842d467af24798d..f6a03e16688ff7ccf4328ed79c9eb65ee26bfee7 100644 (file)
@@ -813,14 +813,14 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
         * error.
         */
        save_client_min_messages =
-               pstrdup(GetConfigOption("client_min_messages", false));
+               pstrdup(GetConfigOption("client_min_messages", false, false));
        if (client_min_messages < WARNING)
                (void) set_config_option("client_min_messages", "warning",
                                                                 PGC_USERSET, PGC_S_SESSION,
                                                                 GUC_ACTION_LOCAL, true);
 
        save_log_min_messages =
-               pstrdup(GetConfigOption("log_min_messages", false));
+               pstrdup(GetConfigOption("log_min_messages", false, false));
        if (log_min_messages < WARNING)
                (void) set_config_option("log_min_messages", "warning",
                                                                 PGC_SUSET, PGC_S_SESSION,
@@ -835,7 +835,7 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
         * but we cannot do that.  We have to actually set the search_path GUC in
         * case the extension script examines or changes it.
         */
-       save_search_path = pstrdup(GetConfigOption("search_path", false));
+       save_search_path = pstrdup(GetConfigOption("search_path", false, false));
 
        initStringInfo(&pathbuf);
        appendStringInfoString(&pathbuf, quote_identifier(schemaName));
index 78907b939dee1383244042c9dbc48aed6ab76d35..3e9b10328d480b47dce5240d74577fdc7b715885 100644 (file)
@@ -306,9 +306,9 @@ ProcessConfigFile(GucContext context)
                /* In SIGHUP cases in the postmaster, report changes */
                if (context == PGC_SIGHUP && !IsUnderPostmaster)
                {
-                       const char *preval = GetConfigOption(item->name, false);
+                       const char *preval = GetConfigOption(item->name, true, false);
 
-                       /* string variables could be NULL; treat that as empty */
+                       /* If option doesn't exist yet or is NULL, treat as empty string */
                        if (!preval)
                                preval = "";
                        /* must dup, else might have dangling pointer below */
@@ -323,7 +323,7 @@ ProcessConfigFile(GucContext context)
 
                        if (pre_value)
                        {
-                               const char *post_value = GetConfigOption(item->name, false);
+                               const char *post_value = GetConfigOption(item->name, true, false);
 
                                if (!post_value)
                                        post_value = "";
index f14ee9ebad0d4225603bb70520defc010e65cdbe..1460214293d68e4bc100cc9bf097f418c92da630 100644 (file)
@@ -5838,8 +5838,11 @@ SetConfigOption(const char *name, const char *value,
 
 
 /*
- * Fetch the current value of the option `name'. If the option doesn't exist,
- * throw an ereport and don't return.
+ * Fetch the current value of the option `name', as a string.
+ *
+ * If the option doesn't exist, return NULL if missing_ok is true (NOTE that
+ * this cannot be distinguished from a string variable with a NULL value!),
+ * otherwise throw an ereport and don't return.
  *
  * If restrict_superuser is true, we also enforce that only superusers can
  * see GUC_SUPERUSER_ONLY variables.  This should only be passed as true
@@ -5849,16 +5852,21 @@ SetConfigOption(const char *name, const char *value,
  * valid until the next call to configuration related functions.
  */
 const char *
-GetConfigOption(const char *name, bool restrict_superuser)
+GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
 {
        struct config_generic *record;
        static char buffer[256];
 
        record = find_option(name, false, ERROR);
        if (record == NULL)
+       {
+               if (missing_ok)
+                       return NULL;
                ereport(ERROR,
                                (errcode(ERRCODE_UNDEFINED_OBJECT),
-                          errmsg("unrecognized configuration parameter \"%s\"", name)));
+                                errmsg("unrecognized configuration parameter \"%s\"",
+                                               name)));
+       }
        if (restrict_superuser &&
                (record->flags & GUC_SUPERUSER_ONLY) &&
                !superuser())
index ee52cd735e33776ad647a57973cd261b7e4b1b62..011f6b7f001a60ce1fcfb732264238f5d355866d 100644 (file)
@@ -296,7 +296,8 @@ extern void DefineCustomEnumVariable(
 
 extern void EmitWarningsOnPlaceholders(const char *className);
 
-extern const char *GetConfigOption(const char *name, bool restrict_superuser);
+extern const char *GetConfigOption(const char *name, bool missing_ok,
+                               bool restrict_superuser);
 extern const char *GetConfigOptionResetString(const char *name);
 extern void ProcessConfigFile(GucContext context);
 extern void InitializeGUCOptions(void);