summaryrefslogtreecommitdiff
path: root/src/bin/initdb/initdb.c
diff options
context:
space:
mode:
authorTom Lane2024-03-04 17:00:39 +0000
committerTom Lane2024-03-04 17:00:48 +0000
commitfce2ce797c412df8b794b8a92c5a586db5e1bedc (patch)
tree10a469099c53f749c569a180e37ff063da88947f /src/bin/initdb/initdb.c
parenta0b808baef39e9f9465b7f63f2d735f35852aa21 (diff)
Fix initdb's -c option to treat the GUC name case-insensitively.
The backend treats GUC names case-insensitively, so this code should too. This avoids ending up with a confusing set of redundant entries in the generated postgresql.conf file. Per report from Kyotaro Horiguchi. Back-patch to v16 where this feature was added (in commit 3e51b278d). Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/bin/initdb/initdb.c')
-rw-r--r--src/bin/initdb/initdb.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index ac409b00064..200b2e8e317 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -484,6 +484,7 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
for (i = 0; lines[i]; i++)
{
const char *where;
+ const char *namestart;
/*
* Look for a line assigning to guc_name. Typically it will be
@@ -494,15 +495,19 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
where = lines[i];
while (*where == '#' || isspace((unsigned char) *where))
where++;
- if (strncmp(where, guc_name, namelen) != 0)
+ if (pg_strncasecmp(where, guc_name, namelen) != 0)
continue;
+ namestart = where;
where += namelen;
while (isspace((unsigned char) *where))
where++;
if (*where != '=')
continue;
- /* found it -- append the original comment if any */
+ /* found it -- let's use the canonical casing shown in the file */
+ memcpy(&newline->data[mark_as_comment ? 1 : 0], namestart, namelen);
+
+ /* now append the original comment if any */
where = strrchr(where, '#');
if (where)
{