Common function for percent placeholder replacement

From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Common function for percent placeholder replacement
Date: 2022-12-14 07:31:02
Message-ID: 5238bbed-0b01-83a6-d4b2-7eb0562a054e@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

There are a number of places where a shell command is constructed with
percent-placeholders (like %x). First, it's obviously cumbersome to
have to open-code this several times. Second, each of those pieces of
code silently encodes some edge case behavior, such as what to do with
unrecognized placeholders. (I remember when I last did one of these, I
stared very hard at the existing code instances to figure out what they
would do.) We now also have a newer instance in basebackup_to_shell.c
that has different behavior in such cases. (Maybe it's better, but it
would be good to be explicit and consistent about this.)

This patch factors out this logic into a separate function. I have
documented to "old" error handling (which is to not handle them) and
brutally converted basebackup_to_shell.c to use that. We could also
adopt the new behavior; now there is only a single place to change for that.

Note that this is only used for shell commands with placeholders, not
for other places with placeholders, such as prompts and log line
prefixes, which would (IMO) need a different API that wouldn't be quite
as compact. This is explained in the code comments.

Attachment Content-Type Size
v1-0001-Common-function-for-percent-placeholder-replaceme.patch text/plain 16.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nitin Jadhav 2022-12-14 07:31:49 Inconsistency in reporting checkpointer stats
Previous Message Peter Eisentraut 2022-12-14 07:04:29 Re: pg_upgrade: Make testing different transfer modes easier