resolvectl: minor optimizations to allocate less

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-01-11 11:37:26 +01:00
parent d308bb99d2
commit 957d9df388

View file

@ -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;