Skip to content

Commit

Permalink
fix: rewrite linux router dns flusher (#1335)
Browse files Browse the repository at this point in the history
Co-authored-by: sund3RRR <[email protected]>
  • Loading branch information
sund3RRR and sund3RRR authored Jan 8, 2025
1 parent 62f3a33 commit c3fb62a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
22 changes: 15 additions & 7 deletions service/server/router_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,29 @@ bool RouterLinux::routeDeleteList(const QString &gw, const QStringList &ips)
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()
{
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);

//check what the dns manager use
if (QFileInfo::exists("/usr/bin/nscd")
|| QFileInfo::exists("/usr/sbin/nscd")
|| QFileInfo::exists("/usr/lib/systemd/system/nscd.service"))
{
if (isServiceActive("nscd.service")) {
qDebug() << "Restarting nscd.service";
p.start("systemctl", { "restart", "nscd" });
}
else
{
} else if (isServiceActive("systemd-resolved.service")) {
qDebug() << "Restarting systemd-resolved.service";
p.start("systemctl", { "restart", "systemd-resolved" });
} else {
qDebug() << "No suitable DNS manager found.";
return;
}

p.waitForFinished();
Expand Down
1 change: 1 addition & 0 deletions service/server/router_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public slots:
RouterLinux(RouterLinux const &) = delete;
RouterLinux& operator= (RouterLinux const&) = delete;

bool isServiceActive(const QString &serviceName);
QList<Route> m_addedRoutes;
DnsUtilsLinux *m_dnsUtil;
};
Expand Down

0 comments on commit c3fb62a

Please sign in to comment.