isATBQTRunning():
Use std::fstream to read /proc/<pid>/status, as the lines end on '\r', not on '\n'.
This commit is contained in:
parent
ff6a6e0e45
commit
103b3f3f9c
27
utils.cpp
27
utils.cpp
@ -9,6 +9,9 @@
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
int Utils::read1stLineOfFile(QString fileName) {
|
||||
QFile f(fileName);
|
||||
@ -203,17 +206,19 @@ bool Utils::isATBQTRunning() {
|
||||
QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString const &nextStatusFile = it.next();
|
||||
QFile f(nextStatusFile);
|
||||
if (f.exists()) {
|
||||
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QTextStream in(&f);
|
||||
in.setCodec("UTF-8");
|
||||
while(!in.atEnd()) {
|
||||
// Name: ATBQT
|
||||
QStringList line = in.readLine().split(':');
|
||||
if (line.size() == 2) {
|
||||
if (line[0].trimmed() == "Name") {
|
||||
if (line[1].trimmed() == "ATBQT") {
|
||||
static const QRegularExpression re("^/proc/[0-9]{1,}/status");
|
||||
QRegularExpressionMatch match = re.match(nextStatusFile);
|
||||
if (match.hasMatch()) {
|
||||
std::ifstream f(nextStatusFile.toStdString().c_str());
|
||||
if (f.is_open()) {
|
||||
std::string next;
|
||||
while (std::getline(f, next)) {
|
||||
QString line = QString(next.c_str()).simplified();
|
||||
if (line.startsWith("Name")) {
|
||||
int const idx = line.indexOf(QChar(':'));
|
||||
if (idx != -1) {
|
||||
QString const binary = line.mid(idx+1).trimmed();
|
||||
if (binary == "ATBQT") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user