]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
pgindent: Clean up temp files created by File::Temp on SIGINT
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 27 Mar 2026 13:24:13 +0000 (14:24 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 27 Mar 2026 13:26:43 +0000 (14:26 +0100)
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.

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://www.postgresql.org/message-id/flat/DFCDD5H4J7VX.3GJKRBBDCKQ86@jeltef.nl

src/tools/pgindent/pgindent

index 7481696a584c373040ee0fc6791d123ccd127ade..f78a34eb3ced857dd661c3713ac713b79f9f5f63 100755 (executable)
@@ -19,6 +19,15 @@ 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";