Commit 488b8e8e authored by Kai Koehne's avatar Kai Koehne
Browse files

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
Change-Id: I24d103bb15e77db69faae3bcfc736df25e4ec5d3
Reviewed-by: default avatarMichal Klocek <michal.klocek@qt.io>
Showing with 25 additions and 3 deletions
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <stdio.h> #include <stdio.h>
#include <memory>
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
...@@ -97,9 +98,30 @@ int main(int argc, const char **argv) ...@@ -97,9 +98,30 @@ int main(int argc, const char **argv)
initDpiAwareness(); initDpiAwareness();
#endif #endif
// QCoreApplication needs a non-const pointer, while the // Chromium on Linux manipulates argv to set a process title
// ContentMain in Chromium needs the pointer to be const. // (see set_process_title_linux.cc).
QCoreApplication qtApplication(argc, const_cast<char**>(argv)); // 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); return QtWebEngine::processMain(argc, argv);
} }
......
Supports Markdown
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