}
int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
- _cleanup_free_ char *temp_path = NULL;
+ _cleanup_(unlink_and_freep) char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
struct sd_dhcp_raw_option *option;
struct in_addr address;
r = fopen_temporary(lease_file, &f, &temp_path);
if (r < 0)
- goto fail;
+ return r;
(void) fchmod(fileno(f), 0644);
_cleanup_free_ char *client_id_hex = NULL;
client_id_hex = hexmem(client_id, client_id_len);
- if (!client_id_hex) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!client_id_hex)
+ return -ENOMEM;
fprintf(f, "CLIENTID=%s\n", client_id_hex);
}
_cleanup_free_ char *option_hex = NULL;
option_hex = hexmem(data, data_len);
- if (!option_hex) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!option_hex)
+ return -ENOMEM;
fprintf(f, "VENDOR_SPECIFIC=%s\n", option_hex);
}
xsprintf(key, "OPTION_%" PRIu8, option->tag);
r = serialize_dhcp_option(f, key, option->data, option->length);
if (r < 0)
- goto fail;
+ return r;
}
r = fflush_and_check(f);
if (r < 0)
- goto fail;
+ return r;
r = conservative_rename(temp_path, lease_file);
if (r < 0)
- goto fail;
-
- return 0;
+ return r;
-fail:
- if (temp_path)
- (void) unlink(temp_path);
+ temp_path = mfree(temp_path);
- return log_error_errno(r, "Failed to save lease data %s: %m", lease_file);
+ return 0;
}
int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
-
_cleanup_(sd_dhcp_lease_unrefp) sd_dhcp_lease *lease = NULL;
_cleanup_free_ char
*address = NULL,