From f7e191782e2d411be38f167f9bc7576b4fe2a49a Mon Sep 17 00:00:00 2001
From: Greg Burd <greg@burd.me>
Date: Thu, 12 Nov 2026 12:13:36 -0500
Subject: [PATCH v4 13/21] pgbench: Report pg_threads.h errors correctly.

pgbench stored the results of pg_thrd_create() and
pg_thrd_barrier_init() in errno and printed them with %m, but these
functions return pg_thrd_* codes rather than errno values, so a
generic failure was reported as "Interrupted system call".  Use
pg_thrd_error_string_with_detail(), as pg_basebackup does.
---
 src/bin/pgbench/pgbench.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index be048b728a2..3baf419f7d8 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -6782,6 +6782,7 @@ main(int argc, char **argv)
 	char	   *env;
 
 	int			exit_code = 0;
+	int			rc;
 	struct timeval tv;
 
 	/* initialize timing infrastructure (required for INSTR_* calls) */
@@ -7410,9 +7411,9 @@ main(int argc, char **argv)
 	if (duration > 0)
 		setalarm(duration);
 
-	errno = pg_thrd_barrier_init(&barrier, nthreads);
-	if (errno != 0)
-		pg_fatal("could not initialize barrier: %m");
+	if ((rc = pg_thrd_barrier_init(&barrier, nthreads)) != pg_thrd_success)
+		pg_fatal("could not initialize barrier: %s",
+				 pg_thrd_error_string_with_detail(rc));
 
 	/* start all threads but thread 0 which is executed directly later */
 	for (i = 1; i < nthreads; i++)
@@ -7420,10 +7421,10 @@ main(int argc, char **argv)
 		TState	   *thread = &threads[i];
 
 		thread->create_time = pg_time_now();
-		errno = pg_thrd_create(&thread->thread, threadRun, thread);
-
-		if (errno != 0)
-			pg_fatal("could not create thread: %m");
+		rc = pg_thrd_create(&thread->thread, threadRun, thread);
+		if (rc != pg_thrd_success)
+			pg_fatal("could not create thread: %s",
+					 pg_thrd_error_string_with_detail(rc));
 	}
 
 	/* compute when to stop */
-- 
2.54.0

