Merge lp:~gerboland/unity-mir/shutdown-crash-fix3 into lp:unity-mir/devel-mir-next

Proposed by Gerry Boland
Status: Merged
Approved by: Michał Sawicz
Approved revision: 223
Merged at revision: 220
Proposed branch: lp:~gerboland/unity-mir/shutdown-crash-fix3
Merge into: lp:unity-mir/devel-mir-next
Diff against target: 62 lines (+22/-3)
1 file modified
src/unity-mir/qmirserver.cpp (+22/-3)
To merge this branch: bzr merge lp:~gerboland/unity-mir/shutdown-crash-fix3
Reviewer Review Type Date Requested Status
Michał Sawicz Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+218394@code.launchpad.net

Commit message

Fix crash on Mir-initiated shutdown, where stop() was being called on an already shutting-down server.

Mir initiates shutdown on SIGINT & SIGTERM, need to distinguish that shutdown from a client-initiated shutdown. Do this by installing a custom signal handler that is run after Mir's initiate-shutdown handler is called, so that we only call server.stop() on a client-initiated shutdown.

Description of the change

Fix crash on Mir-initiated shutdown, where stop() was being called on an already shutting-down server

To test, need to cover 2 use-cases:
1. Mir-initiated shutdown: run unity8 manually in shell, then hit Ctrl+C - should not crash
2. Qt-initiated shutdown: the first-run wizard, when it has completed, calls Qt.quit() on itself. This should cleanly shutdown the process.

To post a comment you must log in.
221. By Gerry Boland

bump

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
222. By Gerry Boland

Missing csignal header

223. By Gerry Boland

Add Mir main_loop.h header

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

Yeah, tested both unity8 and the wizard and things are better.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-mir/qmirserver.cpp'
2--- src/unity-mir/qmirserver.cpp 2014-04-09 15:47:05 +0000
3+++ src/unity-mir/qmirserver.cpp 2014-05-06 12:35:11 +0000
4@@ -19,6 +19,7 @@
5 #include <mir/abnormal_exit.h>
6 #include <mir/default_server_configuration.h>
7 #include <mir/display_server.h>
8+#include <mir/main_loop.h>
9
10 // Platform API
11 #include <application/ubuntu_application_api_mirserver_priv.h>
12@@ -30,9 +31,11 @@
13
14 // Std
15 #include <chrono>
16+#include <csignal>
17 #include <thread>
18
19 // local
20+#include "logging.h"
21 #include "qmirserver.h"
22
23 QMirServer::QMirServer(int argc, const char* argv[], QObject *parent)
24@@ -53,19 +56,35 @@
25 auto argv = m_argv;
26 auto config = new ShellServerConfiguration(m_argc, m_argv);
27 std::thread *t;
28+ bool mirServerShutDown = false;
29
30- mir::run_mir(*config, [config, &client, &argc, &argv, &t](mir::DisplayServer& server) {
31+ mir::run_mir(*config, [&](mir::DisplayServer &server) {
32 ua_ui_mirserver_init(*config);
33
34+ // Mir initiates shutdown on SIGINT & SIGTERM, need to distinguish that shutdown from a
35+ // client-initiated shutdown. Do this by installing a custom signal handler that is run
36+ // after Mir's initiate-shutdown handler is called.
37+ config->the_main_loop()->register_signal_handler(
38+ {SIGINT, SIGTERM},
39+ [&](int)
40+ {
41+ DLOG("Mir-initiated shut down in progress");
42+ mirServerShutDown = true;
43+ });
44+
45 try {
46 t = new std::thread([&]() {
47 client (argc, argv, config);
48- server.stop();
49+ if (!mirServerShutDown) {
50+ DLOG("Qt-initiated shut down in progress");
51+ server.stop();
52+ }
53 });
54 } catch (...) {
55- qDebug() << "Exception caught, quitting";
56+ LOG("Exception caught, quitting");
57 }
58 });
59+
60 if (QCoreApplication::instance()) {
61 bool aboutToQuitSignaled = false;
62 QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, [&]() {

Subscribers

People subscribed via source and target branches