From 6800e168d5ac780f57a4659b0636bc2f072440a2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 17 Apr 2024 22:05:04 -0700 Subject: [PATCH] tst_QDnsLookup: also use the nameservers behind systemd-resolved MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the file exists, we are using systemd-resolved, so let's try directly using the nameservers it uses. Change-Id: I455fe22ef4ad4b2f9b01fffd17c7476a2385bf4b Reviewed-by: MÃ¥rten Nordheim --- .../kernel/qdnslookup/tst_qdnslookup.cpp | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp b/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp index cfb764e796..b4619166cc 100644 --- a/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp +++ b/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp @@ -91,19 +91,23 @@ static QList systemNameservers() } } #else - QFile f("/etc/resolv.conf"); - if (!f.open(QIODevice::ReadOnly)) - return result; + auto parseFile = [&](QLatin1StringView path) { + QFile f(path); + if (!f.open(QIODevice::ReadOnly)) + return; - while (!f.atEnd()) { - static const char command[] = "nameserver"; - QByteArray line = f.readLine().simplified(); - if (!line.startsWith(command)) - continue; + while (!f.atEnd()) { + static const char command[] = "nameserver"; + QByteArray line = f.readLine().simplified(); + if (!line.startsWith(command)) + continue; - QString addr = QLatin1StringView(line).mid(sizeof(command)); - result.emplaceBack(addr); - } + QString addr = QLatin1StringView(line).mid(sizeof(command)); + result.emplaceBack(addr); + } + }; + parseFile("/etc/resolv.conf"_L1); + parseFile("/run/systemd/resolve/resolv.conf"_L1); #endif return result;