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/login/logind-dbus.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/login/logind-dbus.c') diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index e6371ff04d..397952e7e5 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1816,17 +1816,22 @@ static int update_schedule_file(Manager *m) { if (!isempty(m->wall_message)) fprintf(f, "WALL_MESSAGE=%s\n", t); - (void) fflush_and_check(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, "/run/systemd/shutdown/scheduled") < 0) { - log_error_errno(errno, "Failed to write information about scheduled shutdowns: %m"); + if (rename(temp_path, "/run/systemd/shutdown/scheduled") < 0) { r = -errno; - - (void) unlink(temp_path); - (void) unlink("/run/systemd/shutdown/scheduled"); + goto fail; } - return r; + return 0; + +fail: + (void) unlink(temp_path); + (void) unlink("/run/systemd/shutdown/scheduled"); + + return log_error_errno(r, "Failed to write information about scheduled shutdowns: %m"); } static int manager_scheduled_shutdown_handler( -- cgit v1.2.3-54-g00ecf