diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-04-26 15:47:55 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-04-29 12:23:34 +0200 |
commit | a0fe2a2d2028ea8b5e6873b1f55e91a36081656c (patch) | |
tree | 1337f3a3a093fb94a46346988213018a70c4a9a0 /src/journal/journal-file.c | |
parent | update TODO a bit (diff) | |
download | systemd-a0fe2a2d2028ea8b5e6873b1f55e91a36081656c.tar.xz systemd-a0fe2a2d2028ea8b5e6873b1f55e91a36081656c.zip |
journal: when creating a new journal file, fsync() the directory it is created in too
Fixes: #2831
Diffstat (limited to '')
-rw-r--r-- | src/journal/journal-file.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 35f4abab1d..a58079bdd1 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -439,6 +439,39 @@ static int journal_file_init_header(JournalFile *f, JournalFile *template) { return 0; } +static int fsync_directory_of_file(int fd) { + _cleanup_free_ char *path = NULL, *dn = NULL; + _cleanup_close_ int dfd = -1; + struct stat st; + int r; + + if (fstat(fd, &st) < 0) + return -errno; + + if (!S_ISREG(st.st_mode)) + return -EBADFD; + + r = fd_get_path(fd, &path); + if (r < 0) + return r; + + if (!path_is_absolute(path)) + return -EINVAL; + + dn = dirname_malloc(path); + if (!dn) + return -ENOMEM; + + dfd = open(dn, O_RDONLY|O_CLOEXEC|O_DIRECTORY); + if (dfd < 0) + return -errno; + + if (fsync(dfd) < 0) + return -errno; + + return 0; +} + static int journal_file_refresh_header(JournalFile *f) { sd_id128_t boot_id; int r; @@ -464,6 +497,9 @@ static int journal_file_refresh_header(JournalFile *f) { /* Sync the online state to disk */ (void) fsync(f->fd); + /* We likely just created a new file, also sync the directory this file is located in. */ + (void) fsync_directory_of_file(f->fd); + return r; } |