resolve: use _cleanup_ attribute
This commit is contained in:
parent
354f62cf3c
commit
906119c046
|
@ -1370,9 +1370,7 @@ static int status_print_strv_ifindex(int ifindex, const char *ifname, char **p)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode mode, bool *empty_line) {
|
struct link_info {
|
||||||
|
|
||||||
struct link_info {
|
|
||||||
uint64_t scopes_mask;
|
uint64_t scopes_mask;
|
||||||
const char *llmnr;
|
const char *llmnr;
|
||||||
const char *mdns;
|
const char *mdns;
|
||||||
|
@ -1383,8 +1381,16 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode
|
||||||
char **domains;
|
char **domains;
|
||||||
char **ntas;
|
char **ntas;
|
||||||
bool dnssec_supported;
|
bool dnssec_supported;
|
||||||
} link_info = {};
|
};
|
||||||
|
|
||||||
|
static void link_info_clear(struct link_info *p) {
|
||||||
|
free(p->current_dns);
|
||||||
|
strv_free(p->dns);
|
||||||
|
strv_free(p->domains);
|
||||||
|
strv_free(p->ntas);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode mode, bool *empty_line) {
|
||||||
static const struct bus_properties_map property_map[] = {
|
static const struct bus_properties_map property_map[] = {
|
||||||
{ "ScopesMask", "t", NULL, offsetof(struct link_info, scopes_mask) },
|
{ "ScopesMask", "t", NULL, offsetof(struct link_info, scopes_mask) },
|
||||||
{ "DNS", "a(iay)", map_link_dns_servers, offsetof(struct link_info, dns) },
|
{ "DNS", "a(iay)", map_link_dns_servers, offsetof(struct link_info, dns) },
|
||||||
|
@ -1398,9 +1404,9 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode
|
||||||
{ "DNSSECSupported", "b", NULL, offsetof(struct link_info, dnssec_supported) },
|
{ "DNSSECSupported", "b", NULL, offsetof(struct link_info, dnssec_supported) },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = 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;
|
_cleanup_free_ char *ifi = NULL, *p = NULL;
|
||||||
char ifname[IF_NAMESIZE] = "";
|
char ifname[IF_NAMESIZE] = "";
|
||||||
char **i;
|
char **i;
|
||||||
|
@ -1431,35 +1437,26 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode
|
||||||
&error,
|
&error,
|
||||||
&m,
|
&m,
|
||||||
&link_info);
|
&link_info);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to get link data for %i: %s", ifindex, bus_error_message(&error, r));
|
return log_error_errno(r, "Failed to get link data for %i: %s", ifindex, bus_error_message(&error, r));
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) pager_open(arg_no_pager, false);
|
(void) pager_open(arg_no_pager, false);
|
||||||
|
|
||||||
if (mode == STATUS_DNS) {
|
if (mode == STATUS_DNS)
|
||||||
r = status_print_strv_ifindex(ifindex, name, link_info.dns);
|
return status_print_strv_ifindex(ifindex, name, link_info.dns);
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == STATUS_DOMAIN) {
|
if (mode == STATUS_DOMAIN)
|
||||||
r = status_print_strv_ifindex(ifindex, name, link_info.domains);
|
return status_print_strv_ifindex(ifindex, name, link_info.domains);
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == STATUS_NTA) {
|
if (mode == STATUS_NTA)
|
||||||
r = status_print_strv_ifindex(ifindex, name, link_info.ntas);
|
return status_print_strv_ifindex(ifindex, name, link_info.ntas);
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == STATUS_LLMNR) {
|
if (mode == STATUS_LLMNR) {
|
||||||
printf("%sLink %i (%s)%s: %s\n",
|
printf("%sLink %i (%s)%s: %s\n",
|
||||||
ansi_highlight(), ifindex, name, ansi_normal(),
|
ansi_highlight(), ifindex, name, ansi_normal(),
|
||||||
strna(link_info.llmnr));
|
strna(link_info.llmnr));
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == STATUS_MDNS) {
|
if (mode == STATUS_MDNS) {
|
||||||
|
@ -1467,8 +1464,7 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode
|
||||||
ansi_highlight(), ifindex, name, ansi_normal(),
|
ansi_highlight(), ifindex, name, ansi_normal(),
|
||||||
strna(link_info.mdns));
|
strna(link_info.mdns));
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == STATUS_PRIVATE) {
|
if (mode == STATUS_PRIVATE) {
|
||||||
|
@ -1476,8 +1472,7 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode
|
||||||
ansi_highlight(), ifindex, name, ansi_normal(),
|
ansi_highlight(), ifindex, name, ansi_normal(),
|
||||||
strna(link_info.dns_over_tls));
|
strna(link_info.dns_over_tls));
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == STATUS_DNSSEC) {
|
if (mode == STATUS_DNSSEC) {
|
||||||
|
@ -1485,8 +1480,7 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode
|
||||||
ansi_highlight(), ifindex, name, ansi_normal(),
|
ansi_highlight(), ifindex, name, ansi_normal(),
|
||||||
strna(link_info.dnssec));
|
strna(link_info.dnssec));
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty_line && *empty_line)
|
if (empty_line && *empty_line)
|
||||||
|
@ -1540,14 +1534,7 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode
|
||||||
if (empty_line)
|
if (empty_line)
|
||||||
*empty_line = true;
|
*empty_line = true;
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
|
|
||||||
finish:
|
|
||||||
free(link_info.current_dns);
|
|
||||||
strv_free(link_info.dns);
|
|
||||||
strv_free(link_info.domains);
|
|
||||||
strv_free(link_info.ntas);
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int map_global_dns_servers(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
|
static int map_global_dns_servers(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
|
||||||
|
@ -1644,9 +1631,7 @@ static int status_print_strv_global(char **p) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) {
|
struct global_info {
|
||||||
|
|
||||||
struct global_info {
|
|
||||||
char *current_dns;
|
char *current_dns;
|
||||||
char **dns;
|
char **dns;
|
||||||
char **fallback_dns;
|
char **fallback_dns;
|
||||||
|
@ -1657,8 +1642,17 @@ static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) {
|
||||||
const char *dns_over_tls;
|
const char *dns_over_tls;
|
||||||
const char *dnssec;
|
const char *dnssec;
|
||||||
bool dnssec_supported;
|
bool dnssec_supported;
|
||||||
} global_info = {};
|
};
|
||||||
|
|
||||||
|
static void global_info_clear(struct global_info *p) {
|
||||||
|
free(p->current_dns);
|
||||||
|
strv_free(p->dns);
|
||||||
|
strv_free(p->fallback_dns);
|
||||||
|
strv_free(p->domains);
|
||||||
|
strv_free(p->ntas);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) {
|
||||||
static const struct bus_properties_map property_map[] = {
|
static const struct bus_properties_map property_map[] = {
|
||||||
{ "DNS", "a(iiay)", map_global_dns_servers, offsetof(struct global_info, dns) },
|
{ "DNS", "a(iiay)", map_global_dns_servers, offsetof(struct global_info, dns) },
|
||||||
{ "FallbackDNS", "a(iiay)", map_global_dns_servers, offsetof(struct global_info, fallback_dns) },
|
{ "FallbackDNS", "a(iiay)", map_global_dns_servers, offsetof(struct global_info, fallback_dns) },
|
||||||
|
@ -1672,9 +1666,9 @@ static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) {
|
||||||
{ "DNSSECSupported", "b", NULL, offsetof(struct global_info, dnssec_supported) },
|
{ "DNSSECSupported", "b", NULL, offsetof(struct global_info, dnssec_supported) },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||||
|
_cleanup_(global_info_clear) struct global_info global_info = {};
|
||||||
char **i;
|
char **i;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -1689,58 +1683,46 @@ static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) {
|
||||||
&error,
|
&error,
|
||||||
&m,
|
&m,
|
||||||
&global_info);
|
&global_info);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to get global data: %s", bus_error_message(&error, r));
|
return log_error_errno(r, "Failed to get global data: %s", bus_error_message(&error, r));
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) pager_open(arg_no_pager, false);
|
(void) pager_open(arg_no_pager, false);
|
||||||
|
|
||||||
if (mode == STATUS_DNS) {
|
if (mode == STATUS_DNS)
|
||||||
r = status_print_strv_global(global_info.dns);
|
return status_print_strv_global(global_info.dns);
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == STATUS_DOMAIN) {
|
if (mode == STATUS_DOMAIN)
|
||||||
r = status_print_strv_global(global_info.domains);
|
return status_print_strv_global(global_info.domains);
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == STATUS_NTA) {
|
if (mode == STATUS_NTA)
|
||||||
r = status_print_strv_global(global_info.ntas);
|
return status_print_strv_global(global_info.ntas);
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == STATUS_LLMNR) {
|
if (mode == STATUS_LLMNR) {
|
||||||
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
|
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
|
||||||
strna(global_info.llmnr));
|
strna(global_info.llmnr));
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == STATUS_MDNS) {
|
if (mode == STATUS_MDNS) {
|
||||||
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
|
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
|
||||||
strna(global_info.mdns));
|
strna(global_info.mdns));
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == STATUS_PRIVATE) {
|
if (mode == STATUS_PRIVATE) {
|
||||||
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
|
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
|
||||||
strna(global_info.dns_over_tls));
|
strna(global_info.dns_over_tls));
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == STATUS_DNSSEC) {
|
if (mode == STATUS_DNSSEC) {
|
||||||
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
|
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
|
||||||
strna(global_info.dnssec));
|
strna(global_info.dnssec));
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%sGlobal%s\n", ansi_highlight(), ansi_normal());
|
printf("%sGlobal%s\n", ansi_highlight(), ansi_normal());
|
||||||
|
@ -1786,16 +1768,7 @@ static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) {
|
||||||
|
|
||||||
*empty_line = true;
|
*empty_line = true;
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
|
|
||||||
finish:
|
|
||||||
free(global_info.current_dns);
|
|
||||||
strv_free(global_info.dns);
|
|
||||||
strv_free(global_info.fallback_dns);
|
|
||||||
strv_free(global_info.domains);
|
|
||||||
strv_free(global_info.ntas);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int status_all(sd_bus *bus, StatusMode mode) {
|
static int status_all(sd_bus *bus, StatusMode mode) {
|
||||||
|
|
Loading…
Reference in a new issue