From b14b29601157fafd3d807f9ca651079543de3494 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 4 Sep 2023 11:42:12 +0200 Subject: [PATCH] Added utility getParentName() (name of parent process) --- utils.cpp | 24 ++++++++++++++++++++++++ utils.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/utils.cpp b/utils.cpp index 1d3c7de..7640bf3 100644 --- a/utils.cpp +++ b/utils.cpp @@ -2,6 +2,8 @@ #include "message_handler.h" #include "git/git_client.h" +#include "unistd.h" + #include #include #include @@ -169,3 +171,25 @@ bool Utils::sameFilesInDirs(QDir const &dir1, QDir const &dir2, return true; } + + +QString Utils::getParentName() { // get name of parent process + QString ppid = QString("/proc/%1/status").arg(getppid()); + QFile f(ppid); + 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") { + return line[1].trimmed(); + } + } + } + } + } + return ""; +} diff --git a/utils.h b/utils.h index 7f16616..62f2c38 100644 --- a/utils.h +++ b/utils.h @@ -19,6 +19,9 @@ namespace Utils { QString rstrip(QString const &str); bool sameFilesInDirs(QDir const &dir1, QDir const &dir2, QStringList const &nameFilters = {"*.json"}); + + + QString getParentName(); } #endif // UTILS_H_INCLUDED