0002-Fix-Makefile-used-for-test_cloexec.patch
text/x-patch
Filename: 0002-Fix-Makefile-used-for-test_cloexec.patch
Type: text/x-patch
Part: 1
From 897d47122ef39f826eae3f3b7db8cb85e45d3c84 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Sun, 14 Dec 2025 17:14:38 +1300
Subject: [PATCH 2/3] Fix Makefile used for test_cloexec.
The previous test for ifeq ($(PORTNAME), win32) never succeeded, so only
meson-based builds were building and testing our O_CLOEXEC emulation.
Defect in commit c507ba55.
That could probably be made to work, but it seems better to compile
test_cloexec.c unconditionally and skip the test for non-Windows
systems. Though the test is skipped on Unix and the executable wouldn't
test anything if run (there is not much point in testing that the system
O_CLOEXEC works on Unix), at least this way the configure-based build
machinery is consistent, for ease of maintenance by Unix-based
developers.
Backpatch-through: 16, like commit c507ba55
---
src/test/modules/test_cloexec/Makefile | 16 ++++-----------
src/test/modules/test_cloexec/test_cloexec.c | 21 +++++++++-----------
2 files changed, 13 insertions(+), 24 deletions(-)
diff --git a/src/test/modules/test_cloexec/Makefile b/src/test/modules/test_cloexec/Makefile
index 70d38575e26..94342319782 100644
--- a/src/test/modules/test_cloexec/Makefile
+++ b/src/test/modules/test_cloexec/Makefile
@@ -1,22 +1,14 @@
# src/test/modules/test_cloexec/Makefile
-# This module is for Windows only
-ifeq ($(PORTNAME),win32)
-
-MODULE_big = test_cloexec
-OBJS = \
- $(WIN32RES) \
- test_cloexec.o
-
PGFILEDESC = "test_cloexec - test O_CLOEXEC flag handling"
+PGAPPICON = win32
-# Build as a standalone program, not a shared library
-PROGRAM = test_cloexec
-override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
+PROGRAM += test_cloexec
+OBJS += $(WIN32RES) test_cloexec.o
+NO_INSTALLCHECK = 1
TAP_TESTS = 1
-endif
ifdef USE_PGXS
PG_CONFIG = pg_config
diff --git a/src/test/modules/test_cloexec/test_cloexec.c b/src/test/modules/test_cloexec/test_cloexec.c
index 9f645451684..7ff6585d710 100644
--- a/src/test/modules/test_cloexec/test_cloexec.c
+++ b/src/test/modules/test_cloexec/test_cloexec.c
@@ -24,21 +24,22 @@
#include "common/file_utils.h"
#include "port.h"
+#ifdef WIN32
static void run_parent_tests(const char *testfile1, const char *testfile2);
static void run_child_tests(const char *handle1_str, const char *handle2_str);
static bool try_write_to_handle(HANDLE h, const char *label);
+#endif
int
main(int argc, char *argv[])
{
- char testfile1[MAXPGPATH];
- char testfile2[MAXPGPATH];
-
- /* Windows-only test */
#ifndef WIN32
+ /* Windows-only test */
fprintf(stderr, "This test only runs on Windows\n");
return 0;
-#endif
+#else
+ char testfile1[MAXPGPATH];
+ char testfile2[MAXPGPATH];
if (argc == 3)
{
@@ -68,12 +69,13 @@ main(int argc, char *argv[])
fprintf(stderr, "Usage: %s [handle1_hex handle2_hex]\n", argv[0]);
return 1;
}
+#endif
}
+#ifdef WIN32
static void
run_parent_tests(const char *testfile1, const char *testfile2)
{
-#ifdef WIN32
int fd1,
fd2;
HANDLE h1,
@@ -186,13 +188,11 @@ run_parent_tests(const char *testfile1, const char *testfile2)
printf("Parent: FAILURE - O_CLOEXEC not working correctly\n");
exit(1);
}
-#endif
}
static void
run_child_tests(const char *handle1_str, const char *handle2_str)
{
-#ifdef WIN32
HANDLE h1,
h2;
bool h1_worked,
@@ -232,13 +232,11 @@ run_child_tests(const char *handle1_str, const char *handle2_str)
printf("Child: Test FAILED - O_CLOEXEC not working correctly\n");
exit(1);
}
-#endif
}
static bool
try_write_to_handle(HANDLE h, const char *label)
{
-#ifdef WIN32
const char *test_data = "test\n";
DWORD bytes_written;
BOOL result;
@@ -256,7 +254,6 @@ try_write_to_handle(HANDLE h, const char *label)
label, GetLastError());
return false;
}
-#else
return false;
-#endif
}
+#endif
--
2.51.2