summaryrefslogtreecommitdiff
path: root/dbutil.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2016-11-19 00:31:21 +0800
committerMatt Johnston <matt@ucc.asn.au>2016-11-19 00:31:21 +0800
commit1496ae874a833ba6f4e91b8ce4837c19a34b1170 (patch)
tree7992b7c12dcc59363c44f0adada893af8c1484a3 /dbutil.c
parentaa1103bd5169866d296ad4018fabfb29bccea6f5 (diff)
downloaddropbear-1496ae874a833ba6f4e91b8ce4837c19a34b1170.tar.gz
Use atomic key generation in all cases
Diffstat (limited to 'dbutil.c')
-rw-r--r--dbutil.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/dbutil.c b/dbutil.c
index ef06802..69e43bb 100644
--- a/dbutil.c
+++ b/dbutil.c
@@ -681,4 +681,21 @@ time_t monotonic_now() {
return time(NULL);
}
+void fsync_parent_dir(const char* fn) {
+#ifdef HAVE_LIBGEN_H
+ char *fn_dir = m_strdup(fn);
+ char *dir = dirname(fn_dir);
+ int dirfd = open(dir, O_RDONLY);
+
+ if (dirfd != -1) {
+ if (fsync(dirfd) != 0) {
+ TRACE(("fsync of directory %s failed: %s", dir, strerror(errno)))
+ }
+ m_close(dirfd);
+ } else {
+ TRACE(("error opening directory %s for fsync: %s", dir, strerror(errno)))
+ }
+ free(fn_dir);
+#endif
+}