From: Lennart Poettering Date: Thu, 18 Oct 2018 14:16:52 +0000 (+0200) Subject: resolved-etc-hosts: FOREACH_LINE excorcism X-Git-Tag: v240~513^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c777a7773790375ce648d2a45f97fb2ce3cbd8b;p=thirdparty%2Fsystemd.git resolved-etc-hosts: FOREACH_LINE excorcism --- diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c index 5be62cc3a84..8074612fb47 100644 --- a/src/resolve/resolved-etc-hosts.c +++ b/src/resolve/resolved-etc-hosts.c @@ -1,10 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ +#include "def.h" #include "fd-util.h" #include "fileio.h" #include "hostname-util.h" -#include "resolved-etc-hosts.h" #include "resolved-dns-synthesize.h" +#include "resolved-etc-hosts.h" #include "string-util.h" #include "strv.h" #include "time-util.h" @@ -161,13 +162,19 @@ static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) { int etc_hosts_parse(EtcHosts *hosts, FILE *f) { _cleanup_(etc_hosts_free) EtcHosts t = {}; - char line[LINE_MAX]; unsigned nr = 0; int r; - FOREACH_LINE(line, f, return log_error_errno(errno, "Failed to read /etc/hosts: %m")) { + for (;;) { + _cleanup_free_ char *line = NULL; char *l; + r = read_line(f, LONG_LINE_MAX, &line); + if (r < 0) + return log_error_errno(r, "Failed to read /etc/hosts: %m"); + if (r == 0) + break; + nr++; l = strstrip(line);