10
10
* Written by Peter Eisentraut <peter_e@gmx.net>.
11
11
*
12
12
* IDENTIFICATION
13
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.338 2006/08/13 01:30:17 momjian Exp $
13
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.339 2006/08/13 02:22:24 momjian Exp $
14
14
*
15
15
*--------------------------------------------------------------------
16
16
*/
@@ -2692,40 +2692,40 @@ InitializeGUCOptions(void)
2692
2692
{
2693
2693
struct config_bool * conf = (struct config_bool * ) gconf ;
2694
2694
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 ;
2701
2701
break ;
2702
2702
}
2703
2703
case PGC_INT :
2704
2704
{
2705
2705
struct config_int * conf = (struct config_int * ) gconf ;
2706
2706
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 ;
2715
2715
break ;
2716
2716
}
2717
2717
case PGC_REAL :
2718
2718
{
2719
2719
struct config_real * conf = (struct config_real * ) gconf ;
2720
2720
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 ;
2729
2729
break ;
2730
2730
}
2731
2731
case PGC_STRING :
@@ -2738,10 +2738,8 @@ InitializeGUCOptions(void)
2738
2738
conf -> tentative_val = NULL ;
2739
2739
2740
2740
if (conf -> boot_val == NULL )
2741
- {
2742
2741
/* Cannot set value yet */
2743
2742
break ;
2744
- }
2745
2743
2746
2744
str = guc_strdup (FATAL , conf -> boot_val );
2747
2745
conf -> reset_val = str ;
@@ -2753,10 +2751,8 @@ InitializeGUCOptions(void)
2753
2751
newstr = (* conf -> assign_hook ) (str , true,
2754
2752
PGC_S_DEFAULT );
2755
2753
if (newstr == NULL )
2756
- {
2757
2754
elog (FATAL , "failed to initialize %s to \"%s\"" ,
2758
2755
conf -> gen .name , str );
2759
- }
2760
2756
else if (newstr != str )
2761
2757
{
2762
2758
free (str );
@@ -2796,12 +2792,10 @@ InitializeGUCOptions(void)
2796
2792
if (env != NULL )
2797
2793
SetConfigOption ("port" , env , PGC_POSTMASTER , PGC_S_ENV_VAR );
2798
2794
2799
- env = getenv ("PGDATESTYLE" );
2800
- if (env != NULL )
2795
+ if ((env = getenv ("PGDATESTYLE" )) != NULL )
2801
2796
SetConfigOption ("datestyle" , env , PGC_POSTMASTER , PGC_S_ENV_VAR );
2802
2797
2803
- env = getenv ("PGCLIENTENCODING" );
2804
- if (env != NULL )
2798
+ if ((env = getenv ("PGCLIENTENCODING" )) != NULL )
2805
2799
SetConfigOption ("client_encoding" , env , PGC_POSTMASTER , PGC_S_ENV_VAR );
2806
2800
}
2807
2801
@@ -3178,7 +3172,7 @@ AtEOXact_GUC(bool isCommit, bool isSubXact)
3178
3172
for (i = 0 ; i < num_guc_variables ; i ++ )
3179
3173
{
3180
3174
struct config_generic * gconf = guc_variables [i ];
3181
- int my_status = gconf -> status ;
3175
+ int my_status = gconf -> status & (~ GUC_IN_CONFFILE ) ;
3182
3176
GucStack * stack = gconf -> stack ;
3183
3177
bool useTentative ;
3184
3178
bool changed ;
@@ -3723,12 +3717,22 @@ parse_value(int elevel, const struct config_generic *record,
3723
3717
}
3724
3718
else
3725
3719
{
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
+ }
3728
3732
}
3729
3733
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 ))
3732
3736
{
3733
3737
ereport (elevel ,
3734
3738
(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
@@ -3767,8 +3771,18 @@ parse_value(int elevel, const struct config_generic *record,
3767
3771
}
3768
3772
else
3769
3773
{
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
+ }
3772
3786
}
3773
3787
3774
3788
if (conf -> assign_hook )
@@ -3811,12 +3825,22 @@ parse_value(int elevel, const struct config_generic *record,
3811
3825
}
3812
3826
else
3813
3827
{
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
+ }
3816
3840
}
3817
3841
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 ))
3820
3844
{
3821
3845
ereport (elevel ,
3822
3846
(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
@@ -3845,6 +3869,18 @@ parse_value(int elevel, const struct config_generic *record,
3845
3869
if (conf -> gen .flags & GUC_IS_NAME )
3846
3870
truncate_identifier (newval , strlen (newval ), true);
3847
3871
}
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
+ }
3848
3884
else if (conf -> reset_val )
3849
3885
{
3850
3886
/*
@@ -3856,10 +3892,8 @@ parse_value(int elevel, const struct config_generic *record,
3856
3892
* source = conf -> gen .reset_source ;
3857
3893
}
3858
3894
else
3859
- {
3860
3895
/* Nothing to reset to, as yet; so do nothing */
3861
3896
break ;
3862
- }
3863
3897
3864
3898
if (conf -> assign_hook )
3865
3899
{
@@ -4047,6 +4081,13 @@ verify_config_option(const char *name, const char *value,
4047
4081
4048
4082
if (parse_value (elevel , record , value , & source , false, NULL ))
4049
4083
{
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
+
4050
4091
if (isNewEqual != NULL )
4051
4092
* isNewEqual = is_newvalue_equal (record , value );
4052
4093
if (isContextOK != NULL )
@@ -4109,7 +4150,8 @@ set_config_option(const char *name, const char *value,
4109
4150
* Should we set reset/stacked values? (If so, the behavior is not
4110
4151
* transactional.)
4111
4152
*/
4112
- makeDefault = changeVal && (source <= PGC_S_OVERRIDE ) && (value != NULL );
4153
+ makeDefault = changeVal && (source <= PGC_S_OVERRIDE ) &&
4154
+ (value != NULL || source == PGC_S_FILE );
4113
4155
4114
4156
/*
4115
4157
* Ignore attempted set if overridden by previously processed setting.
0 commit comments