}
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;
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;
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++)