Re: Allow escape in application_name

Kyotaro Horiguchi <horikyota.ntt@gmail.com>

From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: kuroda.hayato@fujitsu.com
Cc: houzj.fnst@fujitsu.com, ikedamsh@oss.nttdata.com, pgsql-hackers@lists.postgresql.org, tgl@sss.pgh.pa.us, masao.fujii@oss.nttdata.com
Date: 2021-09-13T07:12:47Z
Lists: pgsql-hackers
At Fri, 10 Sep 2021 04:33:53 +0000, "kuroda.hayato@fujitsu.com" <kuroda.hayato@fujitsu.com> wrote in 
> Dear Hou,
> 
> > I found one minor thing in the patch.
> 
> Thanks!
> 
> > Is it better to use Abs(padding) here ?
> > Although some existing codes are using " padding > 0 ? padding : -padding ".
> 
> +1, fixed.
> 
> And I found that some comments were not added above padding calculation,
> so added.

Thanks for the new version.  I don't object for reusing
process_log_prefix_padding, but I still find it strange that the
function with the name 'process_padding' is in string.c.  If we move
it to string.c, I'd like to name it "pg_fast_strtoi" or something and
change the interface to int pg_fast_strtoi(const char *p, char
**endptr) that is (roughly) compatible to strtol.  What do (both) you
think about this?


+		/*
+		 * Search application_name and replace it if found.
+		 *
+		 * We search paramters from the end because the later
+		 * one have higher priority.  See also the above comment.
+		 */
+		for (i = n - 1; i >= 0; i--)
+		{
+			if (strcmp(keywords[i], "application_name") == 0)
+			{
+				parse_pgfdw_appname(&buf, values[i]);
+				values[i] = buf.data;
+
+				/*
+				 * If the input format is wrong and the string becomes '\0',
+				 * this parameter is no longer used.
+				 * We conitnue searching application_name.
+				 */
+				if (*values[i] != '\0')
+					break;
+			}
+		}

I didn't fully checked in what case parse_pgfdw_appname gives "" as
result, I feel that we should use the original value in that
case. That is,

>  parse_pgfdw_appname(&buf, vaues[i]);
>
>  /* use the result if any, otherwise use the original string */
>  if (buf.data[0] != 0)
>     values[i] = buf.data;
>
>  /* break if it results in non-empty string */
>  if (values[0][0] != 0)
>     break;

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center



Commits

  1. postgres_fdw: Add regression test for postgres_fdw.application_name GUC.

  2. postgres_fdw: Allow postgres_fdw.application_name to include escape sequences.

  3. doc: Add note about postgres_fdw.application_name.

  4. postgres_fdw: Revert unstable tests for postgres_fdw.application_name.

  5. postgres_fdw: Allow application_name of remote connection to be set via GUC.