summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Keller <rainer.keller@digia.com>2013-10-30 09:22:13 +0100
committerRainer Keller <rainer.keller@digia.com>2013-12-05 09:32:03 +0200
commit196ad45ac77a3762a6e41af1cfdd4c28ce4ba299 (patch)
tree8fbde910f076e58547953712d1bf5c2c45e04fe4
parent6f1f70fb23d969b985f51178fbbc5fc3f43d31eb (diff)
Start process with interactive process environment
Change-Id: I4fb38bd85099f1f9c3816f28abde04914c7e3abf Reviewed-by: Rainer Keller <rainer.keller@digia.com>
-rw-r--r--process.cpp71
-rw-r--r--process.h1
2 files changed, 72 insertions, 0 deletions
diff --git a/process.cpp b/process.cpp
index 539f8e9..acdaa99 100644
--- a/process.cpp
+++ b/process.cpp
@@ -178,7 +178,11 @@ void Process::finished(int exitCode, QProcess::ExitStatus exitStatus)
void Process::startup(QStringList args)
{
+#ifdef Q_OS_ANDROID
+ QProcessEnvironment pe = interactiveProcessEnvironment();
+#else
QProcessEnvironment pe = QProcessEnvironment::systemEnvironment();
+#endif
foreach (const QString &key, mConfig.env.keys()) {
qDebug() << key << mConfig.env.value(key);
@@ -239,3 +243,70 @@ void Process::setConfig(const Config &config)
{
mConfig = config;
}
+
+QProcessEnvironment Process::interactiveProcessEnvironment() const
+{
+ QProcessEnvironment env;
+
+ QProcess process;
+ process.start("sh");
+ if (!process.waitForStarted(3000)) {
+ printf("Could not start shell.\n");
+ return env;
+ }
+
+ process.write("source /system/etc/mkshrc\n");
+ process.write("export -p\n");
+ process.closeWriteChannel();
+
+ printf("waiting for process to finish\n");
+ if (!process.waitForFinished(1000)) {
+ printf("did not finish: terminate\n");
+ process.terminate();
+ if (!process.waitForFinished(1000)) {
+ printf("did not terminate: kill\n");
+ process.kill();
+ if (!process.waitForFinished(1000)) {
+ printf("Could not stop process.\n");
+ }
+ }
+ }
+
+ QList<QByteArray> list = process.readAllStandardOutput().split('\n');
+ if (list.isEmpty())
+ printf("Failed to read environment output\n");
+
+ foreach (QByteArray entry, list) {
+ if (entry.startsWith("export ")) {
+ entry = entry.mid(7);
+ } else if (entry.startsWith("declare -x ")) {
+ entry = entry.mid(11);
+ } else {
+ continue;
+ }
+
+ QByteArray key;
+ QByteArray value;
+ int index = entry.indexOf('=');
+
+ if (index > 0) {
+ key = entry.left(index);
+ value = entry.mid(index + 1);
+ } else {
+ key = entry;
+ // value is empty
+ }
+
+ // Remove simple escaping.
+ // This is not complete.
+ if (value.startsWith('\'') and value.endsWith('\''))
+ value = value.mid(1, value.size()-2);
+ else if (value.startsWith('"') and value.endsWith('"'))
+ value = value.mid(1, value.size()-2);
+
+ env.insert(key, value);
+ }
+
+ return env;
+}
+
diff --git a/process.h b/process.h
index c98da9a..bacfc41 100644
--- a/process.h
+++ b/process.h
@@ -63,6 +63,7 @@ private slots:
void incomingConnection(int);
private:
void startup(QStringList);
+ QProcessEnvironment interactiveProcessEnvironment() const;
QProcess *mProcess;
int mDebuggee;
bool mDebug;