summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/sd-dhcp-lease.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-03-03 16:25:54 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-03-03 16:26:32 +0900
commitab7153b3f4f47d1c9763ba406c64abbf61a50cac (patch)
tree5b80f59484045c3eb6838192185624554cf9c2cd /src/libsystemd-network/sd-dhcp-lease.c
parent3be9d62ad1e3178a7defc0f48b64bd27eeb99d77 (diff)
downloadsystemd-ab7153b3f4f47d1c9763ba406c64abbf61a50cac.tar.gz
dhcp: use unlink_and_freep() in dhcp_lease_save()
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-lease.c')
-rw-r--r--src/libsystemd-network/sd-dhcp-lease.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 1c0b431165..9fcbe17006 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -869,7 +869,7 @@ int dhcp_lease_new(sd_dhcp_lease **ret) {
}
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;
@@ -889,7 +889,7 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
r = fopen_temporary(lease_file, &f, &temp_path);
if (r < 0)
- goto fail;
+ return r;
(void) fchmod(fileno(f), 0644);
@@ -992,10 +992,8 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
_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);
}
@@ -1004,10 +1002,8 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
_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);
}
@@ -1017,28 +1013,23 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
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,