v2-0002-Avoid-use-of-Perl-getprotobyname.patch

text/plain

Filename: v2-0002-Avoid-use-of-Perl-getprotobyname.patch
Type: text/plain
Part: 1
Message: Re: Make all Perl warnings fatal

Patch

Format: format-patch
Series: patch v2-0002
Subject: Avoid use of Perl getprotobyname
File+
src/test/perl/PostgreSQL/Test/Cluster.pm 1 2
From 54a5904e38d533d8dbf492d0f1f19674cbcf3d39 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 1 Aug 2023 13:43:34 +0200
Subject: [PATCH v2] Avoid use of Perl getprotobyname

getprotobyname returns undefined on some CI machines.  It's not clear
why.  The code overall still works, but it raises a warning.

In PostgreSQL C code, we always call socket() with 0 for the protocol
argument, so we should be able to do the same in Perl (since the Perl
documentation says that the arguments of the socket function are the
same as in C).  So do that, to avoid the issue.
---
 src/test/perl/PostgreSQL/Test/Cluster.pm | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm
index 3fa679ff97..ea6cbe5703 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -1570,9 +1570,8 @@ sub can_bind
 	my ($host, $port) = @_;
 	my $iaddr = inet_aton($host);
 	my $paddr = sockaddr_in($port, $iaddr);
-	my $proto = getprotobyname("tcp");
 
-	socket(SOCK, PF_INET, SOCK_STREAM, $proto)
+	socket(SOCK, PF_INET, SOCK_STREAM, 0)
 	  or die "socket failed: $!";
 
 	# As in postmaster, don't use SO_REUSEADDR on Windows
-- 
2.41.0