From 8862ec4be4139f6d7e84932b3435a4ea5940037d Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Wed, 4 Mar 2026 10:02:39 +0100
Subject: [PATCH v3 1/8] pgindent: Clean up temp files created by File::Temp on
 SIGINT

When pressing Ctrl+C while running pgindent, it would often leave around
files like pgtypedefAXUEEA. This slightly changes SIGINT handling so
those files are cleaned up.
---
 src/tools/pgindent/pgindent | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 7481696a584..b96891b2252 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -19,6 +19,14 @@ use File::Temp;
 use IO::Handle;
 use Getopt::Long;
 
+# By default Perl's SIGINT/SIGTERM kill the process without running END blocks,
+# so File::Temp never gets to clean up. Converting the signal into an exit()
+# makes END-block cleanup run. See: http://www.perlmonks.org/?node_id=714225
+# Exit codes use the 128+signum convention so callers can tell the process was
+# killed by a signal.
+$SIG{INT} = sub { exit 130; };     # 128 + 2 (SIGINT)
+$SIG{TERM} = sub { exit 143; };    # 128 + 15 (SIGTERM)
+
 # Update for pg_bsd_indent version
 my $INDENT_VERSION = "2.1.2";
 

base-commit: a0b6ef29a51818a4073a5f390ed10ef6453d5c11
-- 
2.53.0

