]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: do not remove LLDP state file on failure 18773/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 3 Mar 2021 07:42:18 +0000 (16:42 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 3 Mar 2021 07:42:23 +0000 (16:42 +0900)
src/network/networkd-lldp-rx.c

index 068adca571124ac743ff57a4489a379ada4a2f7b..bf1dd045b870a4622737a8abd66d1c3197987d87 100644 (file)
@@ -135,7 +135,7 @@ int link_update_lldp(Link *link) {
 }
 
 int link_lldp_save(Link *link) {
-        _cleanup_free_ char *temp_path = NULL;
+        _cleanup_(unlink_and_freep) char *temp_path = NULL;
         _cleanup_fclose_ FILE *f = NULL;
         sd_lldp_neighbor **l = NULL;
         int n = 0, r, i;
@@ -150,10 +150,10 @@ int link_lldp_save(Link *link) {
 
         r = sd_lldp_get_neighbors(link->lldp, &l);
         if (r < 0)
-                goto finish;
+                return r;
         if (r == 0) {
                 (void) unlink(link->lldp_file);
-                goto finish;
+                return 0;
         }
 
         n = r;
@@ -187,13 +187,8 @@ int link_lldp_save(Link *link) {
                 goto finish;
 
 finish:
-        if (r < 0) {
-                (void) unlink(link->lldp_file);
-                if (temp_path)
-                        (void) unlink(temp_path);
-
+        if (r < 0)
                 log_link_error_errno(link, r, "Failed to save LLDP data to %s: %m", link->lldp_file);
-        }
 
         if (l) {
                 for (i = 0; i < n; i++)