diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-07-29 20:31:07 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-07-29 20:31:07 +0200 |
commit | dacd6cee76a08331b8c8616c5f30f70ee49aa2f9 (patch) | |
tree | 7a7d73f2ac1f909255361781ca923365b6c9b7c3 /src/login/logind-seat.c | |
parent | 8388607b5851574e50a6e65db98135b793b08910 (diff) |
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.
Diffstat (limited to 'src/login/logind-seat.c')
-rw-r--r-- | src/login/logind-seat.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 495ec50be0..8d13a63688 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -93,11 +93,11 @@ int seat_save(Seat *s) { r = mkdir_safe_label("/run/systemd/seats", 0755, 0, 0); if (r < 0) - goto finish; + goto fail; r = fopen_temporary(s->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; fchmod(fileno(f), 0644); @@ -141,19 +141,24 @@ int seat_save(Seat *s) { i->sessions_by_seat_next ? ' ' : '\n'); } - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, s->state_file) < 0) { + if (rename(temp_path, s->state_file) < 0) { r = -errno; - unlink(s->state_file); - unlink(temp_path); + goto fail; } -finish: - if (r < 0) - log_error_errno(r, "Failed to save seat data %s: %m", s->state_file); + return 0; - return r; +fail: + (void) unlink(s->state_file); + + if (temp_path) + (void) unlink(temp_path); + + return log_error_errno(r, "Failed to save seat data %s: %m", s->state_file); } int seat_load(Seat *s) { |