When "servicefile" is specified in a connection string but the requested
service is not found in this file, libpq falls back to a default file,
pg_service.conf in PGSYSCONFDIR. The "servicefile" option was missing
an update in this case, causing an incorrect value to be reported,
impacting SERVICEFILE in psql, for example.
An extra update of the option is added in this commit, based on the
actual file where the service name has been found. A test is added to
cover this problem.
Oversight in
092f3c63efc6.
Author: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/
59DD1652-4EB5-449B-8DE3-
959F06561A96@gmail.com
if (status != 0)
return status;
+ /* Update servicefile to the file that actually supplied the service */
+ if (group_found && service_fname != NULL &&
+ conninfo_storeval(options, "servicefile", serviceFile,
+ errorMessage, false, false) == NULL)
+ {
+ /*
+ * conninfo_storeval already set an error message, that could be only
+ * an OOM.
+ */
+ return 3;
+ }
+
last_file:
if (!group_found)
{
sql => "SELECT 'connect2_3'",
expected_stdout => qr/connect2_3/);
+ my $srvfile_empty_win_cared = $srvfile_empty;
+ $srvfile_empty_win_cared =~ s/\\/\\\\/g;
+ $dummy_node->connect_ok(
+ q{service=my_srv servicefile='} . $srvfile_empty_win_cared . q{'},
+ 'SERVICEFILE updated when service is found in default pg_service.conf',
+ sql => '\echo :SERVICEFILE',
+ expected_stdout => qr/^\Q$srvfile_default\E$/);
+
local $ENV{PGSERVICE} = 'undefined-service';
$dummy_node->connect_fails(
'',