Commit 31c75e48 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

Read BAMF_DESKTOP_FILE_HINT from environment

This contains the actual name of the desktop file which might be different from the one the application got built with.

Differential Revision: https://phabricator.kde.org/D22506
parent c3e4c731
......@@ -503,6 +503,31 @@ KService::List servicesFromPid(quint32 pid, KSharedConfig::Ptr rulesConfig)
return KService::List();
}
// Read the BAMF_DESKTOP_FILE_HINT environment variable which contains the actual desktop file path for Snaps.
QFile environFile(QStringLiteral("/proc/%1/environ").arg(QString::number(pid)));
if (environFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
const QByteArray bamfDesktopFileHint = QByteArrayLiteral("BAMF_DESKTOP_FILE_HINT");
const auto lines = environFile.readAll().split('\0');
for (const QByteArray &line : lines) {
const int equalsIdx = line.indexOf('=');
if (equalsIdx <= 0) {
continue;
}
const QByteArray key = line.left(equalsIdx);
if (key == bamfDesktopFileHint) {
const QByteArray value = line.mid(equalsIdx + 1);
KService::Ptr service = KService::serviceByDesktopPath(QString::fromUtf8(value));
if (service) {
return {service};
}
break;
}
}
}
auto proc = KProcessList::processInfo(pid);
if (!proc.isValid()) {
return KService::List();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment