summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2015-01-04 22:22:43 +0800
committerMatt Johnston <matt@ucc.asn.au>2015-01-04 22:22:43 +0800
commit859f547aa1c2212fe90d31832d65c4223943172b (patch)
treead1dfb02454efa62f424e6500163e85475b657a1
parentf79737b53fe3c79bbe3b15c09dfe34731da8c256 (diff)
downloaddropbear-859f547aa1c2212fe90d31832d65c4223943172b.tar.gz
Open directories O_RDONLY for fsync, add debugging if it fails
-rw-r--r--gensignkey.c4
-rw-r--r--svr-kex.c9
2 files changed, 9 insertions, 4 deletions
diff --git a/gensignkey.c b/gensignkey.c
index 06fdfd3..e6c40e0 100644
--- a/gensignkey.c
+++ b/gensignkey.c
@@ -41,7 +41,9 @@ static int buf_writefile(buffer * buf, const char * filename) {
out:
if (fd >= 0) {
- fsync(fd);
+ if (fsync(fd) != 0) {
+ dropbear_log(LOG_ERR, "fsync of %s failed: %s", filename, strerror(errno));
+ }
m_close(fd);
}
return ret;
diff --git a/svr-kex.c b/svr-kex.c
index 01c76e6..6cc5433 100644
--- a/svr-kex.c
+++ b/svr-kex.c
@@ -91,12 +91,15 @@ static void fsync_parent_dir(const char* fn) {
#ifdef HAVE_LIBGEN_H
char *fn_dir = m_strdup(fn);
char *dir = dirname(fn_dir);
- /* some OSes need the fd to be writable for fsync */
- int dirfd = open(dir, O_RDWR);
+ int dirfd = open(dir, O_RDONLY);
if (dirfd != -1) {
- fsync(dirfd);
+ 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);