]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: update manager_save() to use fflush_and_check() to simplify things a bit
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Aug 2014 09:55:06 +0000 (11:55 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Aug 2014 11:02:27 +0000 (13:02 +0200)
src/network/networkd-link.c
src/network/networkd-manager.c

index a95efe3655d3c556854ee48ac5360a2d3e808d3a..62533c1666b9df61e59307e4c107d89af7b6f5c6 100644 (file)
@@ -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;
 }
 
index 223cb2a75aa5e7de77f8afaecc3c3dc51b0b3d1d..8a0ed5ea2b4f38966cd07562eaa8c6bf4636a40a 100644 (file)
@@ -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;
 }