summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-08-12 11:55:06 +0200
committerLennart Poettering <lennart@poettering.net>2014-08-12 13:02:27 +0200
commitc2d6bd61ee77b59566116afe6e20513d19945ed4 (patch)
tree795e387c0b08ba84a48f88a7926e714a180e2c39 /src/network/networkd-link.c
parentbf1594f54ea4b49eee95a16796ec11c55314b2a4 (diff)
networkd: update manager_save() to use fflush_and_check() to simplify things a bit
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index a95efe3655..62533c1666 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2332,7 +2332,7 @@ int link_save(Link *link) {
r = fopen_temporary(link->state_file, &f, &temp_path);
if (r < 0)
- goto finish;
+ return r;
fchmod(fileno(f), 0644);
@@ -2393,7 +2393,7 @@ int link_save(Link *link) {
r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
if (r < 0)
- goto finish;
+ goto fail;
fprintf(f,
"DHCP_LEASE=%s\n",
@@ -2401,18 +2401,21 @@ int link_save(Link *link) {
} else
unlink(link->lease_file);
- fflush(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
- if (ferror(f) || rename(temp_path, link->state_file) < 0) {
+ if (rename(temp_path, link->state_file) < 0) {
r = -errno;
- unlink(link->state_file);
- unlink(temp_path);
+ goto fail;
}
-finish:
- if (r < 0)
- log_error_link(link, "Failed to save link data to %s: %s", link->state_file, strerror(-r));
+ return 0;
+fail:
+ log_error_link(link, "Failed to save link data to %s: %s", link->state_file, strerror(-r));
+ unlink(link->state_file);
+ unlink(temp_path);
return r;
}