24 #include <sys/types.h> 26 #define FP (void)fprintf 28 static void bail(
char *msg,
int line) {
29 FP(stderr,
"%s:%d: %s: %s\n", __FILE__, line, msg, strerror(errno));
32 #define BAIL(msg) bail(msg, __LINE__) 34 static void trim_rightmost_path_component(
char *p) {
35 char *s = p + strlen(p) - 1;
38 while (s > p &&
'/' != *s)
44 char rp[1+PATH_MAX], *file = (
char *) malloc(
sizeof(
char)*strlen(name)+1);
46 FP(stderr,
"fsync to root '%s'\n", file);
47 if (NULL == realpath(file, rp))
BAIL(
"realpath failed");
48 FP(stderr,
" realpath '%s'\n", rp);
51 FP(stderr,
" fsync-ing '%s'\n", rp);
52 if (-1 == (fd = open(rp, O_RDONLY)))
BAIL(
"open failed");
53 if (-1 == fsync(fd))
BAIL(
"fsync failed");
54 if (-1 == close(fd))
BAIL(
"close failed");
55 trim_rightmost_path_component(rp);
57 FP(stderr,
" done\n");
#define FP
Definition: fsync.hpp:26
int fsync_paranoid(const char *name)
Definition: fsync.hpp:43
#define BAIL(msg)
Definition: fsync.hpp:32