From 256e9761676502ac7b481cbfe773201ae817130e Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 13 Jul 2020 02:50:27 +0400 Subject: [PATCH] Hide ProcessNameByPID and RealExecutablePath into a private namespace --- .../platform/linux/specific_linux.cpp | 54 +++++++++---------- .../platform/linux/specific_linux.h | 3 -- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index ba9a8835e0..ab48dfe87d 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -132,6 +132,33 @@ uint FileChooserPortalVersion() { } #endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION +QString ProcessNameByPID(const QString &pid) { + constexpr auto kMaxPath = 1024; + char result[kMaxPath] = { 0 }; + auto count = readlink("/proc/" + pid.toLatin1() + "/exe", result, kMaxPath); + if (count > 0) { + auto filename = QFile::decodeName(result); + auto deletedPostfix = qstr(" (deleted)"); + if (filename.endsWith(deletedPostfix) && !QFileInfo(filename).exists()) { + filename.chop(deletedPostfix.size()); + } + return filename; + } + + return QString(); +} + +QString RealExecutablePath(int argc, char *argv[]) { + const auto processName = ProcessNameByPID(qsl("self")); + + // Fallback to the first command line argument. + return !processName.isEmpty() + ? processName + : argc + ? QFile::decodeName(argv[0]) + : QString(); +} + bool RunShellCommand(const QByteArray &command) { auto result = system(command.constData()); if (result) { @@ -642,33 +669,6 @@ bool CanOpenDirectoryWithPortal() { #endif // (Qt < 5.15 && !DESKTOP_APP_QT_PATCHED) || TDESKTOP_DISABLE_DBUS_INTEGRATION } -QString ProcessNameByPID(const QString &pid) { - constexpr auto kMaxPath = 1024; - char result[kMaxPath] = { 0 }; - auto count = readlink("/proc/" + pid.toLatin1() + "/exe", result, kMaxPath); - if (count > 0) { - auto filename = QFile::decodeName(result); - auto deletedPostfix = qstr(" (deleted)"); - if (filename.endsWith(deletedPostfix) && !QFileInfo(filename).exists()) { - filename.chop(deletedPostfix.size()); - } - return filename; - } - - return QString(); -} - -QString RealExecutablePath(int argc, char *argv[]) { - const auto processName = ProcessNameByPID(qsl("self")); - - // Fallback to the first command line argument. - return !processName.isEmpty() - ? processName - : argc - ? QFile::decodeName(argv[0]) - : QString(); -} - QString CurrentExecutablePath(int argc, char *argv[]) { if (InAppImage()) { const auto appimagePath = QString::fromUtf8(qgetenv("APPIMAGE")); diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.h b/Telegram/SourceFiles/platform/linux/specific_linux.h index d94d518078..3d9158d285 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.h +++ b/Telegram/SourceFiles/platform/linux/specific_linux.h @@ -33,9 +33,6 @@ bool IsXDGDesktopPortalPresent(); bool UseXDGDesktopPortal(); bool CanOpenDirectoryWithPortal(); -QString ProcessNameByPID(const QString &pid); -QString RealExecutablePath(int argc, char *argv[]); - QString AppRuntimeDirectory(); QString GetLauncherBasename();