sd-network: introduce network_link_get_boolean() helper function

This commit is contained in:
Yu Watanabe
2022-09-24 09:20:36 +09:00
parent 27b13df45a
commit c9d22489ca

View File

@@ -120,6 +120,17 @@ static int network_link_get_string(int ifindex, const char *field, char **ret) {
return 0;
}
static int network_link_get_boolean(int ifindex, const char *key) {
_cleanup_free_ char *s = NULL;
int r;
r = network_link_get_string(ifindex, key, &s);
if (r < 0)
return r;
return parse_boolean(s);
}
static int network_link_get_strv(int ifindex, const char *key, char ***ret) {
char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex)];
_cleanup_strv_free_ char **a = NULL;
@@ -307,20 +318,7 @@ int sd_network_link_get_route_domains(int ifindex, char ***ret) {
}
int sd_network_link_get_dns_default_route(int ifindex) {
char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex)];
_cleanup_free_ char *s = NULL;
int r;
assert_return(ifindex > 0, -EINVAL);
xsprintf(path, "/run/systemd/netif/links/%i", ifindex);
r = parse_env_file(NULL, path, "DNS_DEFAULT_ROUTE", &s);
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
return parse_boolean(s);
return network_link_get_boolean(ifindex, "DNS_DEFAULT_ROUTE");
}
static int network_link_get_ifindexes(int ifindex, const char *key, int **ret) {