Merge lp:~thomas-voss/unity-mir/replace_get_env_with_thread_safe_variant into lp:unity-mir

Proposed by Thomas Voß
Status: Rejected
Rejected by: Michał Sawicz
Proposed branch: lp:~thomas-voss/unity-mir/replace_get_env_with_thread_safe_variant
Merge into: lp:unity-mir
Prerequisite: lp:~thomas-voss/unity-mir/refactor-oom-score-adj-to-rely-on-process-cpp
Diff against target: 230 lines (+83/-48)
3 files modified
src/modules/Unity/Application/applicationscreenshotprovider.cpp (+14/-12)
src/modules/Unity/Application/taskcontroller.cpp (+63/-29)
src/modules/Unity/Application/ubuntukeyboardinfo.cpp (+6/-7)
To merge this branch: bzr merge lp:~thomas-voss/unity-mir/replace_get_env_with_thread_safe_variant
Reviewer Review Type Date Requested Status
Michał Sawicz Disapprove
Gerry Boland (community) Needs Information
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+195037@code.launchpad.net

Commit message

Switch to process-cpp for querying the environment in a thread-safe manner.

Description of the change

Switch to process-cpp for querying the environment in a thread-safe manner.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
146. By Thomas Voß

Leverage default values for env::get().

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

As discussed on IRC, posix::this_process::env would give us false confidence that we're safe, when in fact any non-wrapped call to setenv in a library, for example, would result in a segfault just the same.

There's some other changes here that still make sense, please extract them or revert the env-related changes alone.

review: Needs Fixing
147. By Thomas Voß

Merged dependent branches.

148. By Thomas Voß

Reverted changes to getenv.

149. By Thomas Voß

Ensure that panel height is adjusted for grid unit pixel units.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
150. By Thomas Voß

