-/***
- This file is part of systemd.
-
- Copyright 2016 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
+/* SPDX-License-Identifier: LGPL-2.1+ */
#include "fd-util.h"
#include "fileio.h"
static int etc_hosts_item_compare_func(const void *a, const void *b) {
const EtcHostsItem *x = a, *y = b;
- if (x->family != x->family)
+ if (x->family != y->family)
return x->family - y->family;
if (x->family == AF_INET)
};
static int add_item(Manager *m, int family, const union in_addr_union *address, char **names) {
-
+ _cleanup_strv_free_ char **dummy = names;
EtcHostsItem key = {
.family = family,
.address = *address,
if (r < 0)
return log_oom();
- item = new0(EtcHostsItem, 1);
+ item = new(EtcHostsItem, 1);
if (!item)
return log_oom();
- item->family = family;
- item->address = *address;
- item->names = names;
+ *item = (EtcHostsItem) {
+ .family = family,
+ .address = *address,
+ .names = names,
+ };
r = set_put(m->etc_hosts_by_address, item);
if (r < 0) {
free(item);
return log_oom();
}
+
+ dummy = NULL;
}
}
return r;
}
-int manager_etc_hosts_read(Manager *m) {
+static int manager_etc_hosts_read(Manager *m) {
_cleanup_fclose_ FILE *f = NULL;
char line[LINE_MAX];
struct stat st;
FOREACH_LINE(line, f, return log_error_errno(errno, "Failed to read /etc/hosts: %m")) {
char *l;
- nr ++;
+ nr++;
l = strstrip(line);
if (isempty(l))
assert(q);
assert(answer);
+ if (!m->read_etc_hosts)
+ return 0;
+
r = manager_etc_hosts_read(m);
if (r < 0)
return r;
if (!IN_SET(t->class, DNS_CLASS_IN, DNS_CLASS_ANY))
continue;
- r = dns_name_equal(DNS_RESOURCE_KEY_NAME(t), name);
+ r = dns_name_equal(dns_resource_key_name(t), name);
if (r < 0)
return r;
if (r > 0) {
if (!IN_SET(t->class, DNS_CLASS_IN, DNS_CLASS_ANY))
continue;
- r = dns_name_equal(DNS_RESOURCE_KEY_NAME(t), name);
+ r = dns_name_equal(dns_resource_key_name(t), name);
if (r < 0)
return r;
if (r == 0)
for (i = 0; i < bn->n_items; i++) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
- if ((found_a && bn->items[i]->family != AF_INET) &&
- (found_aaaa && bn->items[i]->family != AF_INET6))
+ if ((!found_a && bn->items[i]->family == AF_INET) ||
+ (!found_aaaa && bn->items[i]->family == AF_INET6))
continue;
r = dns_resource_record_new_address(&rr, bn->items[i]->family, &bn->items[i]->address, bn->name);
return r;
}
- return 1;
+ return found_a || found_aaaa;
}