OSDN Git Service

attempt to guess application name from /proc/<pid>/exe in QCoreApplication::applicati...
authorIvailo Monev <xakepa10@gmail.com>
Fri, 12 Feb 2021 12:12:09 +0000 (14:12 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Fri, 12 Feb 2021 12:12:09 +0000 (14:12 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/codecs/qtextcodec.cpp
src/core/kernel/qcoreapplication.cpp

index 18aeaf4..63e161b 100644 (file)
@@ -124,13 +124,13 @@ static void setupLocaleMapper()
         // 1. CODESET from ctype if it contains a .CODESET part (e.g. en_US.ISO8859-15)
         int indexOfDot = ctype.indexOf('.');
         if (indexOfDot != -1)
-            localeMapper = checkForCodec( ctype.mid(indexOfDot + 1) );
+            localeMapper = checkForCodec(ctype.mid(indexOfDot + 1));
 
         // 2. CODESET from lang if it contains a .CODESET part
         if (!localeMapper) {
             indexOfDot = lang.indexOf('.');
             if (indexOfDot != -1)
-                localeMapper = checkForCodec( lang.mid(indexOfDot + 1) );
+                localeMapper = checkForCodec(lang.mid(indexOfDot + 1));
         }
 
         // 3. ctype (maybe the locale is named "ISO-8859-1" or something)
index 6639643..5828893 100644 (file)
@@ -1584,6 +1584,18 @@ QString QCoreApplication::applicationName()
         name = QString::fromLocal8Bit(::getprogname());
     }
 #else
+#if defined(QT_HAVE_PROC_EXE)
+    if (name.isEmpty()) {
+        // Try looking for a /proc/<pid>/exe symlink first which points to
+        // the absolute path of the executable
+        QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(::getpid()));
+        if (pfi.exists() && pfi.isSymLink()) {
+            pfi.setFile(pfi.canonicalFilePath());
+            name = pfi.baseName();
+        }
+    }
+#endif
+
     if (name.isEmpty() && self) {
         char ** const argv = self->d_func()->argv;
         if (argv[0]) {