chiark / gitweb /
networkd: link - clean up state files
authorTom Gundersen <teg@jklm.no>
Thu, 8 May 2014 16:53:32 +0000 (18:53 +0200)
committerTom Gundersen <teg@jklm.no>
Fri, 9 May 2014 12:41:27 +0000 (14:41 +0200)
Also keep the path to the lease file around rather than regenarating it all the time.

src/network/networkd-link.c
src/network/networkd.h

index ab3158356a703c24f5be05bbd0bac73e83527b60..74860196a506bb08d753a19ce4cbbddfac07e73d 100644 (file)
@@ -79,6 +79,11 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
         if (r < 0)
                 return -ENOMEM;
 
+        r = asprintf(&link->lease_file, "/run/systemd/network/leases/%"PRIu64,
+                     link->ifindex);
+        if (r < 0)
+                return -ENOMEM;
+
         r = hashmap_put(manager->links, &link->ifindex, link);
         if (r < 0)
                 return r;
@@ -98,11 +103,16 @@ void link_free(Link *link) {
         sd_dhcp_client_unref(link->dhcp_client);
         sd_dhcp_lease_unref(link->dhcp_lease);
 
+        unlink(link->lease_file);
+        free(link->lease_file);
+
         sd_ipv4ll_unref(link->ipv4ll);
 
         hashmap_remove(link->manager->links, &link->ifindex);
 
         free(link->ifname);
+
+        unlink(link->state_file);
         free(link->state_file);
 
         udev_device_unref(link->udev_device);
@@ -1682,13 +1692,14 @@ int link_update(Link *link, sd_rtnl_message *m) {
 }
 
 int link_save(Link *link) {
-        _cleanup_free_ char *temp_path = NULL, *lease_file = NULL;
+        _cleanup_free_ char *temp_path = NULL;
         _cleanup_fclose_ FILE *f = NULL;
         const char *admin_state, *oper_state = "unknown";
         int r;
 
         assert(link);
         assert(link->state_file);
+        assert(link->lease_file);
         assert(link->manager);
 
         r = manager_save(link->manager);
@@ -1703,11 +1714,6 @@ int link_save(Link *link) {
         else if (link_has_carrier(link->flags, link->operstate))
                 oper_state = "carrier";
 
-        r = asprintf(&lease_file, "/run/systemd/network/leases/%"PRIu64,
-                             link->ifindex);
-        if (r < 0)
-                return -ENOMEM;
-
         r = fopen_temporary(link->state_file, &f, &temp_path);
         if (r < 0)
                 goto finish;
@@ -1722,13 +1728,13 @@ int link_save(Link *link) {
                 admin_state, oper_state, link->flags);
 
         if (link->dhcp_lease) {
-                r = dhcp_lease_save(link->dhcp_lease, lease_file);
+                r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
                 if (r < 0)
                         goto finish;
 
-                fprintf(f, "DHCP_LEASE=%s\n", lease_file);
+                fprintf(f, "DHCP_LEASE=%s\n", link->lease_file);
         } else
-                unlink(lease_file);
+                unlink(link->lease_file);
 
         fflush(f);
 
index aebb2859206691f7788a495fcfb51b2fa5309589..57eecf4db3316cfb05d9f3cf712af20fec760d35 100644 (file)
@@ -218,6 +218,7 @@ struct Link {
 
         sd_dhcp_client *dhcp_client;
         sd_dhcp_lease *dhcp_lease;
+        char *lease_file;
         uint16_t original_mtu;
         sd_ipv4ll *ipv4ll;
 };