fix: rewrite linux router dns flusher (#1335)
Co-authored-by: sund3RRR <evenquantity@gamil.com>
This commit is contained in:
parent
62f3a339b7
commit
c3fb62a6ab
2 changed files with 16 additions and 7 deletions
|
@ -152,21 +152,29 @@ bool RouterLinux::routeDeleteList(const QString &gw, const QStringList &ips)
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RouterLinux::isServiceActive(const QString &serviceName) {
|
||||||
|
QProcess process;
|
||||||
|
process.start("systemctl", { "is-active", "--quiet", serviceName });
|
||||||
|
process.waitForFinished();
|
||||||
|
|
||||||
|
return process.exitCode() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
void RouterLinux::flushDns()
|
void RouterLinux::flushDns()
|
||||||
{
|
{
|
||||||
QProcess p;
|
QProcess p;
|
||||||
p.setProcessChannelMode(QProcess::MergedChannels);
|
p.setProcessChannelMode(QProcess::MergedChannels);
|
||||||
|
|
||||||
//check what the dns manager use
|
//check what the dns manager use
|
||||||
if (QFileInfo::exists("/usr/bin/nscd")
|
if (isServiceActive("nscd.service")) {
|
||||||
|| QFileInfo::exists("/usr/sbin/nscd")
|
qDebug() << "Restarting nscd.service";
|
||||||
|| QFileInfo::exists("/usr/lib/systemd/system/nscd.service"))
|
|
||||||
{
|
|
||||||
p.start("systemctl", { "restart", "nscd" });
|
p.start("systemctl", { "restart", "nscd" });
|
||||||
}
|
} else if (isServiceActive("systemd-resolved.service")) {
|
||||||
else
|
qDebug() << "Restarting systemd-resolved.service";
|
||||||
{
|
|
||||||
p.start("systemctl", { "restart", "systemd-resolved" });
|
p.start("systemctl", { "restart", "systemd-resolved" });
|
||||||
|
} else {
|
||||||
|
qDebug() << "No suitable DNS manager found.";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.waitForFinished();
|
p.waitForFinished();
|
||||||
|
|
|
@ -43,6 +43,7 @@ private:
|
||||||
RouterLinux(RouterLinux const &) = delete;
|
RouterLinux(RouterLinux const &) = delete;
|
||||||
RouterLinux& operator= (RouterLinux const&) = delete;
|
RouterLinux& operator= (RouterLinux const&) = delete;
|
||||||
|
|
||||||
|
bool isServiceActive(const QString &serviceName);
|
||||||
QList<Route> m_addedRoutes;
|
QList<Route> m_addedRoutes;
|
||||||
DnsUtilsLinux *m_dnsUtil;
|
DnsUtilsLinux *m_dnsUtil;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue