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

Commit f3f06b1

Browse files
committed
Apply GUC name from central table in more places of guc.c
The name extracted from the record of the GUC tables is applied to more internal places of guc.c. This change has the advantage to simplify parse_and_validate_value(), where the "name" was only used in elog messages, while it was required to match with the name from the GUC record. pg_parameter_aclcheck() now passes the name of the GUC from its record in two places rather than the caller's argument. The value given to this function goes through convert_GUC_name_for_parameter_acl() that does a simple ASCII downcasing. Few GUCs mix character casing in core; one test is added for one of these code paths with "IntervalStyle". Author: Peter Smith, Michael Paquier Discussion: https://postgr.es/m/ZwNh4vkc2NHJHnND@paquier.xyz
1 parent 67a54b9 commit f3f06b1

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

src/backend/utils/misc/guc.c

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,7 +3115,6 @@ config_enum_get_options(struct config_enum *record, const char *prefix,
31153115
* and also calls any check hook the parameter may have.
31163116
*
31173117
* record: GUC variable's info record
3118-
* name: variable name (should match the record of course)
31193118
* value: proposed value, as a string
31203119
* source: identifies source of value (check hooks may need this)
31213120
* elevel: level to log any error reports at
@@ -3127,7 +3126,7 @@ config_enum_get_options(struct config_enum *record, const char *prefix,
31273126
*/
31283127
static bool
31293128
parse_and_validate_value(struct config_generic *record,
3130-
const char *name, const char *value,
3129+
const char *value,
31313130
GucSource source, int elevel,
31323131
union config_var_val *newval, void **newextra)
31333132
{
@@ -3142,7 +3141,7 @@ parse_and_validate_value(struct config_generic *record,
31423141
ereport(elevel,
31433142
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
31443143
errmsg("parameter \"%s\" requires a Boolean value",
3145-
name)));
3144+
conf->gen.name)));
31463145
return false;
31473146
}
31483147

@@ -3162,7 +3161,7 @@ parse_and_validate_value(struct config_generic *record,
31623161
ereport(elevel,
31633162
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
31643163
errmsg("invalid value for parameter \"%s\": \"%s\"",
3165-
name, value),
3164+
conf->gen.name, value),
31663165
hintmsg ? errhint("%s", _(hintmsg)) : 0));
31673166
return false;
31683167
}
@@ -3181,7 +3180,7 @@ parse_and_validate_value(struct config_generic *record,
31813180
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
31823181
errmsg("%d%s%s is outside the valid range for parameter \"%s\" (%d%s%s .. %d%s%s)",
31833182
newval->intval, unitspace, unit,
3184-
name,
3183+
conf->gen.name,
31853184
conf->min, unitspace, unit,
31863185
conf->max, unitspace, unit)));
31873186
return false;
@@ -3203,7 +3202,7 @@ parse_and_validate_value(struct config_generic *record,
32033202
ereport(elevel,
32043203
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
32053204
errmsg("invalid value for parameter \"%s\": \"%s\"",
3206-
name, value),
3205+
conf->gen.name, value),
32073206
hintmsg ? errhint("%s", _(hintmsg)) : 0));
32083207
return false;
32093208
}
@@ -3222,7 +3221,7 @@ parse_and_validate_value(struct config_generic *record,
32223221
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
32233222
errmsg("%g%s%s is outside the valid range for parameter \"%s\" (%g%s%s .. %g%s%s)",
32243223
newval->realval, unitspace, unit,
3225-
name,
3224+
conf->gen.name,
32263225
conf->min, unitspace, unit,
32273226
conf->max, unitspace, unit)));
32283227
return false;
@@ -3278,7 +3277,7 @@ parse_and_validate_value(struct config_generic *record,
32783277
ereport(elevel,
32793278
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
32803279
errmsg("invalid value for parameter \"%s\": \"%s\"",
3281-
name, value),
3280+
conf->gen.name, value),
32823281
hintmsg ? errhint("%s", _(hintmsg)) : 0));
32833282

32843283
if (hintmsg)
@@ -3460,7 +3459,7 @@ set_config_with_handle(const char *name, config_handle *handle,
34603459
ereport(elevel,
34613460
(errcode(ERRCODE_INVALID_TRANSACTION_STATE),
34623461
errmsg("parameter \"%s\" cannot be set during a parallel operation",
3463-
name)));
3462+
record->name)));
34643463
return 0;
34653464
}
34663465