[ Gerry Boland ]
* Unity.Application is not a shared library, but a plugin. (LP:
  #1256014)
* Implement preStart callback added to upstart-app-launch-2. (LP:
  #1243665)
[ Ubuntu daily release ]
* Automatic snapshot from revision 157
[ Gerry Boland ]
* Install ServerStatusListener to be notified of mir server start, pause
  and resume. Use start notification to send SIGSTOP signal to upstart,
  so it knows mir is ready for other clients.
* Bump version number
* InputArea: don't use lambda function as slot, can cause crash on
  shutdown Using lambda function as slot can introduce crash as the
  slot's object deletion is not registered unlike with traditional
  signal/slot connections. As a result, on signal emission, the lambda
  can be called on a deleted object. (LP: #1253685)
* Misc fixes for Mir 0.1.2 support. (LP: #1254986)
[ Alan Griffiths ]
* ApplicationSession is a Mir implementation class that shouldn't be
  used by unity-mir, use shell::session instead.
[ Kevin Gunn ]
* mir server abi and api broke, updating dependency to deb 0.1.1.
* update mir deb build dep to 0.1.2
[ Victor Thompson ]
* Fix mir to not suspend the music-app, or any other app granted a
  lifecycle exception, when switching between apps. (LP: #1241185,
  #1241045)
[ Daniel van Vugt ]
* Force the screen to redraw after turning the display back on (LP:
  #1255045). Also stop the compositor when the screen is off.
  Otherwise it will spin in the background, eating battery. (LP:
  #1255045)
[ Ubuntu daily release ]
* Automatic snapshot from revision 154
* Cherry-pick upstream patch to avoid Unity8 crashing on stop
  (LP: #1253685)
[ Gerry Boland ]
* On MirSurface destruction, any InputAreas on that surface will be
  notified and remove their links to that surface. Fixes crash
  bug:1243444. (LP: #1243444)
[ Alan Griffiths ]
* Remove dependency on mir::shell::SessionManager.
* Remove dependency on mir::surfaces::SurfaceController.
* Remove dependency on msh::OrganisingSurfaceFactory.
* Avoid relying on an explicit Mir typename that changes in a
  refactoring coming soon.
* Do all the hacky surface creation customization in
  SurfaceFactory::create_surface() - and don't mention SurfaceBuilder
  at all. (That will allow Mir to get rid of that interface.).
[ Albert Astals ]
* Don't include the QtQml megaheader Include the one we really need.
[ Ubuntu daily release ]
* Automatic snapshot from revision 144

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

Is this MR still relevant?

review: Needs Information
Revision history for this message
Michał Sawicz (saviq) wrote :

No, we've discussed and decided it's a trap.

review: Disapprove

Unmerged revisions

150. By Thomas Voß

[ Gerry Boland ]
* Unity.Application is not a shared library, but a plugin. (LP:
  #1256014)
* Implement preStart callback added to upstart-app-launch-2. (LP:
  #1243665)
[ Ubuntu daily release ]
* Automatic snapshot from revision 157
[ Gerry Boland ]
* Install ServerStatusListener to be notified of mir server start, pause
  and resume. Use start notification to send SIGSTOP signal to upstart,
  so it knows mir is ready for other clients.
* Bump version number
* InputArea: don't use lambda function as slot, can cause crash on
  shutdown Using lambda function as slot can introduce crash as the
  slot's object deletion is not registered unlike with traditional
  signal/slot connections. As a result, on signal emission, the lambda
  can be called on a deleted object. (LP: #1253685)
* Misc fixes for Mir 0.1.2 support. (LP: #1254986)
[ Alan Griffiths ]
* ApplicationSession is a Mir implementation class that shouldn't be
  used by unity-mir, use shell::session instead.
[ Kevin Gunn ]
* mir server abi and api broke, updating dependency to deb 0.1.1.
* update mir deb build dep to 0.1.2
[ Victor Thompson ]
* Fix mir to not suspend the music-app, or any other app granted a
  lifecycle exception, when switching between apps. (LP: #1241185,
  #1241045)
[ Daniel van Vugt ]
* Force the screen to redraw after turning the display back on (LP:
  #1255045). Also stop the compositor when the screen is off.
  Otherwise it will spin in the background, eating battery. (LP:
  #1255045)
[ Ubuntu daily release ]
* Automatic snapshot from revision 154
* Cherry-pick upstream patch to avoid Unity8 crashing on stop
  (LP: #1253685)
[ Gerry Boland ]
* On MirSurface destruction, any InputAreas on that surface will be
  notified and remove their links to that surface. Fixes crash
  bug:1243444. (LP: #1243444)
[ Alan Griffiths ]
* Remove dependency on mir::shell::SessionManager.
* Remove dependency on mir::surfaces::SurfaceController.
* Remove dependency on msh::OrganisingSurfaceFactory.
* Avoid relying on an explicit Mir typename that changes in a
  refactoring coming soon.
* Do all the hacky surface creation customization in
  SurfaceFactory::create_surface() - and don't mention SurfaceBuilder
  at all. (That will allow Mir to get rid of that interface.).
[ Albert Astals ]
* Don't include the QtQml megaheader Include the one we really need.
[ Ubuntu daily release ]
* Automatic snapshot from revision 144

149. By Thomas Voß

Ensure that panel height is adjusted for grid unit pixel units.

148. By Thomas Voß

Reverted changes to getenv.

147. By Thomas Voß

Merged dependent branches.

146. By Thomas Voß

Leverage default values for env::get().

145. By Thomas Voß

Switch to process-cpp for querying the environment in a thread-safe manner.

144. By Thomas Voß

Refactor sigstop'ing and sigcont'ing of application process groups to rely on process-cpp.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/Unity/Application/applicationscreenshotprovider.cpp'
2--- src/modules/Unity/Application/applicationscreenshotprovider.cpp 2013-11-26 10:32:56 +0000
3+++ src/modules/Unity/Application/applicationscreenshotprovider.cpp 2013-12-09 16:43:13 +0000
4@@ -25,6 +25,9 @@
5 // mir
6 #include "mirserver/mir/shell/session.h"
7
8+// STL
9+#include <sstream>
10+
11 // fallback grid unit used if GRID_UNIT_PX is not in the environment.
12 const int defaultGridUnitPx = 8;
13
14@@ -46,7 +49,6 @@
15 }
16
17 int densityPixelPx = qFloor( (float)gridUnitPx / defaultGridUnitPx );
18-
19 m_panelHeight = 3 * gridUnitPx + 2 * densityPixelPx;
20 }
21
22@@ -57,7 +59,7 @@
23 }
24
25 QImage ApplicationScreenshotProvider::requestImage(const QString &appId, QSize * size,
26- const QSize &requestedSize)
27+ const QSize &requestedSize)
28 {
29 DLOG("ApplicationScreenshotProvider::requestPixmap (this=%p, id=%s)", this, appId.toLatin1().constData());
30
31@@ -95,17 +97,17 @@
32 QImage image;
33
34 app->session()->take_snapshot(
35- [&](mir::shell::Snapshot const& snapshot)
36- {
37- DLOG("ApplicationScreenshotProvider - Mir snapshot ready with size %d x %d",
38- snapshot.size.height.as_int(), snapshot.size.width.as_int());
39+ [&](mir::shell::Snapshot const& snapshot)
40+ {
41+ DLOG("ApplicationScreenshotProvider - Mir snapshot ready with size %d x %d",
42+ snapshot.size.height.as_int(), snapshot.size.width.as_int());
43
44- image = QImage( (const uchar*)snapshot.pixels, // since we mirror, no need to offset starting position
45- snapshot.size.width.as_int(),
46- snapshot.size.height.as_int() - yOffset,
47- QImage::Format_ARGB32_Premultiplied).mirrored();
48- wait.wakeOne();
49- });
50+ image = QImage( (const uchar*)snapshot.pixels, // since we mirror, no need to offset starting position
51+ snapshot.size.width.as_int(),
52+ snapshot.size.height.as_int() - yOffset,
53+ QImage::Format_ARGB32_Premultiplied).mirrored();
54+ wait.wakeOne();
55+ });
56
57 wait.wait(&mutex, 5000);
58
59
60=== modified file 'src/modules/Unity/Application/taskcontroller.cpp'
61--- src/modules/Unity/Application/taskcontroller.cpp 2013-12-09 16:43:13 +0000
62+++ src/modules/Unity/Application/taskcontroller.cpp 2013-12-09 16:43:13 +0000
63@@ -45,14 +45,12 @@
64
65 namespace
66 {
67-void ensureProcessIsUnlikelyToBeKilled(pid_t pid)
68+void ensureProcessIsUnlikelyToBeKilled(core::posix::Process process)
69 {
70 // By system default, we set the oom_score_adj of Unity8 to -10 (via lightdm).
71 // As we want to avoid that any app's oom_score_adj is <= Unity8's oom_score_adj,
72 // we choose a default increase of +1.
73 static const int default_increase = 1;
74-
75- core::posix::Process process(pid);
76
77 try
78 {
79@@ -84,14 +82,12 @@
80 }
81 }
82
83-void ensureProcessIsLikelyToBeKilled(pid_t pid)
84+void ensureProcessIsLikelyToBeKilled(core::posix::Process process)
85 {
86 // We avoid extremal values for oom_score_adj. For that, we
87 // set it to 80% of the total available range.
88 static const float defaultPercentage = 0.8;
89
90- core::posix::Process process(pid);
91-
92 try
93 {
94 plpp::OomScoreAdj shellScore;
95@@ -150,7 +146,15 @@
96 focusCallback = [](const gchar * appId, gpointer userData) {
97 Q_UNUSED(userData)
98 pid_t pid = upstart_app_launch_get_primary_pid(appId);
99- ensureProcessIsUnlikelyToBeKilled(pid);
100+
101+ try
102+ {
103+ ensureProcessIsUnlikelyToBeKilled(core::posix::Process{pid});
104+ } catch(const std::runtime_error&)
105+ {
106+ LOG("TaskController::startCallback: pid queried from upstart app launch is invalid.");
107+ }
108+
109 Q_EMIT TaskController::singleton()->requestFocus(QString(appId));
110 };
111
112@@ -232,17 +236,32 @@
113 DLOG("TaskController::suspend (this=%p, application=%p)", this, qPrintable(appId));
114 pid_t pid = upstart_app_launch_get_primary_pid(appId.toLatin1().constData());
115
116- ensureProcessIsLikelyToBeKilled(pid);
117-
118- if (pid) {
119- // We do assume that the app was launched by upstart and with that,
120- // in its own process group. For that, we interpret the pid as pgid and
121- // sigstop the complete process group on suspend.
122- kill(-pid, SIGSTOP);
123- return true;
124- } else {
125- return false;
126- }
127+ core::posix::Process process = core::posix::Process::invalid();
128+ try
129+ {
130+ process = core::posix::Process{pid};
131+ } catch(const std::runtime_error&)
132+ {
133+ // If the pid reported by upstart app launch is invalid, we error out here.
134+ LOG("TaskController::suspend: pid queried from upstart app launch is invalid.");
135+ return false;
136+ }
137+
138+ ensureProcessIsLikelyToBeKilled(process);
139+
140+ // We do assume that the app was launched by upstart and with that,
141+ // in its own process group.
142+ try
143+ {
144+ auto pg = process.process_group_or_throw();
145+ pg.send_signal_or_throw(core::posix::Signal::sig_stop);
146+ } catch(const std::system_error& e)
147+ {
148+ LOG("TaskController::suspend: Exception sig-stop'ing process group (%s)", e.what());
149+ return false;
150+ }
151+
152+ return true;
153 }
154
155 bool TaskController::resume(const QString& appId)
156@@ -250,15 +269,30 @@
157 DLOG("TaskController::resume (this=%p, application=%p)", this, qPrintable(appId));
158 pid_t pid = upstart_app_launch_get_primary_pid(appId.toLatin1().constData());
159
160- ensureProcessIsUnlikelyToBeKilled(pid);
161-
162- if (pid) {
163- // We do assume that the app was launched by upstart and with that,
164- // in its own process group. For that, we interpret the pid as pgid and
165- // sigcont the complete process group on resume.
166- kill(-pid, SIGCONT);
167- return true;
168- } else {
169- return false;
170- }
171+ core::posix::Process process = core::posix::Process::invalid();
172+ try
173+ {
174+ process = core::posix::Process{pid};
175+ } catch(const std::runtime_error&)
176+ {
177+ // If the pid reported by upstart app launch is invalid, we error out here.
178+ LOG("TaskController::resume: pid queried from upstart app launch is invalid.");
179+ return false;
180+ }
181+
182+ ensureProcessIsUnlikelyToBeKilled(process);
183+
184+ // We do assume that the app was launched by upstart and with that,
185+ // in its own process group.
186+ try
187+ {
188+ auto pg = process.process_group_or_throw();
189+ pg.send_signal_or_throw(core::posix::Signal::sig_cont);
190+ } catch(const std::system_error& e)
191+ {
192+ LOG("TaskController::resume: Exception sig-continue'ing process group (%s)", e.what());
193+ return false;
194+ }
195+
196+ return true;
197 }
198
199=== modified file 'src/modules/Unity/Application/ubuntukeyboardinfo.cpp'
200--- src/modules/Unity/Application/ubuntukeyboardinfo.cpp 2013-10-14 18:39:55 +0000
201+++ src/modules/Unity/Application/ubuntukeyboardinfo.cpp 2013-12-09 16:43:13 +0000
202@@ -19,16 +19,16 @@
203 #include <QDir>
204
205 namespace {
206- const int gConnectionAttemptIntervalMs = 5000;
207- const int gMaxConsecutiveAttempts = 10;
208- const char gServerName[] = "ubuntu-keyboard-info";
209+const int gConnectionAttemptIntervalMs = 5000;
210+const int gMaxConsecutiveAttempts = 10;
211+const char gServerName[] = "ubuntu-keyboard-info";
212 }
213
214 UbuntuKeyboardInfo::UbuntuKeyboardInfo(QObject *parent)
215 : QObject(parent),
216- m_consecutiveAttempts(0),
217- m_lastWidth(0),
218- m_lastHeight(0)
219+ m_consecutiveAttempts(0),
220+ m_lastWidth(0),
221+ m_lastHeight(0)
222 {
223 connect(&m_socket, &QLocalSocket::stateChanged, this, &UbuntuKeyboardInfo::onSocketStateChanged);
224 connect(&m_socket, &QIODevice::readyRead,
225@@ -149,5 +149,4 @@
226 } else {
227 m_socketFilePath = QDir("/tmp").filePath(gServerName);
228 }
229-
230 }

Subscribers

People subscribed via source and target branches