Skip to content

Commit

Permalink
bugfix: Correctly use QProcess::start and QProcess::execute (#1331)
Browse files Browse the repository at this point in the history
Affected functions (all on Linux/Mac):
 - `RouterLinux::flushDns` was not reloading the DNS manager.
 - `Utils::processIsRunning` was always saying that the process
   is not running when `fullFlag` was set to `false`.
 - `Utils::killProcessByName` was not killing anything.
  • Loading branch information
al42and authored Dec 31, 2024
1 parent 6acaab0 commit a741186
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions client/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,13 @@ bool Utils::processIsRunning(const QString &fileName, const bool fullFlag)
return false;
#else
QProcess process;
QStringList arguments;
if (fullFlag) {
arguments << "-f";
}
arguments << fileName;
process.setProcessChannelMode(QProcess::MergedChannels);
process.start("pgrep", QStringList({ fullFlag ? "-f" : "", fileName }));
process.start("pgrep", arguments);
process.waitForFinished();
if (process.exitStatus() == QProcess::NormalExit) {
if (fullFlag) {
Expand Down Expand Up @@ -248,7 +253,7 @@ bool Utils::killProcessByName(const QString &name)
#elif defined Q_OS_IOS || defined(Q_OS_ANDROID)
return false;
#else
return QProcess::execute(QString("pkill %1").arg(name)) == 0;
return QProcess::execute("pkill", { name }) == 0;
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions service/server/router_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ void RouterLinux::flushDns()
|| QFileInfo::exists("/usr/sbin/nscd")
|| QFileInfo::exists("/usr/lib/systemd/system/nscd.service"))
{
p.start("systemctl restart nscd");
p.start("systemctl", { "restart", "nscd" });
}
else
{
p.start("systemctl restart systemd-resolved");
p.start("systemctl", { "restart", "systemd-resolved" });
}

p.waitForFinished();
Expand Down

0 comments on commit a741186

Please sign in to comment.