Fixed getParentName() to work analogously to isATBQTRunning().

This commit is contained in:
Gerhard Hoffmann 2023-09-11 10:12:20 +02:00
parent 7832ef5d8c
commit a03261d04a

View File

@ -2,7 +2,10 @@
#include "message_handler.h" #include "message_handler.h"
#include "git/git_client.h" #include "git/git_client.h"
#if defined (Q_OS_UNIX) || defined (Q_OS_LINUX)
#include "unistd.h" #include "unistd.h"
#endif
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
@ -180,18 +183,15 @@ bool Utils::sameFilesInDirs(QDir const &dir1, QDir const &dir2,
QString Utils::getParentName() { // get name of parent process QString Utils::getParentName() { // get name of parent process
QString ppid = QString("/proc/%1/status").arg(getppid()); QString ppid = QString("/proc/%1/status").arg(getppid());
QFile f(ppid); std::ifstream f(ppid.toStdString().c_str());
if (f.exists()) { if (f.is_open()) {
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { std::string next;
QTextStream in(&f); while (std::getline(f, next)) {
in.setCodec("UTF-8"); QString line = QString(next.c_str()).simplified();
while(!in.atEnd()) { if (line.startsWith("Name")) {
// Name: ATBQT int const idx = line.indexOf(QChar(':'));
QStringList line = in.readLine().split(':'); if (idx != -1) {
if (line.size() == 2) { return line.mid(idx+1).trimmed();
if (line[0].trimmed() == "Name") {
return line[1].trimmed();
}
} }
} }
} }