diff dbutil.c @ 1344:b90da477ab63 coverity

merge coverity
author Matt Johnston <matt@ucc.asn.au>
date Thu, 18 May 2017 23:02:39 +0800
parents bbc0a0ee3843
children 6b89eb92f872 336cae2238ca 58a74cb829b8
line wrap: on
line diff
--- a/dbutil.c	Fri Jul 22 00:08:02 2016 +0800
+++ b/dbutil.c	Thu May 18 23:02:39 2017 +0800
@@ -182,7 +182,7 @@
 void dropbear_trace(const char* format, ...) {
 	va_list param;
 
-	if (!ses.debug_trace) {
+	if (!debug_trace) {
 		return;
 	}
 
@@ -681,4 +681,21 @@
 	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
+}