Skip to content

Commit 2773e54

Browse files
committed
core/process: ignore environment changes made by the Env pragma
This pragma ends up used to set things like QQC theme which shouldn't be cascaded into child processes.
1 parent 4a0f638 commit 2773e54

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

src/core/common.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "common.hpp"
22

33
#include <qdatetime.h>
4+
#include <qprocess.h>
45

56
namespace qs {
67

78
const QDateTime Common::LAUNCH_TIME = QDateTime::currentDateTime();
9+
QProcessEnvironment Common::INITIAL_ENVIRONMENT = {}; // NOLINT
810

9-
}
11+
} // namespace qs

src/core/common.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#pragma once
22

33
#include <qdatetime.h>
4+
#include <qprocess.h>
45

56
namespace qs {
67

78
struct Common {
89
static const QDateTime LAUNCH_TIME;
10+
static QProcessEnvironment INITIAL_ENVIRONMENT; // NOLINT
911
};
1012

1113
} // namespace qs

src/core/desktopentry.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <qtenvironmentvariables.h>
1717
#include <ranges>
1818

19+
#include "common.hpp"
1920
#include "model.hpp"
2021

2122
namespace {
@@ -260,6 +261,7 @@ void DesktopEntry::doExec(const QString& execString, const QString& workingDirec
260261
process.setProgram(args.at(0));
261262
process.setArguments(args.sliced(1));
262263
if (!workingDirectory.isEmpty()) process.setWorkingDirectory(workingDirectory);
264+
process.setProcessEnvironment(qs::Common::INITIAL_ENVIRONMENT);
263265
process.startDetached();
264266
}
265267

src/io/process.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <qtypes.h>
1414
#include <qvariant.h>
1515

16+
#include "../core/common.hpp"
1617
#include "../core/generation.hpp"
1718
#include "../core/qmlglobal.hpp"
1819
#include "datastream.hpp"
@@ -223,26 +224,24 @@ void Process::setupEnvironment(QProcess* process) {
223224
process->setWorkingDirectory(this->mWorkingDirectory);
224225
}
225226

226-
if (!this->mEnvironment.isEmpty() || this->mClearEnvironment) {
227-
auto sysenv = QProcessEnvironment::systemEnvironment();
228-
auto env = this->mClearEnvironment ? QProcessEnvironment() : sysenv;
229-
230-
for (auto& name: this->mEnvironment.keys()) {
231-
auto value = this->mEnvironment.value(name);
232-
if (!value.isValid()) continue;
233-
234-
if (this->mClearEnvironment) {
235-
if (value.isNull()) {
236-
if (sysenv.contains(name)) env.insert(name, sysenv.value(name));
237-
} else env.insert(name, value.toString());
238-
} else {
239-
if (value.isNull()) env.remove(name);
240-
else env.insert(name, value.toString());
241-
}
242-
}
227+
const auto& sysenv = qs::Common::INITIAL_ENVIRONMENT;
228+
auto env = this->mClearEnvironment ? QProcessEnvironment() : sysenv;
229+
230+
for (auto& name: this->mEnvironment.keys()) {
231+
auto value = this->mEnvironment.value(name);
232+
if (!value.isValid()) continue;
243233

244-
process->setProcessEnvironment(env);
234+
if (this->mClearEnvironment) {
235+
if (value.isNull()) {
236+
if (sysenv.contains(name)) env.insert(name, sysenv.value(name));
237+
} else env.insert(name, value.toString());
238+
} else {
239+
if (value.isNull()) env.remove(name);
240+
else env.insert(name, value.toString());
241+
}
245242
}
243+
244+
process->setProcessEnvironment(env);
246245
}
247246

248247
void Process::onStarted() {

src/launch/launch.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <qlist.h>
1010
#include <qlogging.h>
1111
#include <qnamespace.h>
12+
#include <qprocess.h>
1213
#include <qqmldebug.h>
1314
#include <qquickwindow.h>
1415
#include <qstring.h>
@@ -151,6 +152,8 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
151152
QsPaths::instance()->linkPathDir();
152153
LogManager::initFs();
153154

155+
Common::INITIAL_ENVIRONMENT = QProcessEnvironment::systemEnvironment();
156+
154157
for (auto [var, val]: pragmas.envOverrides.asKeyValueRange()) {
155158
qputenv(var.toUtf8(), val.toUtf8());
156159
}

0 commit comments

Comments
 (0)