comparison svr-kex.c @ 983:2b62f26cf808

Open directories O_RDONLY for fsync, add debugging if it fails
author Matt Johnston <matt@ucc.asn.au>
date Sun, 04 Jan 2015 22:22:43 +0800
parents fd2e8bbb0333
children aaf576b27a10
comparison
equal deleted inserted replaced
982:fd2e8bbb0333 983:2b62f26cf808
89 89
90 static void fsync_parent_dir(const char* fn) { 90 static void fsync_parent_dir(const char* fn) {
91 #ifdef HAVE_LIBGEN_H 91 #ifdef HAVE_LIBGEN_H
92 char *fn_dir = m_strdup(fn); 92 char *fn_dir = m_strdup(fn);
93 char *dir = dirname(fn_dir); 93 char *dir = dirname(fn_dir);
94 /* some OSes need the fd to be writable for fsync */ 94 int dirfd = open(dir, O_RDONLY);
95 int dirfd = open(dir, O_RDWR);
96 95
97 if (dirfd != -1) { 96 if (dirfd != -1) {
98 fsync(dirfd); 97 if (fsync(dirfd) != 0) {
98 TRACE(("fsync of directory %s failed: %s", dir, strerror(errno)))
99 }
99 m_close(dirfd); 100 m_close(dirfd);
101 } else {
102 TRACE(("error opening directory %s for fsync: %s", dir, strerror(errno)))
100 } 103 }
101 104
102 free(fn_dir); 105 free(fn_dir);
103 #endif 106 #endif
104 } 107 }