@@ -3476,7 +3475,7 @@ set_config_with_handle(const char *name, config_handle *handle,
34763475
ereport(elevel,
34773476
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
34783477
errmsg("parameter \"%s\" cannot be changed",
3479-
name)));
3478+
record->name)));
34803479
return 0;
34813480
}
34823481
break;
@@ -3499,7 +3498,7 @@ set_config_with_handle(const char *name, config_handle *handle,
34993498
ereport(elevel,
35003499
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
35013500
errmsg("parameter \"%s\" cannot be changed without restarting the server",
3502-
name)));
3501+
record->name)));
35033502
return 0;
35043503
}
35053504
break;
@@ -3509,7 +3508,7 @@ set_config_with_handle(const char *name, config_handle *handle,
35093508
ereport(elevel,
35103509
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
35113510
errmsg("parameter \"%s\" cannot be changed now",
3512-
name)));
3511+
record->name)));
35133512
return 0;
35143513
}
35153514

@@ -3529,14 +3528,14 @@ set_config_with_handle(const char *name, config_handle *handle,
35293528
*/
35303529
AclResult aclresult;
35313530

3532-
aclresult = pg_parameter_aclcheck(name, srole, ACL_SET);
3531+
aclresult = pg_parameter_aclcheck(record->name, srole, ACL_SET);
35333532
if (aclresult != ACLCHECK_OK)
35343533
{
35353534
/* No granted privilege */
35363535
ereport(elevel,
35373536
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
35383537
errmsg("permission denied to set parameter \"%s\"",
3539-
name)));
3538+
record->name)));
35403539
return 0;
35413540
}
35423541
}
@@ -3578,7 +3577,7 @@ set_config_with_handle(const char *name, config_handle *handle,
35783577
ereport(elevel,
35793578
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
35803579
errmsg("parameter \"%s\" cannot be set after connection start",
3581-
name)));
3580+
record->name)));
35823581
return 0;
35833582
}
35843583
break;
@@ -3591,14 +3590,14 @@ set_config_with_handle(const char *name, config_handle *handle,
35913590
*/
35923591
AclResult aclresult;
35933592

3594-
aclresult = pg_parameter_aclcheck(name, srole, ACL_SET);
3593+
aclresult = pg_parameter_aclcheck(record->name, srole, ACL_SET);
35953594
if (aclresult != ACLCHECK_OK)
35963595
{
35973596
/* No granted privilege */
35983597
ereport(elevel,
35993598
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
36003599
errmsg("permission denied to set parameter \"%s\"",
3601-
name)));
3600+
record->name)));
36023601
return 0;
36033602
}
36043603
}
@@ -3637,15 +3636,15 @@ set_config_with_handle(const char *name, config_handle *handle,
36373636
ereport(elevel,
36383637
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
36393638
errmsg("cannot set parameter \"%s\" within security-definer function",
3640-
name)));
3639+
record->name)));
36413640
return 0;
36423641
}
36433642
if (InSecurityRestrictedOperation())
36443643
{
36453644
ereport(elevel,
36463645
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
36473646
errmsg("cannot set parameter \"%s\" within security-restricted operation",
3648-
name)));
3647+
record->name)));
36493648
return 0;
36503649
}
36513650
}
@@ -3657,15 +3656,15 @@ set_config_with_handle(const char *name, config_handle *handle,
36573656
{
36583657
ereport(elevel,
36593658
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3660-
errmsg("parameter \"%s\" cannot be reset", name)));
3659+
errmsg("parameter \"%s\" cannot be reset", record->name)));
36613660
return 0;
36623661
}
36633662
if (action == GUC_ACTION_SAVE)
36643663
{
36653664
ereport(elevel,
36663665
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
36673666
errmsg("parameter \"%s\" cannot be set locally in functions",
3668-
name)));
3667+
record->name)));
36693668
return 0;
36703669
}
36713670
}
@@ -3691,7 +3690,7 @@ set_config_with_handle(const char *name, config_handle *handle,
36913690
if (changeVal && !makeDefault)
36923691
{
36933692
elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
3694-
name);
3693+
record->name);
36953694
return -1;
36963695
}
36973696
changeVal = false;
@@ -3710,7 +3709,7 @@ set_config_with_handle(const char *name, config_handle *handle,
37103709

37113710
if (value)
37123711
{
3713-
if (!parse_and_validate_value(record, name, value,
3712+
if (!parse_and_validate_value(record, value,
37143713
source, elevel,
37153714
&newval_union, &newextra))
37163715
return 0;
@@ -3743,7 +3742,7 @@ set_config_with_handle(const char *name, config_handle *handle,
37433742
ereport(elevel,
37443743
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
37453744
errmsg("parameter \"%s\" cannot be changed without restarting the server",
3746-
name)));
3745+
conf->gen.name)));
37473746
return 0;
37483747
}
37493748
record->status &= ~GUC_PENDING_RESTART;
@@ -3808,7 +3807,7 @@ set_config_with_handle(const char *name, config_handle *handle,
38083807

38093808
if (value)
38103809
{
3811-
if (!parse_and_validate_value(record, name, value,
3810+
if (!parse_and_validate_value(record, value,
38123811
source, elevel,
38133812
&newval_union, &newextra))
38143813
return 0;
@@ -3841,7 +3840,7 @@ set_config_with_handle(const char *name, config_handle *handle,
38413840
ereport(elevel,
38423841
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
38433842
errmsg("parameter \"%s\" cannot be changed without restarting the server",
3844-
name)));
3843+
conf->gen.name)));
38453844
return 0;
38463845
}
38473846
record->status &= ~GUC_PENDING_RESTART;
@@ -3906,7 +3905,7 @@ set_config_with_handle(const char *name, config_handle *handle,
39063905

39073906
if (value)
39083907
{
3909-
if (!parse_and_validate_value(record, name, value,
3908+
if (!parse_and_validate_value(record, value,
39103909
source, elevel,
39113910
&newval_union, &newextra))
39123911
return 0;
@@ -3939,7 +3938,7 @@ set_config_with_handle(const char *name, config_handle *handle,
39393938
ereport(elevel,
39403939
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
39413940
errmsg("parameter \"%s\" cannot be changed without restarting the server",
3942-
name)));
3941+
conf->gen.name)));
39433942
return 0;
39443943
}
39453944
record->status &= ~GUC_PENDING_RESTART;
@@ -4004,7 +4003,7 @@ set_config_with_handle(const char *name, config_handle *handle,
40044003

40054004
if (value)
40064005
{
4007-
if (!parse_and_validate_value(record, name, value,
4006+
if (!parse_and_validate_value(record, value,
40084007
source, elevel,
40094008
&newval_union, &newextra))
40104009
return 0;
@@ -4063,7 +4062,7 @@ set_config_with_handle(const char *name, config_handle *handle,
40634062
ereport(elevel,
40644063
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
40654064
errmsg("parameter \"%s\" cannot be changed without restarting the server",
4066-
name)));
4065+
conf->gen.name)));
40674066
return 0;
40684067
}
40694068
record->status &= ~GUC_PENDING_RESTART;
@@ -4133,7 +4132,7 @@ set_config_with_handle(const char *name, config_handle *handle,
41334132

41344133
if (value)
41354134
{
4136-
if (!parse_and_validate_value(record, name, value,
4135+
if (!parse_and_validate_value(record, value,
41374136
source, elevel,
41384137
&newval_union, &newextra))
41394138
return 0;
@@ -4166,7 +4165,7 @@ set_config_with_handle(const char *name, config_handle *handle,
41664165
ereport(elevel,
41674166
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
41684167
errmsg("parameter \"%s\" cannot be changed without restarting the server",
4169-
name)));
4168+
conf->gen.name)));
41704169
return 0;
41714170
}
41724171
record->status &= ~GUC_PENDING_RESTART;
@@ -4660,7 +4659,7 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
46604659
union config_var_val newval;
46614660
void *newextra = NULL;
46624661

4663-
if (!parse_and_validate_value(record, name, value,
4662+
if (!parse_and_validate_value(record, value,
46644663
PGC_S_FILE, ERROR,
46654664
&newval, &newextra))
46664665
ereport(ERROR,

src/test/regress/expected/guc.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ SHOW datestyle;
66
Postgres, MDY
77
(1 row)
88

9+
-- Check output style of CamelCase enum options
10+
SET intervalstyle to 'asd';
11+
ERROR: invalid value for parameter "IntervalStyle": "asd"
12+
HINT: Available values: postgres, postgres_verbose, sql_standard, iso_8601.
913
-- SET to some nondefault value
1014
SET vacuum_cost_delay TO 40;
1115
SET datestyle = 'ISO, YMD';

src/test/regress/sql/guc.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
-- we can't rely on any specific default value of vacuum_cost_delay
33
SHOW datestyle;
44

5+
-- Check output style of CamelCase enum options
6+
SET intervalstyle to 'asd';
7+
58
-- SET to some nondefault value
69
SET vacuum_cost_delay TO 40;
710
SET datestyle = 'ISO, YMD';

0 commit comments

Comments
 (0)