ts = now(CLOCK_MONOTONIC);
r = sd_bus_call(bus, req, SD_RESOLVED_QUERY_TIMEOUT_USEC, &error, &reply);
- if (r < 0) {
- log_error("%s: resolve call failed: %s", pretty, bus_error_message(&error, r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "%s: resolve call failed: %s", pretty, bus_error_message(&error, r));
ts = now(CLOCK_MONOTONIC) - ts;
return 0;
}
-static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode mode, bool *empty_line) {
-
- struct link_info {
- uint64_t scopes_mask;
- const char *llmnr;
- const char *mdns;
- const char *dns_over_tls;
- const char *dnssec;
- char *current_dns;
- char **dns;
- char **domains;
- char **ntas;
- bool dnssec_supported;
- } link_info = {};
+struct link_info {
+ uint64_t scopes_mask;
+ const char *llmnr;
+ const char *mdns;
+ const char *dns_over_tls;
+ const char *dnssec;
+ char *current_dns;
+ char **dns;
+ char **domains;
+ char **ntas;
+ bool dnssec_supported;
+};
+
+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[] = {
{ "ScopesMask", "t", NULL, offsetof(struct link_info, scopes_mask) },
{ "DNS", "a(iay)", map_link_dns_servers, offsetof(struct link_info, dns) },
{ "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_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] = "";
char **i;
&error,
&m,
&link_info);
- if (r < 0) {
- log_error_errno(r, "Failed to get link data for %i: %s", ifindex, bus_error_message(&error, r));
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to get link data for %i: %s", ifindex, bus_error_message(&error, r));
(void) pager_open(arg_no_pager, false);
- if (mode == STATUS_DNS) {
- r = status_print_strv_ifindex(ifindex, name, link_info.dns);
- goto finish;
- }
+ if (mode == STATUS_DNS)
+ return status_print_strv_ifindex(ifindex, name, link_info.dns);
- if (mode == STATUS_DOMAIN) {
- r = status_print_strv_ifindex(ifindex, name, link_info.domains);
- goto finish;
- }
+ if (mode == STATUS_DOMAIN)
+ return status_print_strv_ifindex(ifindex, name, link_info.domains);
- if (mode == STATUS_NTA) {
- r = status_print_strv_ifindex(ifindex, name, link_info.ntas);
- goto finish;
- }
+ if (mode == STATUS_NTA)
+ return status_print_strv_ifindex(ifindex, name, link_info.ntas);
if (mode == STATUS_LLMNR) {
printf("%sLink %i (%s)%s: %s\n",
ansi_highlight(), ifindex, name, ansi_normal(),
strna(link_info.llmnr));
- r = 0;
- goto finish;
+ return 0;
}
if (mode == STATUS_MDNS) {
ansi_highlight(), ifindex, name, ansi_normal(),
strna(link_info.mdns));
- r = 0;
- goto finish;
+ return 0;
}
if (mode == STATUS_PRIVATE) {
ansi_highlight(), ifindex, name, ansi_normal(),
strna(link_info.dns_over_tls));
- r = 0;
- goto finish;
+ return 0;
}
if (mode == STATUS_DNSSEC) {
ansi_highlight(), ifindex, name, ansi_normal(),
strna(link_info.dnssec));
- r = 0;
- goto finish;
+ return 0;
}
if (empty_line && *empty_line)
if (empty_line)
*empty_line = true;
- r = 0;
-
-finish:
- free(link_info.current_dns);
- strv_free(link_info.dns);
- strv_free(link_info.domains);
- strv_free(link_info.ntas);
- return r;
+ return 0;
}
static int map_global_dns_servers(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
return 0;
}
-static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) {
-
- struct global_info {
- char *current_dns;
- char **dns;
- char **fallback_dns;
- char **domains;
- char **ntas;
- const char *llmnr;
- const char *mdns;
- const char *dns_over_tls;
- const char *dnssec;
- bool dnssec_supported;
- } global_info = {};
+struct global_info {
+ char *current_dns;
+ char **dns;
+ char **fallback_dns;
+ char **domains;
+ char **ntas;
+ const char *llmnr;
+ const char *mdns;
+ const char *dns_over_tls;
+ const char *dnssec;
+ bool dnssec_supported;
+};
+
+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[] = {
{ "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) },
{ "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_message_unrefp) sd_bus_message *m = NULL;
+ _cleanup_(global_info_clear) struct global_info global_info = {};
char **i;
int r;
&error,
&m,
&global_info);
- if (r < 0) {
- log_error_errno(r, "Failed to get global data: %s", bus_error_message(&error, r));
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to get global data: %s", bus_error_message(&error, r));
(void) pager_open(arg_no_pager, false);
- if (mode == STATUS_DNS) {
- r = status_print_strv_global(global_info.dns);
- goto finish;
- }
+ if (mode == STATUS_DNS)
+ return status_print_strv_global(global_info.dns);
- if (mode == STATUS_DOMAIN) {
- r = status_print_strv_global(global_info.domains);
- goto finish;
- }
+ if (mode == STATUS_DOMAIN)
+ return status_print_strv_global(global_info.domains);
- if (mode == STATUS_NTA) {
- r = status_print_strv_global(global_info.ntas);
- goto finish;
- }
+ if (mode == STATUS_NTA)
+ return status_print_strv_global(global_info.ntas);
if (mode == STATUS_LLMNR) {
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
strna(global_info.llmnr));
- r = 0;
- goto finish;
+ return 0;
}
if (mode == STATUS_MDNS) {
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
strna(global_info.mdns));
- r = 0;
- goto finish;
+ return 0;
}
if (mode == STATUS_PRIVATE) {
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
strna(global_info.dns_over_tls));
- r = 0;
- goto finish;
+ return 0;
}
if (mode == STATUS_DNSSEC) {
printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(),
strna(global_info.dnssec));
- r = 0;
- goto finish;
+ return 0;
}
printf("%sGlobal%s\n", ansi_highlight(), ansi_normal());
*empty_line = true;
- r = 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;
+ return 0;
}
static int status_all(sd_bus *bus, StatusMode mode) {