From: Zbigniew Jędrzejewski-Szmek Date: Sat, 11 Jan 2020 10:37:26 +0000 (+0100) Subject: resolvectl: minor optimizations to allocate less X-Git-Tag: v245-rc1~138^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=957d9df388222850225dd8f9ba0a3e8457f864df;p=thirdparty%2Fsystemd.git resolvectl: minor optimizations to allocate less --- diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index 2dceaa5d215..df40349e662 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -27,6 +27,7 @@ #include "resolved-def.h" #include "resolved-dns-packet.h" #include "socket-netlink.h" +#include "stdio-util.h" #include "string-table.h" #include "strv.h" #include "terminal-util.h" @@ -1382,8 +1383,8 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; _cleanup_(link_info_clear) struct link_info link_info = {}; - _cleanup_free_ char *ifi = NULL, *p = NULL; - char ifname[IF_NAMESIZE + 1] = ""; + _cleanup_free_ char *p = NULL; + char ifi[DECIMAL_STR_MAX(int)], ifname[IF_NAMESIZE + 1] = ""; char **i; int r; @@ -1397,9 +1398,7 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode name = ifname; } - if (asprintf(&ifi, "%i", ifindex) < 0) - return log_oom(); - + xsprintf(ifi, "%i", ifindex); r = sd_bus_path_encode("/org/freedesktop/resolve1/link", ifi, &p); if (r < 0) return log_oom(); @@ -1819,6 +1818,7 @@ static int status_all(sd_bus *bus, StatusMode mode) { static int verb_status(int argc, char **argv, void *userdata) { sd_bus *bus = userdata; + _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL; int r = 0; if (argc > 1) { @@ -1828,7 +1828,7 @@ static int verb_status(int argc, char **argv, void *userdata) { STRV_FOREACH(ifname, argv + 1) { int ifindex, q; - ifindex = resolve_interface(NULL, *ifname); + ifindex = resolve_interface(&rtnl, *ifname); if (ifindex < 0) { log_warning_errno(ifindex, "Failed to resolve interface \"%s\", ignoring: %m", *ifname); continue;