summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@pelagicore.com>2017-03-14 17:22:18 +0100
committerDominik Holland <dominik.holland@pelagicore.com>2017-03-14 16:46:08 +0000
commit73a175aee57f73c81864ca8b9d2f88e14448d80d (patch)
tree89b7f904e86b6ccc054966f8e514b8e30f4b845c
parent23aec4017a7e10b2342c82f6f3ac1bcde4cdc038 (diff)
downloadqtapplicationmanager-73a175aee57f73c81864ca8b9d2f88e14448d80d.tar.gz
Fix race condition in the controller when apps quit immediately
Change-Id: If77156dc3353a1fff3fe68b843b9bbbbc0157d59 Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
-rw-r--r--src/tools/controller/main.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/tools/controller/main.cpp b/src/tools/controller/main.cpp
index 2754a3f0..7efd656b 100644
--- a/src/tools/controller/main.cpp
+++ b/src/tools/controller/main.cpp
@@ -402,6 +402,24 @@ void startOrDebugApplication(const QString &debugWrapper, const QString &appId,
stopReply.waitForFinished();
}
+ static bool isStarted = false;
+
+ if (!stdRedirections.isEmpty()) {
+ // in case application quits -> quit the controller
+ QObject::connect(dbus.manager(), &IoQtApplicationManagerInterface::applicationRunStateChanged,
+ qApp, [appId](const QString &id, uint runState) {
+ if (isStarted && id == appId && runState == 0 /* NotRunning */) {
+ auto getReply = dbus.manager()->get(id);
+ getReply.waitForFinished();
+ if (getReply.isError())
+ throw Exception(Error::IO, "failed to get exit code from application-manager: %1").arg(getReply.error().message());
+ fprintf(stdout, "\n --- application has quit ---\n\n");
+ auto app = getReply.value();
+ qApp->exit(app.value(qSL("lastExitCode"), 1).toInt());
+ }
+ });
+ }
+
bool isDebug = !debugWrapper.isEmpty();
QDBusPendingReply<bool> reply;
if (stdRedirections.isEmpty()) {
@@ -422,11 +440,11 @@ void startOrDebugApplication(const QString &debugWrapper, const QString &appId,
.arg(reply.error().message()).arg(isDebug ? "debug" : "start");
}
- bool ok = reply.value();
+ isStarted = reply.value();
if (stdRedirections.isEmpty()) {
- qApp->exit(ok ? 0 : 2);
+ qApp->exit(isStarted ? 0 : 2);
} else {
- if (!ok) {
+ if (!isStarted) {
qApp->exit(2);
} else {
// on Ctrl+C or SIGTERM -> stop the application
@@ -472,20 +490,6 @@ void startOrDebugApplication(const QString &debugWrapper, const QString &appId,
};
(new HupThread(qApp))->start();
#endif // defined(POLLRDHUP)
-
- // in case application quits -> quit the controller
- QObject::connect(dbus.manager(), &IoQtApplicationManagerInterface::applicationRunStateChanged,
- qApp, [appId](const QString &id, uint runState) {
- if (id == appId && runState == 0 /* NotRunning */) {
- auto getReply = dbus.manager()->get(id);
- getReply.waitForFinished();
- if (getReply.isError())
- throw Exception(Error::IO, "failed to get exit code from application-manager: %1").arg(getReply.error().message());
- fprintf(stdout, "\n --- application has quit ---\n\n");
- auto app = getReply.value();
- qApp->exit(app.value(qSL("lastExitCode"), 1).toInt());
- }
- });
}
}
});