1010 * Written by Peter Eisentraut <peter_e@gmx.net>.
1111 *
1212 * IDENTIFICATION
13- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.338 2006/08/1301:30:17 momjian Exp $
13+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.339 2006/08/1302:22:24 momjian Exp $
1414 *
1515 *--------------------------------------------------------------------
1616 */
@@ -2692,40 +2692,40 @@ InitializeGUCOptions(void)
26922692{
26932693struct config_bool * conf = (struct config_bool * )gconf ;
26942694
2695- if (conf -> assign_hook )
2696- if ( !(* conf -> assign_hook ) (conf -> reset_val , true,
2697- PGC_S_DEFAULT ))
2698- elog (FATAL ,"failed to initialize %s to %d" ,
2699- conf -> gen .name , (int )conf -> reset_val );
2700- * conf -> variable = conf -> reset_val ;
2695+ if (conf -> assign_hook &&
2696+ !(* conf -> assign_hook ) (conf -> boot_val , true,
2697+ PGC_S_DEFAULT ))
2698+ elog (FATAL ,"failed to initialize %s to %d" ,
2699+ conf -> gen .name , (int )conf -> boot_val );
2700+ * conf -> variable = conf -> reset_val = conf -> boot_val ;
27012701break ;
27022702}
27032703case PGC_INT :
27042704{
27052705struct config_int * conf = (struct config_int * )gconf ;
27062706
2707- Assert (conf -> reset_val >=conf -> min );
2708- Assert (conf -> reset_val <=conf -> max );
2709- if (conf -> assign_hook )
2710- if ( !(* conf -> assign_hook ) (conf -> reset_val , true,
2711- PGC_S_DEFAULT ))
2712- elog (FATAL ,"failed to initialize %s to %d" ,
2713- conf -> gen .name ,conf -> reset_val );
2714- * conf -> variable = conf -> reset_val ;
2707+ Assert (conf -> boot_val >=conf -> min );
2708+ Assert (conf -> boot_val <=conf -> max );
2709+ if (conf -> assign_hook &&
2710+ !(* conf -> assign_hook ) (conf -> boot_val , true,
2711+ PGC_S_DEFAULT ))
2712+ elog (FATAL ,"failed to initialize %s to %d" ,
2713+ conf -> gen .name ,conf -> boot_val );
2714+ * conf -> variable = conf -> reset_val = conf -> boot_val ;
27152715break ;
27162716}
27172717case PGC_REAL :
27182718{
27192719struct config_real * conf = (struct config_real * )gconf ;
27202720
2721- Assert (conf -> reset_val >=conf -> min );
2722- Assert (conf -> reset_val <=conf -> max );
2723- if (conf -> assign_hook )
2724- if ( !(* conf -> assign_hook ) (conf -> reset_val , true,
2725- PGC_S_DEFAULT ))
2726- elog (FATAL ,"failed to initialize %s to %g" ,
2727- conf -> gen .name ,conf -> reset_val );
2728- * conf -> variable = conf -> reset_val ;
2721+ Assert (conf -> boot_val >=conf -> min );
2722+ Assert (conf -> boot_val <=conf -> max );
2723+ if (conf -> assign_hook &&
2724+ !(* conf -> assign_hook ) (conf -> boot_val , true,
2725+ PGC_S_DEFAULT ))
2726+ elog (FATAL ,"failed to initialize %s to %g" ,
2727+ conf -> gen .name ,conf -> boot_val );
2728+ * conf -> variable = conf -> reset_val = conf -> boot_val ;
27292729break ;
27302730}
27312731case PGC_STRING :
@@ -2738,10 +2738,8 @@ InitializeGUCOptions(void)
27382738conf -> tentative_val = NULL ;
27392739
27402740if (conf -> boot_val == NULL )
2741- {
27422741/* Cannot set value yet */
27432742break ;
2744- }
27452743
27462744str = guc_strdup (FATAL ,conf -> boot_val );
27472745conf -> reset_val = str ;
@@ -2753,10 +2751,8 @@ InitializeGUCOptions(void)
27532751newstr = (* conf -> assign_hook ) (str , true,
27542752PGC_S_DEFAULT );
27552753if (newstr == NULL )
2756- {
27572754elog (FATAL ,"failed to initialize %s to \"%s\"" ,
27582755conf -> gen .name ,str );
2759- }
27602756else if (newstr != str )
27612757{
27622758free (str );
@@ -2796,12 +2792,10 @@ InitializeGUCOptions(void)
27962792if (env != NULL )
27972793SetConfigOption ("port" ,env ,PGC_POSTMASTER ,PGC_S_ENV_VAR );
27982794
2799- env = getenv ("PGDATESTYLE" );
2800- if (env != NULL )
2795+ if ((env = getenv ("PGDATESTYLE" ))!= NULL )
28012796SetConfigOption ("datestyle" ,env ,PGC_POSTMASTER ,PGC_S_ENV_VAR );
28022797
2803- env = getenv ("PGCLIENTENCODING" );
2804- if (env != NULL )
2798+ if ((env = getenv ("PGCLIENTENCODING" ))!= NULL )
28052799SetConfigOption ("client_encoding" ,env ,PGC_POSTMASTER ,PGC_S_ENV_VAR );
28062800}
28072801
@@ -3178,7 +3172,7 @@ AtEOXact_GUC(bool isCommit, bool isSubXact)
31783172for (i = 0 ;i < num_guc_variables ;i ++ )
31793173{
31803174struct config_generic * gconf = guc_variables [i ];
3181- int my_status = gconf -> status ;
3175+ int my_status = gconf -> status & (~ GUC_IN_CONFFILE ) ;
31823176GucStack * stack = gconf -> stack ;
31833177bool useTentative ;
31843178bool changed ;
@@ -3723,12 +3717,22 @@ parse_value(int elevel, const struct config_generic *record,
37233717}
37243718else
37253719{
3726- newval = conf -> reset_val ;
3727- * source = conf -> gen .reset_source ;
3720+ /*
3721+ * Revert value to default if source is configuration file. It is used when
3722+ * configuration parameter is removed/commented out in the config file. Else
3723+ * RESET or SET TO DEFAULT command is called and reset_val is used.
3724+ */
3725+ if (* source == PGC_S_FILE )
3726+ newval = conf -> boot_val ;
3727+ else
3728+ {
3729+ newval = conf -> reset_val ;
3730+ * source = conf -> gen .reset_source ;
3731+ }
37283732}
37293733
3730- if (conf -> assign_hook )
3731- if ( !(* conf -> assign_hook ) (newval ,changeVal ,* source ))
3734+ if (conf -> assign_hook &&
3735+ !(* conf -> assign_hook ) (newval ,changeVal ,* source ))
37323736{
37333737ereport (elevel ,
37343738(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
@@ -3767,8 +3771,18 @@ parse_value(int elevel, const struct config_generic *record,
37673771}
37683772else
37693773{
3770- newval = conf -> reset_val ;
3771- * source = conf -> gen .reset_source ;
3774+ /*
3775+ * Revert value to default if source is configuration file. It is used when
3776+ * configuration parameter is removed/commented out in the config file. Else
3777+ * RESET or SET TO DEFAULT command is called and reset_val is used.
3778+ */
3779+ if (* source == PGC_S_FILE )
3780+ newval = conf -> boot_val ;
3781+ else
3782+ {
3783+ newval = conf -> reset_val ;
3784+ * source = conf -> gen .reset_source ;
3785+ }
37723786}
37733787
37743788if (conf -> assign_hook )
@@ -3811,12 +3825,22 @@ parse_value(int elevel, const struct config_generic *record,
38113825}
38123826else
38133827{
3814- newval = conf -> reset_val ;
3815- * source = conf -> gen .reset_source ;
3828+ /*
3829+ * Revert value to default if source is configuration file. It is used when
3830+ * configuration parameter is removed/commented out in the config file. Else
3831+ * RESET or SET TO DEFAULT command is called and reset_val is used.
3832+ */
3833+ if (* source == PGC_S_FILE )
3834+ newval = conf -> boot_val ;
3835+ else
3836+ {
3837+ newval = conf -> reset_val ;
3838+ * source = conf -> gen .reset_source ;
3839+ }
38163840}
38173841
3818- if (conf -> assign_hook )
3819- if ( !(* conf -> assign_hook ) (newval ,changeVal ,* source ))
3842+ if (conf -> assign_hook &&
3843+ !(* conf -> assign_hook ) (newval ,changeVal ,* source ))
38203844{
38213845ereport (elevel ,
38223846(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
@@ -3845,6 +3869,18 @@ parse_value(int elevel, const struct config_generic *record,
38453869if (conf -> gen .flags & GUC_IS_NAME )
38463870truncate_identifier (newval ,strlen (newval ), true);
38473871}
3872+ else if (* source == PGC_S_FILE )
3873+ {
3874+ /* Revert value to default when item is removed from config file. */
3875+ if (conf -> boot_val != NULL )
3876+ {
3877+ newval = guc_strdup (elevel ,conf -> boot_val );
3878+ if (newval == NULL )
3879+ return false;
3880+ }
3881+ else
3882+ return false;
3883+ }
38483884else if (conf -> reset_val )
38493885{
38503886/*
@@ -3856,10 +3892,8 @@ parse_value(int elevel, const struct config_generic *record,
38563892* source = conf -> gen .reset_source ;
38573893}
38583894else
3859- {
38603895/* Nothing to reset to, as yet; so do nothing */
38613896break ;
3862- }
38633897
38643898if (conf -> assign_hook )
38653899{
@@ -4047,6 +4081,13 @@ verify_config_option(const char *name, const char *value,
40474081
40484082if (parse_value (elevel ,record ,value ,& source , false,NULL ))
40494083{
4084+ /*
4085+ * Mark record like presented in the config file. Be carefull if
4086+ * you use this function for another purpose than config file
4087+ * verification. It causes confusion configfile parser.
4088+ */
4089+ record -> status |=GUC_IN_CONFFILE ;
4090+
40504091if (isNewEqual != NULL )
40514092* isNewEqual = is_newvalue_equal (record ,value );
40524093if (isContextOK != NULL )
@@ -4109,7 +4150,8 @@ set_config_option(const char *name, const char *value,
41094150 * Should we set reset/stacked values?(If so, the behavior is not
41104151 * transactional.)
41114152 */
4112- makeDefault = changeVal && (source <=PGC_S_OVERRIDE )&& (value != NULL );
4153+ makeDefault = changeVal && (source <=PGC_S_OVERRIDE )&&
4154+ (value != NULL || source == PGC_S_FILE );
41134155
41144156/*
41154157 * Ignore attempted set if overridden by previously processed setting.