From: Karol Lewandowski Date: Wed, 7 Nov 2018 11:58:19 +0000 (+0100) Subject: util: Add fsync_path to selectively flush file buffer to disk X-Git-Tag: accepted/tizen/unified/20181119.153038~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6accf65c59124e5a70e6034922ad14f8853fc511;p=platform%2Fcore%2Fsystem%2Fcrash-worker.git util: Add fsync_path to selectively flush file buffer to disk Change-Id: I3cd9169dafff33cdfbaf1c21955c37d38a524fae --- diff --git a/src/shared/util.c b/src/shared/util.c index bdb8259..85879d6 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -502,6 +502,22 @@ int run_command_timeout(char *path, char *args[], char *env[], int timeout) return res; } +int fsync_path(char *const path) +{ + int fd, ret; + + ret = fd = open(path, O_RDONLY); + if (fd >= 0) { + ret = fsync(fd); + close(fd); + } + + if (ret < 0) + _E("Unable to fsync %s: %m", path); + + return ret; +} + static int remove_dir_internal(int fd) { DIR *dir; diff --git a/src/shared/util.h b/src/shared/util.h index 53e0c7d..819a19c 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -51,6 +51,8 @@ int run_command_write_fd_timeout(char *path, char *args[], char *env[], int dfd, int run_command_timeout(char *path, char *args[], char *env[], int timeout); +int fsync_path(char *const path); + int remove_dir(const char *path, int del_dir); int get_exec_pid(const char *execpath);