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/locale/localed.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/locale') diff --git a/src/locale/localed.c b/src/locale/localed.c index 88756542fd..e8a8f17d86 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -476,15 +476,25 @@ static int x11_write_data(Context *c) { fprintf(f, " Option \"XkbOptions\" \"%s\"\n", c->x11_options); fputs("EndSection\n", f); - fflush(f); - if (ferror(f) || rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) { + r = fflush_and_check(f); + if (r < 0) + goto fail; + + if (rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) { r = -errno; - unlink("/etc/X11/xorg.conf.d/00-keyboard.conf"); - unlink(temp_path); - return r; - } else - return 0; + goto fail; + } + + return 0; + +fail: + (void) unlink("/etc/X11/xorg.conf.d/00-keyboard.conf"); + + if (temp_path) + (void) unlink(temp_path); + + return r; } static int vconsole_reload(sd_bus *bus) { -- cgit v1.2.3-54-g00ecf