Hi list,
I found a 'pg_test_fsync.out' file in my $PGDATA, which was probably
left around because I aborted pg_test_fsync with ^C back when setting
up the server.
Here's a patch to delete that file via a signal handler for
SIGINT/SIGTERM/SIGHUP.
Not tested on Windows, but should work according to MSDN documentation.
Regards,
Marti
From 5531c177bf108b840563e5aecbf3321fe7efbf87 Mon Sep 17 00:00:00 2001
From: Marti Raudsepp ma...@juffo.org
Date: Wed, 7 Dec 2011 18:40:58 +0200
Subject: [PATCH] pg_test_fsync: Delete temporary file when aborted by a
signal
---
contrib/pg_test_fsync/pg_test_fsync.c | 20
1 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/contrib/pg_test_fsync/pg_test_fsync.c b/contrib/pg_test_fsync/pg_test_fsync.c
index 3791f5a..5fe6228 100644
--- a/contrib/pg_test_fsync/pg_test_fsync.c
+++ b/contrib/pg_test_fsync/pg_test_fsync.c
@@ -9,6 +9,7 @@
#include sys/time.h
#include time.h
#include unistd.h
+#include signal.h
#include getopt_long.h
#include access/xlogdefs.h
@@ -44,6 +45,7 @@ static void test_sync(int writes_per_op);
static void test_open_syncs(void);
static void test_open_sync(const char *msg, int writes_size);
static void test_file_descriptor_sync(void);
+static void signal_cleanup(int sig);
#ifdef HAVE_FSYNC_WRITETHROUGH
static int pg_fsync_writethrough(int fd);
@@ -59,6 +61,14 @@ main(int argc, char *argv[])
handle_args(argc, argv);
+ /* Prevent leaving behind the test file */
+ signal(SIGINT, signal_cleanup);
+ signal(SIGTERM, signal_cleanup);
+#ifdef SIGHUP
+ /* Not defined on win32 */
+ signal(SIGHUP, signal_cleanup);
+#endif
+
prepare_buf();
test_open();
@@ -490,6 +500,16 @@ test_non_sync(void)
print_elapse(start_t, stop_t);
}
+static void
+signal_cleanup(int signum)
+{
+ /* Delete the file if it exists. Ignore errors */
+ unlink(filename);
+ /* Finish incomplete line on stdout */
+ puts();
+ exit(signum);
+}
+
#ifdef HAVE_FSYNC_WRITETHROUGH
static int
--
1.7.8
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers