diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-01-12 17:44:49 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-01-14 08:24:27 +0100 |
commit | 100433e05aae71612d6a82e8e285067b4e3348b8 (patch) | |
tree | b6c180ffa41e2afa303588be1228fbf163f2c8e5 /src/network/networkctl.c | |
parent | networkctl: open the bus just once (diff) | |
download | systemd-100433e05aae71612d6a82e8e285067b4e3348b8.tar.xz systemd-100433e05aae71612d6a82e8e285067b4e3348b8.zip |
networkctl: use xsprintf a bit more
Diffstat (limited to '')
-rw-r--r-- | src/network/networkctl.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/network/networkctl.c b/src/network/networkctl.c index c35f851bdb..20e176e854 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -613,11 +613,12 @@ static int link_get_property( sd_bus_message **reply, const char *iface, const char *propname) { - _cleanup_free_ char *path = NULL, *ifindex_str = NULL; + + char ifindex_str[DECIMAL_STR_MAX(int)]; + _cleanup_free_ char *path = NULL; int r; - if (asprintf(&ifindex_str, "%i", link->ifindex) < 0) - return -ENOMEM; + xsprintf(ifindex_str, "%i", link->ifindex); r = sd_bus_path_encode("/org/freedesktop/network1/link", ifindex_str, &path); if (r < 0) @@ -1219,12 +1220,10 @@ static int list_address_labels(int argc, char *argv[], void *userdata) { } static int open_lldp_neighbors(int ifindex, FILE **ret) { - _cleanup_free_ char *p = NULL; + char p[STRLEN("/run/systemd/netif/lldp/") + DECIMAL_STR_MAX(int)]; FILE *f; - if (asprintf(&p, "/run/systemd/netif/lldp/%i", ifindex) < 0) - return -ENOMEM; - + xsprintf(p, "/run/systemd/netif/lldp/%i", ifindex); f = fopen(p, "re"); if (!f) return -errno; @@ -1552,7 +1551,7 @@ static int link_status_one( _cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **sip = NULL, **search_domains = NULL, **route_domains = NULL; _cleanup_free_ char *t = NULL, *network = NULL, *iaid = NULL, *duid = NULL, - *setup_state = NULL, *operational_state = NULL, *online_state = NULL, *lease_file = NULL, *activation_policy = NULL; + *setup_state = NULL, *operational_state = NULL, *online_state = NULL, *activation_policy = NULL; const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL, *link = NULL, *on_color_operational, *off_color_operational, *on_color_setup, *off_color_setup, *on_color_online; _cleanup_free_ int *carrier_bound_to = NULL, *carrier_bound_by = NULL; @@ -1602,8 +1601,8 @@ static int link_status_one( (void) sd_network_link_get_carrier_bound_to(info->ifindex, &carrier_bound_to); (void) sd_network_link_get_carrier_bound_by(info->ifindex, &carrier_bound_by); - if (asprintf(&lease_file, "/run/systemd/netif/leases/%d", info->ifindex) < 0) - return log_oom(); + char lease_file[STRLEN("/run/systemd/netif/leases/") + DECIMAL_STR_MAX(int)]; + xsprintf(lease_file, "/run/systemd/netif/leases/%i", info->ifindex); (void) dhcp_lease_load(&lease, lease_file); |