]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/planet/files/default/flush/flush.c
Add a small preload library to flush files on close
[chef.git] / cookbooks / planet / files / default / flush / flush.c
diff --git a/cookbooks/planet/files/default/flush/flush.c b/cookbooks/planet/files/default/flush/flush.c
new file mode 100644 (file)
index 0000000..c80e86a
--- /dev/null
@@ -0,0 +1,16 @@
+#include <dlfcn.h>
+#include <unistd.h>
+
+static int (*real_close)(int fd);
+
+static void __attribute__((constructor)) initialise(void)
+{
+  real_close = dlsym(RTLD_NEXT, "close");
+}
+
+int close(int fd)
+{
+  fdatasync(fd);
+
+  return real_close(fd);
+}