From dacd6cee76a08331b8c8616c5f30f70ee49aa2f9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 29 Jul 2015 20:31:07 +0200 Subject: tree-wide: port everything over to fflush_and_check() Some places invoked fflush() directly with their own manual error checking, let's unify all that by using fflush_and_check(). This also unifies the general error paths of fflush()+rename() file writers. --- src/journal-remote/journal-upload.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/journal-remote/journal-upload.c') diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 5d23639ee8..172fd80a12 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -126,26 +126,31 @@ static int update_cursor_state(Uploader *u) { r = fopen_temporary(u->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; fprintf(f, "# This is private data. Do not parse.\n" "LAST_CURSOR=%s\n", u->last_cursor); - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, u->state_file) < 0) { + if (rename(temp_path, u->state_file) < 0) { r = -errno; - unlink(u->state_file); - unlink(temp_path); + goto fail; } -finish: - if (r < 0) - log_error_errno(r, "Failed to save state %s: %m", u->state_file); + return 0; - return r; +fail: + if (temp_path) + (void) unlink(temp_path); + + (void) unlink(u->state_file); + + return log_error_errno(r, "Failed to save state %s: %m", u->state_file); } static int load_cursor_state(Uploader *u) { -- cgit v1.2.3-54-g00ecf