From 8c912ed353240ecfa49ee3a9f1f7c65141e9d0d6 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Thu, 6 Jul 2023 15:25:14 -0500 Subject: [PATCH v2 1/2] Use signal-safe functions in signal handler According to signal-safety(7), exit(3) and puts(3) are not safe to call in a signal handler. --- src/bin/pg_test_fsync/pg_test_fsync.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c index 435df8d808..42d0845b06 100644 --- a/src/bin/pg_test_fsync/pg_test_fsync.c +++ b/src/bin/pg_test_fsync/pg_test_fsync.c @@ -595,9 +595,12 @@ signal_cleanup(SIGNAL_ARGS) /* Delete the file if it exists. Ignore errors */ if (needs_unlink) unlink(filename); - /* Finish incomplete line on stdout */ - puts(""); - exit(1); + /* + * Finish incomplete line on stdout. fileno(3) is not signal-safe, and + * STDOUT_FILENO is not portable. + */ + write(1, "\n", 1); + _exit(1); } #ifdef HAVE_FSYNC_WRITETHROUGH -- Tristan Partin Neon (https://neon.tech)