From 1d3dc235dcc06e1630ed8f6466828ca76f673c4b Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Thu, 16 Dec 2021 17:35:12 +0100 Subject: [PATCH] Sync the stream with fdatasync() --- sort.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sort.c b/sort.c index 1061d18..dcb2f29 100644 --- a/sort.c +++ b/sort.c @@ -308,6 +308,7 @@ stream_winsort(struct ovni_stream *stream, struct ring *r) sp.base = stream->buf; size_t empty_regions = 0; + size_t updated = 0; for(i=0; stream->active; i++) { @@ -337,6 +338,7 @@ stream_winsort(struct ovni_stream *stream, struct ring *r) { if(ends_unsorted_region(ev)) { + updated = 1; sp.next = ev; dbg("executing sort plan for stream tid=%d\n", stream->tid); if(execute_sort_plan(&sp) < 0) @@ -361,6 +363,9 @@ stream_winsort(struct ovni_stream *stream, struct ring *r) err("warning: stream %d contains %ld empty sort regions\n", stream->tid, empty_regions); + if(updated && fdatasync(fd) < 0) + die("fdatasync %s failed: %s\n", fn, strerror(errno)); + if(close(fd) < 0) die("close %s failed: %s\n", fn, strerror(errno));