isATBQTRunning():

Use std::fstream to read /proc/<pid>/status, as the lines
end on '\r', not on '\n'.
This commit is contained in:
Gerhard Hoffmann 2023-09-10 16:46:59 +02:00
parent ff6a6e0e45
commit 103b3f3f9c

View File

@ -9,6 +9,9 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QDirIterator> #include <QDirIterator>
#include <QRegularExpression>
#include <fstream>
int Utils::read1stLineOfFile(QString fileName) { int Utils::read1stLineOfFile(QString fileName) {
QFile f(fileName); QFile f(fileName);
@ -203,17 +206,19 @@ bool Utils::isATBQTRunning() {
QDirIterator::Subdirectories); QDirIterator::Subdirectories);
while (it.hasNext()) { while (it.hasNext()) {
QString const &nextStatusFile = it.next(); QString const &nextStatusFile = it.next();
QFile f(nextStatusFile); static const QRegularExpression re("^/proc/[0-9]{1,}/status");
if (f.exists()) { QRegularExpressionMatch match = re.match(nextStatusFile);
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { if (match.hasMatch()) {
QTextStream in(&f); std::ifstream f(nextStatusFile.toStdString().c_str());
in.setCodec("UTF-8"); if (f.is_open()) {
while(!in.atEnd()) { std::string next;
// Name: ATBQT while (std::getline(f, next)) {
QStringList line = in.readLine().split(':'); QString line = QString(next.c_str()).simplified();
if (line.size() == 2) { if (line.startsWith("Name")) {
if (line[0].trimmed() == "Name") { int const idx = line.indexOf(QChar(':'));
if (line[1].trimmed() == "ATBQT") { if (idx != -1) {
QString const binary = line.mid(idx+1).trimmed();
if (binary == "ATBQT") {
return true; return true;
} }
} }