From 195cde040271967c6566d327cef1e01f9f4d178c Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Sun, 24 Jul 2022 00:03:41 +1200
Subject: [PATCH 09/13] Remove configure probes for poll and poll.h.

poll() and <poll.h> are in SUSv2 (XSI) and all targeted Unix systems
have them.  Wherever we test HAVE_POLL or HAVE_POLL_H, we really mean
'not Windows' and alternative paths are not being tested on Unix.
---
 configure                       | 4 ++--
 configure.ac                    | 2 --
 src/backend/libpq/pqcomm.c      | 2 +-
 src/backend/storage/ipc/latch.c | 8 +++-----
 src/backend/utils/misc/guc.c    | 2 +-
 src/bin/pgbench/pgbench.c       | 2 --
 src/include/pg_config.h.in      | 6 ------
 src/interfaces/libpq/fe-misc.c  | 8 ++++----
 src/tools/msvc/Solution.pm      | 2 --
 9 files changed, 11 insertions(+), 25 deletions(-)

diff --git a/configure b/configure
index b6094c1a62..98affa21dd 100755
--- a/configure
+++ b/configure
@@ -13875,7 +13875,7 @@ $as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
 fi
 
 
-for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/event.h sys/ipc.h sys/personality.h sys/prctl.h sys/procctl.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/signalfd.h sys/sockio.h sys/uio.h sys/un.h termios.h ucred.h
+for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h langinfo.h mbarrier.h sys/epoll.h sys/event.h sys/ipc.h sys/personality.h sys/prctl.h sys/procctl.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/signalfd.h sys/sockio.h sys/uio.h sys/un.h termios.h ucred.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
@@ -16039,7 +16039,7 @@ fi
 LIBS_including_readline="$LIBS"
 LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
 
-for ac_func in backtrace_symbols copyfile fdatasync getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s poll posix_fallocate ppoll pthread_is_threaded_np readv setproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range uselocale wcstombs_l writev
+for ac_func in backtrace_symbols copyfile fdatasync getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np readv setproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range uselocale wcstombs_l writev
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/configure.ac b/configure.ac
index 27552e949e..18233608da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1452,7 +1452,6 @@ AC_CHECK_HEADERS(m4_normalize([
 	ifaddrs.h
 	langinfo.h
 	mbarrier.h
-	poll.h
 	sys/epoll.h
 	sys/event.h
 	sys/ipc.h
@@ -1800,7 +1799,6 @@ AC_CHECK_FUNCS(m4_normalize([
 	kqueue
 	mbstowcs_l
 	memset_s
-	poll
 	posix_fallocate
 	ppoll
 	pthread_is_threaded_np
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 75392a8bb7..74ceb7e5f5 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -54,7 +54,7 @@
  */
 #include "postgres.h"
 
-#ifdef HAVE_POLL_H
+#ifndef WIN32
 #include <poll.h>
 #endif
 #include <signal.h>
diff --git a/src/backend/storage/ipc/latch.c b/src/backend/storage/ipc/latch.c
index eb3a569aae..d0e05eefb6 100644
--- a/src/backend/storage/ipc/latch.c
+++ b/src/backend/storage/ipc/latch.c
@@ -46,7 +46,7 @@
 #ifdef HAVE_SYS_SIGNALFD_H
 #include <sys/signalfd.h>
 #endif
-#ifdef HAVE_POLL_H
+#ifndef WIN32
 #include <poll.h>
 #endif
 
@@ -76,12 +76,10 @@
 #define WAIT_USE_EPOLL
 #elif defined(HAVE_KQUEUE)
 #define WAIT_USE_KQUEUE
-#elif defined(HAVE_POLL)
-#define WAIT_USE_POLL
-#elif WIN32
+#elif defined(WIN32)
 #define WAIT_USE_WIN32
 #else
-#error "no wait set implementation available"
+#define WAIT_USE_POLL
 #endif
 
 /*
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index af4a1c3068..7c42c74ed8 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -20,7 +20,7 @@
 #include <float.h>
 #include <math.h>
 #include <limits.h>
-#ifdef HAVE_POLL_H
+#ifndef WIN32
 #include <poll.h>
 #endif
 #ifndef WIN32
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 71682a3300..e48d4f5053 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -47,9 +47,7 @@
 /* For testing, PGBENCH_USE_SELECT can be defined to force use of that code */
 #if defined(HAVE_PPOLL) && !defined(PGBENCH_USE_SELECT)
 #define POLL_USING_PPOLL
-#ifdef HAVE_POLL_H
 #include <poll.h>
-#endif
 #else							/* no ppoll(), so use select() */
 #define POLL_USING_SELECT
 #ifdef HAVE_SYS_SELECT_H
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 9c426ca8a0..be96c292be 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -381,12 +381,6 @@
 /* Define to 1 if you have the <pam/pam_appl.h> header file. */
 #undef HAVE_PAM_PAM_APPL_H
 
-/* Define to 1 if you have the `poll' function. */
-#undef HAVE_POLL
-
-/* Define to 1 if you have the <poll.h> header file. */
-#undef HAVE_POLL_H
-
 /* Define to 1 if you have the `posix_fadvise' function. */
 #undef HAVE_POSIX_FADVISE
 
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index d76bb3957a..86a36cb60c 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -40,7 +40,7 @@
 #include <sys/time.h>
 #endif
 
-#ifdef HAVE_POLL_H
+#ifndef WIN32
 #include <poll.h>
 #endif
 #ifdef HAVE_SYS_SELECT_H
@@ -1095,7 +1095,7 @@ static int
 pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time)
 {
 	/* We use poll(2) if available, otherwise select(2) */
-#ifdef HAVE_POLL
+#ifndef WIN32
 	struct pollfd input_fd;
 	int			timeout_ms;
 
@@ -1125,7 +1125,7 @@ pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time)
 	}
 
 	return poll(&input_fd, 1, timeout_ms);
-#else							/* !HAVE_POLL */
+#else							/* WIN32 */
 
 	fd_set		input_mask;
 	fd_set		output_mask;
@@ -1163,7 +1163,7 @@ pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time)
 
 	return select(sock + 1, &input_mask, &output_mask,
 				  &except_mask, ptr_timeout);
-#endif							/* HAVE_POLL */
+#endif							/* WIN32 */
 }
 
 
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 8ccd9d6ab0..6e6c7126d4 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -321,8 +321,6 @@ sub GenerateFiles
 		HAVE_OPENSSL_INIT_SSL       => undef,
 		HAVE_OSSP_UUID_H            => undef,
 		HAVE_PAM_PAM_APPL_H         => undef,
-		HAVE_POLL                   => undef,
-		HAVE_POLL_H                 => undef,
 		HAVE_POSIX_FADVISE          => undef,
 		HAVE_POSIX_FALLOCATE        => undef,
 		HAVE_PPC_LWARX_MUTEX_HINT   => undef,
-- 
2.30.2

