summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@qt.io>2018-02-19 15:57:36 +0100
committerKai Koehne <kai.koehne@qt.io>2018-02-26 10:31:48 +0000
commite5866624a201b48c16a043fe876f7da08dae90ee (patch)
tree73a230f555196e139e7ae41a5c7914ee581dc0a8
parent2e06a051404c250b847421364c098bf541c43773 (diff)
Separate argv for QCoreApplication and Chromium in WebEngineProcess
On Linux, Chromium manipulates argv, merging all command line arguments into argv[0] and deleting the other arguments - see set_process_title_linux.cc for the glory details. This potentially confuses QCoreApplication::applicationDirPath(), which assumes that argv[0] contains the binary path. This in turn caused a regression in Qt 5.9.4 where resource files could not be located anymore for QtWebEngineProcess. Avoid this by making two distinct copies of argv already in main(). Task-number: QTBUG-66346 Reviewed-by: Michal Klocek <michal.klocek@qt.io> (cherry picked from commit 488b8e8ed01018c155812e5cfb06162a5e216c7a) Change-Id: I22f0abf9e8a253a9cfcf919cdea6940a440a73e6
-rw-r--r--src/process/main.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/process/main.cpp b/src/process/main.cpp
index d2f9d2337..3b4ce9837 100644
--- a/src/process/main.cpp
+++ b/src/process/main.cpp
@@ -41,6 +41,7 @@
#include <QCoreApplication>
#include <stdio.h>
+#include <memory>
#if defined(Q_OS_LINUX)
@@ -97,9 +98,30 @@ int main(int argc, const char **argv)
initDpiAwareness();
#endif
- // QCoreApplication needs a non-const pointer, while the
- // ContentMain in Chromium needs the pointer to be const.
- QCoreApplication qtApplication(argc, const_cast<char**>(argv));
+ // Chromium on Linux manipulates argv to set a process title
+ // (see set_process_title_linux.cc).
+ // This can interfere with QCoreApplication::applicationFilePath,
+ // which assumes that argv[0] only contains the executable path.
+ //
+ // Avoid this by making a deep copy of argv and pass this
+ // to QCoreApplication. Use a unique_ptr with custom deleter to
+ // clean up on exit.
+
+ auto dt = [](char* av[]) {
+ for (char **a = av; *a; a++)
+ delete[] *a;
+ delete[] av;
+ };
+
+ std::unique_ptr<char*[], decltype(dt)> argv_(new char*[argc+1], dt);
+ for (int i = 0; i < argc; ++i) {
+ size_t len = strlen(argv[i]) + 1;
+ argv_[i] = new char[len];
+ strcpy(argv_[i], argv[i]);
+ }
+ argv_[argc] = 0;
+
+ QCoreApplication qtApplication(argc, argv_.get());
return QtWebEngine::processMain(argc, argv);
}