From 223ca88239f6950ccd27e6f75983ecd42edb7762 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Fri, 6 Apr 2018 12:01:37 +1200
Subject: [PATCH 2/2] Break fsyncs for testing, not for commit.

---
 src/backend/storage/smgr/md.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 27c55de16a..930b3111c3 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -39,6 +39,18 @@
 #include "utils/memutils.h"
 #include "pg_trace.h"
 
+#include <unistd.h>
+
+static int broken_fsync(int fd, int x)
+{
+	if (access("/tmp/broken_fsync", F_OK) != -1)
+	{
+			errno = EIO;
+			return -1;
+	}
+	return FileSync(fd, x);
+}
+#define FileSync(a, b) broken_fsync(a, b)
 
 /* intervals for calling AbsorbFsyncRequests in mdsync and mdpostckpt */
 #define FSYNCS_PER_ABSORB		10
-- 
2.16.2

