X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fsocket-util.c;h=912c47e097f8e80c807cabf3cfddcab343594184;hb=d3f82921586b4018b45fdd1cbfa5c94fc37d362c;hp=a8f805c56370c79eb052013943483f51706abe19;hpb=c69ee87c10818267f991236201150b1fa51ae519;p=openvswitch diff --git a/lib/socket-util.c b/lib/socket-util.c index a8f805c5..912c47e0 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -557,3 +557,34 @@ write_fully(int fd, const void *p_, size_t size, size_t *bytes_written) } return 0; } + +/* Given file name 'file_name', fsyncs the directory in which it is contained. + * Returns 0 if successful, otherwise a positive errno value. */ +int +fsync_parent_dir(const char *file_name) +{ + int error = 0; + char *dir; + int fd; + + dir = dir_name(file_name); + fd = open(dir, O_RDONLY); + if (fd >= 0) { + if (fsync(fd)) { + if (errno == EINVAL || errno == EROFS) { + /* This directory does not support synchronization. Not + * really an error. */ + } else { + error = errno; + VLOG_ERR("%s: fsync failed (%s)", dir, strerror(error)); + } + } + close(fd); + } else { + error = errno; + VLOG_ERR("%s: open failed (%s)", dir, strerror(error)); + } + free(dir); + + return error; +}