diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-08-12 11:55:06 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-08-12 13:02:27 +0200 |
commit | c2d6bd61ee77b59566116afe6e20513d19945ed4 (patch) | |
tree | 795e387c0b08ba84a48f88a7926e714a180e2c39 /src/network/networkd-manager.c | |
parent | bf1594f54ea4b49eee95a16796ec11c55314b2a4 (diff) |
networkd: update manager_save() to use fflush_and_check() to simplify things a bit
Diffstat (limited to 'src/network/networkd-manager.c')
-rw-r--r-- | src/network/networkd-manager.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 223cb2a75a..8a0ed5ea2b 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -440,7 +440,7 @@ int manager_save(Manager *m) { r = fopen_temporary(m->state_file, &f, &temp_path); if (r < 0) - goto finish; + return r; fchmod(fileno(f), 0644); @@ -448,18 +448,21 @@ int manager_save(Manager *m) { "# This is private data. Do not parse.\n" "OPER_STATE=%s\n", operstate_str); - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, m->state_file) < 0) { + if (rename(temp_path, m->state_file) < 0) { r = -errno; - unlink(m->state_file); - unlink(temp_path); + goto fail; } -finish: - if (r < 0) - log_error("Failed to save network state to %s: %s", m->state_file, strerror(-r)); + return 0; +fail: + log_error("Failed to save network state to %s: %s", m->state_file, strerror(-r)); + unlink(m->state_file); + unlink(temp_path); return r; } |