diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 4272d386e64..38422becc48 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -6050,6 +6050,18 @@ next_file: 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) { diff --git a/src/interfaces/libpq/t/006_service.pl b/src/interfaces/libpq/t/006_service.pl index 7462d21314d..8e29880731f 100644 --- a/src/interfaces/libpq/t/006_service.pl +++ b/src/interfaces/libpq/t/006_service.pl @@ -143,6 +143,14 @@ local $ENV{PGSERVICEFILE} = "$srvfile_empty"; 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( '',