chiark / gitweb /
networkd: update manager_save() to use fflush_and_check() to simplify things a bit
[elogind.git] / src / network / networkd-link.c
index accb42bf37610a37d44759897f57564cad048422..62533c1666b9df61e59307e4c107d89af7b6f5c6 100644 (file)
@@ -33,7 +33,6 @@
 #include "network-internal.h"
 #include "conf-parser.h"
 
-#include "network-util.h"
 #include "dhcp-lease-internal.h"
 
 static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
@@ -750,7 +749,7 @@ static int link_enter_set_addresses(Link *link) {
                         return r;
                 }
 
-                prefixlen = net_netmask_to_prefixlen(&netmask);
+                prefixlen = in_addr_netmask_to_prefixlen(&netmask);
 
                 r = address_new_dynamic(&address);
                 if (r < 0) {
@@ -983,7 +982,7 @@ static int dhcp_lease_lost(Link *link) {
 
                 sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
                 sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
-                prefixlen = net_netmask_to_prefixlen(&netmask);
+                prefixlen = in_addr_netmask_to_prefixlen(&netmask);
 
                 address->family = AF_INET;
                 address->in_addr.in = addr;
@@ -1073,7 +1072,7 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
                 return r;
         }
 
-        prefixlen = net_netmask_to_prefixlen(&netmask);
+        prefixlen = in_addr_netmask_to_prefixlen(&netmask);
 
         r = sd_dhcp_lease_get_router(lease, &gateway);
         if (r < 0 && r != -ENOENT) {
@@ -2333,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);
 
@@ -2394,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",
@@ -2402,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;
 }