-/***
- 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 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;
assert(q);
assert(answer);
+ if (!m->read_etc_hosts)
+ return 0;
+
r = manager_etc_hosts_read(m);
if (r < 0)
return r;