From 7c777a7773790375ce648d2a45f97fb2ce3cbd8b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 18 Oct 2018 16:16:52 +0200 Subject: [PATCH] resolved-etc-hosts: FOREACH_LINE excorcism --- src/resolve/resolved-etc-hosts.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c index 5be62cc..8074612 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); -- 2.7.4