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/journald-stream.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src/journal/journald-stream.c') diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index db2f581972..69e2d41863 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -142,7 +142,7 @@ static int stdout_stream_save(StdoutStream *s) { r = fopen_temporary(s->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; fprintf(f, "# This is private data. Do not parse\n" @@ -163,7 +163,7 @@ static int stdout_stream_save(StdoutStream *s) { escaped = cescape(s->identifier); if (!escaped) { r = -ENOMEM; - goto finish; + goto fail; } fprintf(f, "IDENTIFIER=%s\n", escaped); @@ -175,7 +175,7 @@ static int stdout_stream_save(StdoutStream *s) { escaped = cescape(s->unit_id); if (!escaped) { r = -ENOMEM; - goto finish; + goto fail; } fprintf(f, "UNIT=%s\n", escaped); @@ -183,16 +183,13 @@ static int stdout_stream_save(StdoutStream *s) { r = fflush_and_check(f); if (r < 0) - goto finish; + goto fail; if (rename(temp_path, s->state_file) < 0) { r = -errno; - goto finish; + goto fail; } - free(temp_path); - temp_path = NULL; - /* Store the connection fd in PID 1, so that we get it passed * in again on next start */ if (!s->fdstore) { @@ -200,14 +197,15 @@ static int stdout_stream_save(StdoutStream *s) { s->fdstore = true; } -finish: - if (temp_path) - unlink(temp_path); + return 0; - if (r < 0) - log_error_errno(r, "Failed to save stream data %s: %m", s->state_file); +fail: + (void) unlink(s->state_file); + + if (temp_path) + (void) unlink(temp_path); - return r; + return log_error_errno(r, "Failed to save stream data %s: %m", s->state_file); } static int stdout_stream_log(StdoutStream *s, const char *p) { -- cgit v1.2.3-54-g00ecf