Merge lp:~thomas-voss/trust-store/watch-service-name-owner-changes into lp:trust-store
- watch-service-name-owner-changes
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~thomas-voss/trust-store/watch-service-name-owner-changes |
Merge into: | lp:trust-store |
Diff against target: |
800 lines (+318/-186) 12 files modified
CMakeLists.txt (+2/-2) debian/changelog (+8/-12) debian/control (+4/-4) src/CMakeLists.txt (+3/-0) src/core/trust/daemon.cpp (+16/-90) src/core/trust/dbus/agent_registry.h (+38/-0) src/core/trust/remote/dbus.cpp (+20/-5) src/core/trust/remote/dbus.h (+7/-1) src/core/trust/runtime.cpp (+80/-0) src/core/trust/runtime.h (+73/-0) tests/CMakeLists.txt (+3/-0) tests/remote_agent_test.cpp (+64/-72) |
To merge this branch: | bzr merge lp:~thomas-voss/trust-store/watch-service-name-owner-changes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phablet Team | Pending | ||
Review via email: mp+281482@code.launchpad.net |
This proposal has been superseded by a proposal from 2016-01-03.
Commit message
core::trust:
asynchronously if a new name owner is detected.
Description of the change
core::trust:
asynchronously if a new name owner is detected.
- 138. By Thomas Voß
-
Make core::trust:
:Runtime a proper class and do not expose its internals anymore. - 139. By Thomas Voß
-
Address a few minor niggles regarding object lifetimes and noexcept(true) guarantees.
- 140. By Thomas Voß
-
Wait a little longer to account for slow builders.
- 141. By Thomas Voß
-
Link correct bug report.
Unmerged revisions
- 141. By Thomas Voß
-
Link correct bug report.
- 140. By Thomas Voß
-
Wait a little longer to account for slow builders.
- 139. By Thomas Voß
-
Address a few minor niggles regarding object lifetimes and noexcept(true) guarantees.
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2015-08-31 13:16:20 +0000 | |||
3 | +++ CMakeLists.txt 2016-01-03 20:28:56 +0000 | |||
4 | @@ -46,8 +46,8 @@ | |||
5 | 46 | pkg_check_modules(GLOG libglog REQUIRED) | 46 | pkg_check_modules(GLOG libglog REQUIRED) |
6 | 47 | pkg_check_modules(PROCESS_CPP process-cpp REQUIRED) | 47 | pkg_check_modules(PROCESS_CPP process-cpp REQUIRED) |
7 | 48 | 48 | ||
10 | 49 | set(TRUST_STORE_VERSION_MAJOR 2) | 49 | set(TRUST_STORE_VERSION_MAJOR 1) |
11 | 50 | set(TRUST_STORE_VERSION_MINOR 0) | 50 | set(TRUST_STORE_VERSION_MINOR 1) |
12 | 51 | set(TRUST_STORE_VERSION_PATCH 0) | 51 | set(TRUST_STORE_VERSION_PATCH 0) |
13 | 52 | 52 | ||
14 | 53 | include(CTest) | 53 | include(CTest) |
15 | 54 | 54 | ||
16 | === modified file 'debian/changelog' | |||
17 | --- debian/changelog 2015-08-31 15:11:26 +0000 | |||
18 | +++ debian/changelog 2016-01-03 20:28:56 +0000 | |||
19 | @@ -1,18 +1,14 @@ | |||
21 | 1 | trust-store (2.0.0+15.10.20150831.3-0ubuntu1) wily; urgency=medium | 1 | trust-store (1.1.0+15.04.20151126-0ubuntu1) vivid; urgency=medium |
22 | 2 | 2 | ||
25 | 3 | [ Alfonso Sanchez-Beato (email Canonical) ] | 3 | [ Thomas Voß ] |
26 | 4 | * Merge wily changes upstream | 4 | * Revert bump to major revision 2, vivid (+overlay) still has |
27 | 5 | 1.1.0 and gcc 4.9. | ||
28 | 5 | 6 | ||
29 | 6 | [ CI Train Bot ] | 7 | [ CI Train Bot ] |
39 | 7 | * No-change rebuild. | 8 | * New rebuild forced. |
40 | 8 | 9 | * Resync trunk. | |
41 | 9 | -- CI Train Bot <ci-train-bot@canonical.com> Mon, 31 Aug 2015 15:11:25 +0000 | 10 | |
42 | 10 | 11 | -- Thomas Voß <ci-train-bot@canonical.com> Thu, 26 Nov 2015 07:32:48 +0000 | |
34 | 11 | trust-store (2.0.0-0ubuntu1) wily; urgency=medium | ||
35 | 12 | |||
36 | 13 | * Bump major revision to account for toolchain update. Fixes LP:#1452341 | ||
37 | 14 | |||
38 | 15 | -- Thomas Voß <thomas.voss@canonical.com> Thu, 23 Jul 2015 09:22:15 +0200 | ||
43 | 16 | 12 | ||
44 | 17 | trust-store (1.1.0+15.04.20150820-0ubuntu1) vivid; urgency=medium | 13 | trust-store (1.1.0+15.04.20150820-0ubuntu1) vivid; urgency=medium |
45 | 18 | 14 | ||
46 | 19 | 15 | ||
47 | === modified file 'debian/control' | |||
48 | --- debian/control 2015-08-31 13:16:20 +0000 | |||
49 | +++ debian/control 2016-01-03 20:28:56 +0000 | |||
50 | @@ -30,7 +30,7 @@ | |||
51 | 30 | # upstream branch | 30 | # upstream branch |
52 | 31 | Vcs-Bzr: lp:trust-store | 31 | Vcs-Bzr: lp:trust-store |
53 | 32 | 32 | ||
55 | 33 | Package: libtrust-store2 | 33 | Package: libtrust-store1 |
56 | 34 | Architecture: any | 34 | Architecture: any |
57 | 35 | Multi-Arch: same | 35 | Multi-Arch: same |
58 | 36 | Pre-Depends: ${misc:Pre-Depends}, | 36 | Pre-Depends: ${misc:Pre-Depends}, |
59 | @@ -48,7 +48,7 @@ | |||
60 | 48 | Multi-Arch: same | 48 | Multi-Arch: same |
61 | 49 | Pre-Depends: ${misc:Pre-Depends}, | 49 | Pre-Depends: ${misc:Pre-Depends}, |
62 | 50 | Recommends: libtrust-store-doc, | 50 | Recommends: libtrust-store-doc, |
64 | 51 | Depends: libtrust-store2 (= ${binary:Version}), | 51 | Depends: libtrust-store1 (= ${binary:Version}), |
65 | 52 | ${misc:Depends}, | 52 | ${misc:Depends}, |
66 | 53 | Description: C++11 library for persisting trust requests - dev files | 53 | Description: C++11 library for persisting trust requests - dev files |
67 | 54 | Provides a common implementation of a trust store to be used by trusted | 54 | Provides a common implementation of a trust store to be used by trusted |
68 | @@ -60,7 +60,7 @@ | |||
69 | 60 | Package: trust-store-bin | 60 | Package: trust-store-bin |
70 | 61 | Section: devel | 61 | Section: devel |
71 | 62 | Architecture: any | 62 | Architecture: any |
73 | 63 | Depends: libtrust-store2 (= ${binary:Version}), | 63 | Depends: libtrust-store1 (= ${binary:Version}), |
74 | 64 | ${misc:Depends}, | 64 | ${misc:Depends}, |
75 | 65 | Description: Daemon binaries to be used by services. | 65 | Description: Daemon binaries to be used by services. |
76 | 66 | Provides a common implementation of a trust store to be used by trusted | 66 | Provides a common implementation of a trust store to be used by trusted |
77 | @@ -71,7 +71,7 @@ | |||
78 | 71 | Package: trust-store-tests | 71 | Package: trust-store-tests |
79 | 72 | Section: libdevel | 72 | Section: libdevel |
80 | 73 | Architecture: any | 73 | Architecture: any |
82 | 74 | Depends: libtrust-store2 (= ${binary:Version}), | 74 | Depends: libtrust-store1 (= ${binary:Version}), |
83 | 75 | ${misc:Depends}, | 75 | ${misc:Depends}, |
84 | 76 | Suggests: libtrust-store-dev, | 76 | Suggests: libtrust-store-dev, |
85 | 77 | Description: Test files for libtrust-store1 | 77 | Description: Test files for libtrust-store1 |
86 | 78 | 78 | ||
87 | === renamed file 'debian/libtrust-store2.install' => 'debian/libtrust-store1.install' | |||
88 | === modified file 'src/CMakeLists.txt' | |||
89 | --- src/CMakeLists.txt 2015-08-31 13:16:20 +0000 | |||
90 | +++ src/CMakeLists.txt 2016-01-03 20:28:56 +0000 | |||
91 | @@ -149,6 +149,9 @@ | |||
92 | 149 | trust-stored | 149 | trust-stored |
93 | 150 | 150 | ||
94 | 151 | core/trust/daemon.cpp | 151 | core/trust/daemon.cpp |
95 | 152 | |||
96 | 153 | core/trust/runtime.h | ||
97 | 154 | core/trust/runtime.cpp | ||
98 | 152 | ) | 155 | ) |
99 | 153 | 156 | ||
100 | 154 | add_executable( | 157 | add_executable( |
101 | 155 | 158 | ||
102 | === modified file 'src/core/trust/daemon.cpp' | |||
103 | --- src/core/trust/daemon.cpp 2015-08-31 14:00:41 +0000 | |||
104 | +++ src/core/trust/daemon.cpp 2016-01-03 20:28:56 +0000 | |||
105 | @@ -22,6 +22,7 @@ | |||
106 | 22 | #include <core/trust/cached_agent.h> | 22 | #include <core/trust/cached_agent.h> |
107 | 23 | #include <core/trust/expose.h> | 23 | #include <core/trust/expose.h> |
108 | 24 | #include <core/trust/i18n.h> | 24 | #include <core/trust/i18n.h> |
109 | 25 | #include <core/trust/runtime.h> | ||
110 | 25 | #include <core/trust/store.h> | 26 | #include <core/trust/store.h> |
111 | 26 | #include <core/trust/white_listing_agent.h> | 27 | #include <core/trust/white_listing_agent.h> |
112 | 27 | 28 | ||
113 | @@ -49,67 +50,6 @@ | |||
114 | 49 | 50 | ||
115 | 50 | namespace | 51 | namespace |
116 | 51 | { | 52 | { |
117 | 52 | struct Runtime | ||
118 | 53 | { | ||
119 | 54 | // Do not execute in parallel, serialize | ||
120 | 55 | // accesses. | ||
121 | 56 | static constexpr std::size_t concurrency_hint{2}; | ||
122 | 57 | |||
123 | 58 | // Our evil singleton pattern. Not bad though, we control the | ||
124 | 59 | // entire executable and rely on automatic cleanup of static | ||
125 | 60 | // instances. | ||
126 | 61 | static Runtime& instance() | ||
127 | 62 | { | ||
128 | 63 | static Runtime runtime; | ||
129 | 64 | return runtime; | ||
130 | 65 | } | ||
131 | 66 | |||
132 | 67 | ~Runtime() | ||
133 | 68 | { | ||
134 | 69 | io_service.stop(); | ||
135 | 70 | |||
136 | 71 | if (worker1.joinable()) | ||
137 | 72 | worker1.join(); | ||
138 | 73 | |||
139 | 74 | if (worker2.joinable()) | ||
140 | 75 | worker2.join(); | ||
141 | 76 | } | ||
142 | 77 | |||
143 | 78 | // We trap sig term to ensure a clean shutdown. | ||
144 | 79 | std::shared_ptr<core::posix::SignalTrap> signal_trap | ||
145 | 80 | { | ||
146 | 81 | core::posix::trap_signals_for_all_subsequent_threads( | ||
147 | 82 | { | ||
148 | 83 | core::posix::Signal::sig_term, | ||
149 | 84 | core::posix::Signal::sig_int | ||
150 | 85 | }) | ||
151 | 86 | }; | ||
152 | 87 | |||
153 | 88 | // Our io_service instance exposed to remote agents. | ||
154 | 89 | boost::asio::io_service io_service | ||
155 | 90 | { | ||
156 | 91 | concurrency_hint | ||
157 | 92 | }; | ||
158 | 93 | |||
159 | 94 | // We keep the io_service alive and introduce some artificial | ||
160 | 95 | // work. | ||
161 | 96 | boost::asio::io_service::work keep_alive | ||
162 | 97 | { | ||
163 | 98 | io_service | ||
164 | 99 | }; | ||
165 | 100 | |||
166 | 101 | // We immediate execute the io_service instance | ||
167 | 102 | std::thread worker1 | ||
168 | 103 | { | ||
169 | 104 | std::thread{[this]() { io_service.run(); }} | ||
170 | 105 | }; | ||
171 | 106 | |||
172 | 107 | std::thread worker2 | ||
173 | 108 | { | ||
174 | 109 | std::thread{[this]() { io_service.run(); }} | ||
175 | 110 | }; | ||
176 | 111 | }; | ||
177 | 112 | |||
178 | 113 | core::trust::Daemon::Dictionary fill_dictionary_from_unrecognized_options(const Options::parsed_options& parsed_options) | 53 | core::trust::Daemon::Dictionary fill_dictionary_from_unrecognized_options(const Options::parsed_options& parsed_options) |
179 | 114 | { | 54 | { |
180 | 115 | auto unrecognized = Options::collect_unrecognized( | 55 | auto unrecognized = Options::collect_unrecognized( |
181 | @@ -170,7 +110,7 @@ | |||
182 | 170 | "Could not create bus for name: " + bus_name | 110 | "Could not create bus for name: " + bus_name |
183 | 171 | }; | 111 | }; |
184 | 172 | 112 | ||
186 | 173 | bus->install_executor(core::dbus::asio::make_executor(bus, Runtime::instance().io_service)); | 113 | bus->install_executor(core::dbus::asio::make_executor(bus, core::trust::Runtime::instance().io_service)); |
187 | 174 | 114 | ||
188 | 175 | return bus; | 115 | return bus; |
189 | 176 | } | 116 | } |
190 | @@ -256,7 +196,7 @@ | |||
191 | 256 | core::trust::remote::posix::Skeleton::Configuration config | 196 | core::trust::remote::posix::Skeleton::Configuration config |
192 | 257 | { | 197 | { |
193 | 258 | agent, | 198 | agent, |
195 | 259 | Runtime::instance().io_service, | 199 | core::trust::Runtime::instance().io_service, |
196 | 260 | boost::asio::local::stream_protocol::endpoint{dict.at("endpoint")}, | 200 | boost::asio::local::stream_protocol::endpoint{dict.at("endpoint")}, |
197 | 261 | core::trust::remote::helpers::proc_stat_start_time_resolver(), | 201 | core::trust::remote::helpers::proc_stat_start_time_resolver(), |
198 | 262 | core::trust::remote::helpers::aa_get_task_con_app_id_resolver(), | 202 | core::trust::remote::helpers::aa_get_task_con_app_id_resolver(), |
199 | @@ -289,16 +229,19 @@ | |||
200 | 289 | core::trust::remote::dbus::default_agent_registry_path | 229 | core::trust::remote::dbus::default_agent_registry_path |
201 | 290 | }); | 230 | }); |
202 | 291 | 231 | ||
203 | 232 | core::dbus::DBus daemon{bus}; | ||
204 | 233 | |||
205 | 292 | core::trust::remote::dbus::Agent::Skeleton::Configuration config | 234 | core::trust::remote::dbus::Agent::Skeleton::Configuration config |
206 | 293 | { | 235 | { |
207 | 294 | agent, | 236 | agent, |
208 | 295 | object, | 237 | object, |
209 | 238 | daemon.make_service_watcher(dbus_service_name), | ||
210 | 296 | service, | 239 | service, |
211 | 297 | bus, | 240 | bus, |
212 | 298 | core::trust::remote::helpers::aa_get_task_con_app_id_resolver() | 241 | core::trust::remote::helpers::aa_get_task_con_app_id_resolver() |
213 | 299 | }; | 242 | }; |
214 | 300 | 243 | ||
216 | 301 | return std::make_shared<core::trust::remote::dbus::Agent::Skeleton>(config); | 244 | return std::make_shared<core::trust::remote::dbus::Agent::Skeleton>(std::move(config)); |
217 | 302 | } | 245 | } |
218 | 303 | } | 246 | } |
219 | 304 | }; | 247 | }; |
220 | @@ -390,16 +333,6 @@ | |||
221 | 390 | // Executes the daemon with the given configuration. | 333 | // Executes the daemon with the given configuration. |
222 | 391 | core::posix::exit::Status core::trust::Daemon::Skeleton::main(const core::trust::Daemon::Skeleton::Configuration& configuration) | 334 | core::posix::exit::Status core::trust::Daemon::Skeleton::main(const core::trust::Daemon::Skeleton::Configuration& configuration) |
223 | 392 | { | 335 | { |
224 | 393 | Runtime::instance().signal_trap->signal_raised().connect([](core::posix::Signal) | ||
225 | 394 | { | ||
226 | 395 | Runtime::instance().signal_trap->stop(); | ||
227 | 396 | }); | ||
228 | 397 | |||
229 | 398 | std::thread worker | ||
230 | 399 | { | ||
231 | 400 | [configuration]() { configuration.bus->run(); } | ||
232 | 401 | }; | ||
233 | 402 | |||
234 | 403 | // Expose the local store to the bus, keeping it exposed for the | 336 | // Expose the local store to the bus, keeping it exposed for the |
235 | 404 | // lifetime of the returned token. | 337 | // lifetime of the returned token. |
236 | 405 | auto token = core::trust::expose_store_to_bus_with_name( | 338 | auto token = core::trust::expose_store_to_bus_with_name( |
237 | @@ -407,12 +340,7 @@ | |||
238 | 407 | configuration.bus, | 340 | configuration.bus, |
239 | 408 | configuration.service_name); | 341 | configuration.service_name); |
240 | 409 | 342 | ||
247 | 410 | Runtime::instance().signal_trap->run(); | 343 | core::trust::Runtime::instance().run(); |
242 | 411 | |||
243 | 412 | configuration.bus->stop(); | ||
244 | 413 | |||
245 | 414 | if (worker.joinable()) | ||
246 | 415 | worker.join(); | ||
248 | 416 | 344 | ||
249 | 417 | return core::posix::exit::Status::success; | 345 | return core::posix::exit::Status::success; |
250 | 418 | } | 346 | } |
251 | @@ -432,7 +360,7 @@ | |||
252 | 432 | 360 | ||
253 | 433 | core::trust::remote::posix::Stub::Configuration config | 361 | core::trust::remote::posix::Stub::Configuration config |
254 | 434 | { | 362 | { |
256 | 435 | Runtime::instance().io_service, | 363 | core::trust::Runtime::instance().io_service, |
257 | 436 | boost::asio::local::stream_protocol::endpoint{dict.at("endpoint")}, | 364 | boost::asio::local::stream_protocol::endpoint{dict.at("endpoint")}, |
258 | 437 | core::trust::remote::helpers::proc_stat_start_time_resolver(), | 365 | core::trust::remote::helpers::proc_stat_start_time_resolver(), |
259 | 438 | core::trust::remote::posix::Stub::get_sock_opt_credentials_resolver(), | 366 | core::trust::remote::posix::Stub::get_sock_opt_credentials_resolver(), |
260 | @@ -524,11 +452,16 @@ | |||
261 | 524 | { | 452 | { |
262 | 525 | Shell(const std::shared_ptr<core::trust::Agent>& agent) | 453 | Shell(const std::shared_ptr<core::trust::Agent>& agent) |
263 | 526 | : agent{agent}, | 454 | : agent{agent}, |
265 | 527 | stdin{Runtime::instance().io_service, STDIN_FILENO}, | 455 | stdin{core::trust::Runtime::instance().io_service, STDIN_FILENO}, |
266 | 528 | app_id_resolver{core::trust::remote::helpers::aa_get_task_con_app_id_resolver()} | 456 | app_id_resolver{core::trust::remote::helpers::aa_get_task_con_app_id_resolver()} |
267 | 529 | { | 457 | { |
268 | 530 | } | 458 | } |
269 | 531 | 459 | ||
270 | 460 | ~Shell() | ||
271 | 461 | { | ||
272 | 462 | stop(); | ||
273 | 463 | } | ||
274 | 464 | |||
275 | 532 | // Prints out the initial prompt and initiates a read operation on stdin. | 465 | // Prints out the initial prompt and initiates a read operation on stdin. |
276 | 533 | void start() | 466 | void start() |
277 | 534 | { | 467 | { |
278 | @@ -607,18 +540,11 @@ | |||
279 | 607 | // We setup our minimal shell here. | 540 | // We setup our minimal shell here. |
280 | 608 | auto shell = std::make_shared<Shell>(configuration.remote.agent); | 541 | auto shell = std::make_shared<Shell>(configuration.remote.agent); |
281 | 609 | 542 | ||
282 | 610 | Runtime::instance().signal_trap->signal_raised().connect([](core::posix::Signal) | ||
283 | 611 | { | ||
284 | 612 | Runtime::instance().signal_trap->stop(); | ||
285 | 613 | }); | ||
286 | 614 | |||
287 | 615 | // We start up our shell | 543 | // We start up our shell |
288 | 616 | shell->start(); | 544 | shell->start(); |
289 | 617 | 545 | ||
290 | 618 | // Wait until signal arrives. | 546 | // Wait until signal arrives. |
294 | 619 | Runtime::instance().signal_trap->run(); | 547 | core::trust::Runtime::instance().run(); |
292 | 620 | |||
293 | 621 | shell->stop(); | ||
295 | 622 | 548 | ||
296 | 623 | return core::posix::exit::Status::success; | 549 | return core::posix::exit::Status::success; |
297 | 624 | } | 550 | } |
298 | 625 | 551 | ||
299 | === modified file 'src/core/trust/dbus/agent_registry.h' | |||
300 | --- src/core/trust/dbus/agent_registry.h 2014-08-04 07:10:52 +0000 | |||
301 | +++ src/core/trust/dbus/agent_registry.h 2016-01-03 20:28:56 +0000 | |||
302 | @@ -179,6 +179,44 @@ | |||
303 | 179 | locking_agent_registry.register_agent_for_user(uid, skeleton); | 179 | locking_agent_registry.register_agent_for_user(uid, skeleton); |
304 | 180 | } | 180 | } |
305 | 181 | 181 | ||
306 | 182 | // Calls into the remote implementation to register the given agent implementation. | ||
307 | 183 | // Throws std::runtime_error and std::logic_error in case of issues. | ||
308 | 184 | void register_agent_for_user_async(const core::trust::Uid& uid, const std::shared_ptr<core::trust::Agent>& impl, const std::function<void()>& then) | ||
309 | 185 | { | ||
310 | 186 | // We sample a path for the given uid | ||
311 | 187 | auto path = configuration.object_path_generator(uid); | ||
312 | 188 | // And construct the skeleton instance. | ||
313 | 189 | auto skeleton = std::shared_ptr<core::trust::dbus::Agent::Skeleton> | ||
314 | 190 | { | ||
315 | 191 | new core::trust::dbus::Agent::Skeleton | ||
316 | 192 | { | ||
317 | 193 | core::trust::dbus::Agent::Skeleton::Configuration | ||
318 | 194 | { | ||
319 | 195 | configuration.service->add_object_for_path(path), | ||
320 | 196 | configuration.bus, | ||
321 | 197 | std::bind(&core::trust::Agent::authenticate_request_with_parameters, impl, std::placeholders::_1) | ||
322 | 198 | } | ||
323 | 199 | } | ||
324 | 200 | }; | ||
325 | 201 | |||
326 | 202 | // And announce the agent. | ||
327 | 203 | configuration.object->invoke_method_asynchronously_with_callback< | ||
328 | 204 | Methods::RegisterAgentForUser, void | ||
329 | 205 | >([this, then, uid, skeleton](const core::dbus::Result<void>& result) | ||
330 | 206 | { | ||
331 | 207 | if (result.is_error()) | ||
332 | 208 | { | ||
333 | 209 | std::cerr << "Failed to register agent for user: " << result.error().print() << std::endl; | ||
334 | 210 | } | ||
335 | 211 | else | ||
336 | 212 | { | ||
337 | 213 | // All good, update our own state prior to invoking the supplied callback. | ||
338 | 214 | locking_agent_registry.register_agent_for_user(uid, skeleton); | ||
339 | 215 | then(); | ||
340 | 216 | } | ||
341 | 217 | }, uid, path); | ||
342 | 218 | } | ||
343 | 219 | |||
344 | 182 | // Calls into the remote implementation to unregister any agent registered for the given uid. | 220 | // Calls into the remote implementation to unregister any agent registered for the given uid. |
345 | 183 | // Throws std::runtime_error and std::logic_error in case of issues. | 221 | // Throws std::runtime_error and std::logic_error in case of issues. |
346 | 184 | void unregister_agent_for_user(const core::trust::Uid& uid) override | 222 | void unregister_agent_for_user(const core::trust::Uid& uid) override |
347 | 185 | 223 | ||
348 | === modified file 'src/core/trust/remote/dbus.cpp' | |||
349 | --- src/core/trust/remote/dbus.cpp 2014-07-29 17:00:35 +0000 | |||
350 | +++ src/core/trust/remote/dbus.cpp 2016-01-03 20:28:56 +0000 | |||
351 | @@ -19,6 +19,7 @@ | |||
352 | 19 | #include <core/trust/remote/dbus.h> | 19 | #include <core/trust/remote/dbus.h> |
353 | 20 | 20 | ||
354 | 21 | #include <core/trust/dbus_agent.h> | 21 | #include <core/trust/dbus_agent.h> |
355 | 22 | #include <core/trust/runtime.h> | ||
356 | 22 | 23 | ||
357 | 23 | core::trust::remote::dbus::Agent::Stub::Stub(const core::trust::remote::dbus::Agent::Stub::Configuration& configuration) | 24 | core::trust::remote::dbus::Agent::Stub::Stub(const core::trust::remote::dbus::Agent::Stub::Configuration& configuration) |
358 | 24 | : agent_registry_skeleton | 25 | : agent_registry_skeleton |
359 | @@ -43,20 +44,34 @@ | |||
360 | 43 | return agent->authenticate_request_with_parameters(parameters); | 44 | return agent->authenticate_request_with_parameters(parameters); |
361 | 44 | } | 45 | } |
362 | 45 | 46 | ||
364 | 46 | core::trust::remote::dbus::Agent::Skeleton::Skeleton(const core::trust::remote::dbus::Agent::Skeleton::Configuration& configuration) | 47 | core::trust::remote::dbus::Agent::Skeleton::Skeleton(core::trust::remote::dbus::Agent::Skeleton::Configuration configuration) |
365 | 47 | : core::trust::remote::Agent::Skeleton{configuration.impl}, | 48 | : core::trust::remote::Agent::Skeleton{configuration.impl}, |
366 | 49 | config(std::move(configuration)), | ||
367 | 48 | agent_registry_stub | 50 | agent_registry_stub |
368 | 49 | { | 51 | { |
369 | 50 | core::trust::dbus::AgentRegistry::Stub::Configuration | 52 | core::trust::dbus::AgentRegistry::Stub::Configuration |
370 | 51 | { | 53 | { |
372 | 52 | configuration.agent_registry_object, | 54 | config.agent_registry_object, |
373 | 53 | core::trust::dbus::AgentRegistry::Stub::counting_object_path_generator(), | 55 | core::trust::dbus::AgentRegistry::Stub::counting_object_path_generator(), |
376 | 54 | configuration.service, | 56 | config.service, |
377 | 55 | configuration.bus | 57 | config.bus |
378 | 56 | } | 58 | } |
379 | 57 | } | 59 | } |
380 | 58 | { | 60 | { |
382 | 59 | agent_registry_stub.register_agent_for_user(core::trust::Uid{::getuid()}, configuration.impl); | 61 | agent_registry_stub.register_agent_for_user_async(core::trust::Uid{::getuid()}, config.impl, []() |
383 | 62 | { | ||
384 | 63 | std::cout << "Error registering agent for user." << std::endl; | ||
385 | 64 | }); | ||
386 | 65 | |||
387 | 66 | // We don't have to track the lifetime of "this" as config.agent_registry_watcher is owned | ||
388 | 67 | // by "this". | ||
389 | 68 | config.agent_registry_watcher->service_registered().connect([this]() | ||
390 | 69 | { | ||
391 | 70 | agent_registry_stub.register_agent_for_user_async(core::trust::Uid{::getuid()}, config.impl, []() | ||
392 | 71 | { | ||
393 | 72 | std::cout << "Error registering agent for user." << std::endl; | ||
394 | 73 | }); | ||
395 | 74 | }); | ||
396 | 60 | } | 75 | } |
397 | 61 | 76 | ||
398 | 62 | core::trust::Request::Answer core::trust::remote::dbus::Agent::Skeleton::authenticate_request_with_parameters(const core::trust::Agent::RequestParameters& parameters) | 77 | core::trust::Request::Answer core::trust::remote::dbus::Agent::Skeleton::authenticate_request_with_parameters(const core::trust::Agent::RequestParameters& parameters) |
399 | 63 | 78 | ||
400 | === modified file 'src/core/trust/remote/dbus.h' | |||
401 | --- src/core/trust/remote/dbus.h 2014-08-04 07:57:05 +0000 | |||
402 | +++ src/core/trust/remote/dbus.h 2016-01-03 20:28:56 +0000 | |||
403 | @@ -25,6 +25,8 @@ | |||
404 | 25 | #include <core/trust/dbus/agent.h> | 25 | #include <core/trust/dbus/agent.h> |
405 | 26 | #include <core/trust/dbus/agent_registry.h> | 26 | #include <core/trust/dbus/agent_registry.h> |
406 | 27 | 27 | ||
407 | 28 | #include <core/dbus/service_watcher.h> | ||
408 | 29 | |||
409 | 28 | #include <unistd.h> | 30 | #include <unistd.h> |
410 | 29 | #include <sys/types.h> | 31 | #include <sys/types.h> |
411 | 30 | 32 | ||
412 | @@ -86,6 +88,8 @@ | |||
413 | 86 | std::shared_ptr<Agent> impl; | 88 | std::shared_ptr<Agent> impl; |
414 | 87 | // The remote object implementing core.trust.dbus.AgentRegistry. | 89 | // The remote object implementing core.trust.dbus.AgentRegistry. |
415 | 88 | core::dbus::Object::Ptr agent_registry_object; | 90 | core::dbus::Object::Ptr agent_registry_object; |
416 | 91 | // The watcher monitoring the remote object implementing core.trust.dbus.AgentRegistry. | ||
417 | 92 | std::unique_ptr<core::dbus::ServiceWatcher> agent_registry_watcher; | ||
418 | 89 | // The service that objects implementing core.trust.dbus.Agent should be added to. | 93 | // The service that objects implementing core.trust.dbus.Agent should be added to. |
419 | 90 | core::dbus::Service::Ptr service; | 94 | core::dbus::Service::Ptr service; |
420 | 91 | // The underlying bus instance. | 95 | // The underlying bus instance. |
421 | @@ -95,11 +99,13 @@ | |||
422 | 95 | }; | 99 | }; |
423 | 96 | 100 | ||
424 | 97 | // Constructs a new Skeleton instance, installing impl for handling actual requests. | 101 | // Constructs a new Skeleton instance, installing impl for handling actual requests. |
426 | 98 | Skeleton(const Configuration& configuration); | 102 | Skeleton(Configuration configuration); |
427 | 99 | 103 | ||
428 | 100 | // From core::trust::Agent, dispatches to the actual implementation. | 104 | // From core::trust::Agent, dispatches to the actual implementation. |
429 | 101 | core::trust::Request::Answer authenticate_request_with_parameters(const RequestParameters& parameters); | 105 | core::trust::Request::Answer authenticate_request_with_parameters(const RequestParameters& parameters); |
430 | 102 | 106 | ||
431 | 107 | // Store all creation-time parameters. | ||
432 | 108 | Configuration config; | ||
433 | 103 | // Stub for accessing the remote agent registry. | 109 | // Stub for accessing the remote agent registry. |
434 | 104 | core::trust::dbus::AgentRegistry::Stub agent_registry_stub; | 110 | core::trust::dbus::AgentRegistry::Stub agent_registry_stub; |
435 | 105 | }; | 111 | }; |
436 | 106 | 112 | ||
437 | === added file 'src/core/trust/runtime.cpp' | |||
438 | --- src/core/trust/runtime.cpp 1970-01-01 00:00:00 +0000 | |||
439 | +++ src/core/trust/runtime.cpp 2016-01-03 20:28:56 +0000 | |||
440 | @@ -0,0 +1,80 @@ | |||
441 | 1 | /* | ||
442 | 2 | * Copyright © 2016 Canonical Ltd. | ||
443 | 3 | * | ||
444 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
445 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
446 | 6 | * as published by the Free Software Foundation. | ||
447 | 7 | * | ||
448 | 8 | * This program is distributed in the hope that it will be useful, | ||
449 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
450 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
451 | 11 | * GNU Lesser General Public License for more details. | ||
452 | 12 | * | ||
453 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
454 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
455 | 15 | * | ||
456 | 16 | * Authored by: Thomas Voß <thomas.voss@canonical.com> | ||
457 | 17 | */ | ||
458 | 18 | |||
459 | 19 | #include <core/trust/runtime.h> | ||
460 | 20 | |||
461 | 21 | #include <iostream> | ||
462 | 22 | #include <stdexcept> | ||
463 | 23 | |||
464 | 24 | namespace | ||
465 | 25 | { | ||
466 | 26 | void execute_and_never_throw(boost::asio::io_service& ios) noexcept(true) | ||
467 | 27 | { | ||
468 | 28 | while (true) | ||
469 | 29 | { | ||
470 | 30 | try | ||
471 | 31 | { | ||
472 | 32 | ios.run(); | ||
473 | 33 | break; | ||
474 | 34 | } | ||
475 | 35 | catch (const std::exception& e) | ||
476 | 36 | { | ||
477 | 37 | std::cerr << __PRETTY_FUNCTION__ << ": " << e.what() << std::endl; | ||
478 | 38 | } | ||
479 | 39 | catch (...) | ||
480 | 40 | { | ||
481 | 41 | std::cerr << __PRETTY_FUNCTION__ << ": unknown exception" << std::endl; | ||
482 | 42 | } | ||
483 | 43 | } | ||
484 | 44 | } | ||
485 | 45 | } | ||
486 | 46 | |||
487 | 47 | core::trust::Runtime& core::trust::Runtime::instance() | ||
488 | 48 | { | ||
489 | 49 | static Runtime runtime; | ||
490 | 50 | return runtime; | ||
491 | 51 | } | ||
492 | 52 | |||
493 | 53 | core::trust::Runtime::Runtime() | ||
494 | 54 | : signal_trap{core::posix::trap_signals_for_all_subsequent_threads({core::posix::Signal::sig_term, core::posix::Signal::sig_int})}, | ||
495 | 55 | keep_alive{io_service} | ||
496 | 56 | { | ||
497 | 57 | for (std::size_t i = 0; i < Runtime::concurrency_hint; i++) | ||
498 | 58 | { | ||
499 | 59 | pool.emplace_back(execute_and_never_throw, std::ref(io_service)); | ||
500 | 60 | } | ||
501 | 61 | |||
502 | 62 | signal_trap->signal_raised().connect([this](const core::posix::Signal&) | ||
503 | 63 | { | ||
504 | 64 | signal_trap->stop(); | ||
505 | 65 | }); | ||
506 | 66 | } | ||
507 | 67 | |||
508 | 68 | core::trust::Runtime::~Runtime() | ||
509 | 69 | { | ||
510 | 70 | io_service.stop(); | ||
511 | 71 | |||
512 | 72 | for (auto& worker : pool) | ||
513 | 73 | if (worker.joinable()) | ||
514 | 74 | worker.join(); | ||
515 | 75 | } | ||
516 | 76 | |||
517 | 77 | void core::trust::Runtime::run() | ||
518 | 78 | { | ||
519 | 79 | signal_trap->run(); | ||
520 | 80 | } | ||
521 | 0 | 81 | ||
522 | === added file 'src/core/trust/runtime.h' | |||
523 | --- src/core/trust/runtime.h 1970-01-01 00:00:00 +0000 | |||
524 | +++ src/core/trust/runtime.h 2016-01-03 20:28:56 +0000 | |||
525 | @@ -0,0 +1,73 @@ | |||
526 | 1 | /* | ||
527 | 2 | * Copyright © 2016 Canonical Ltd. | ||
528 | 3 | * | ||
529 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
530 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
531 | 6 | * as published by the Free Software Foundation. | ||
532 | 7 | * | ||
533 | 8 | * This program is distributed in the hope that it will be useful, | ||
534 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
535 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
536 | 11 | * GNU Lesser General Public License for more details. | ||
537 | 12 | * | ||
538 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
539 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
540 | 15 | * | ||
541 | 16 | * Authored by: Thomas Voß <thomas.voss@canonical.com> | ||
542 | 17 | */ | ||
543 | 18 | |||
544 | 19 | #ifndef CORE_TRUST_RUNTIME_H_ | ||
545 | 20 | #define CORE_TRUST_RUNTIME_H_ | ||
546 | 21 | |||
547 | 22 | #include <core/posix/signal.h> | ||
548 | 23 | |||
549 | 24 | #include <boost/asio.hpp> | ||
550 | 25 | |||
551 | 26 | #include <memory> | ||
552 | 27 | #include <thread> | ||
553 | 28 | #include <vector> | ||
554 | 29 | |||
555 | 30 | namespace core | ||
556 | 31 | { | ||
557 | 32 | namespace trust | ||
558 | 33 | { | ||
559 | 34 | // A Runtime maintains a pool of workers enabling | ||
560 | 35 | // implementations to dispatch invocations and have their | ||
561 | 36 | // ready handlers automatically executed. | ||
562 | 37 | struct Runtime | ||
563 | 38 | { | ||
564 | 39 | // Do not execute in parallel, serialize | ||
565 | 40 | // accesses. | ||
566 | 41 | static constexpr std::size_t concurrency_hint{2}; | ||
567 | 42 | |||
568 | 43 | // Our evil singleton pattern. Not bad though, we control the | ||
569 | 44 | // entire executable and rely on automatic cleanup of static | ||
570 | 45 | // instances. | ||
571 | 46 | static Runtime& instance(); | ||
572 | 47 | |||
573 | 48 | Runtime(); | ||
574 | 49 | |||
575 | 50 | // Gracefully shuts down operations. | ||
576 | 51 | ~Runtime() noexcept(true); | ||
577 | 52 | |||
578 | 53 | // run blocks until either stop is called or a | ||
579 | 54 | // signal requesting graceful shutdown is received. | ||
580 | 55 | void run(); | ||
581 | 56 | |||
582 | 57 | // We trap sig term to ensure a clean shutdown. | ||
583 | 58 | std::shared_ptr<core::posix::SignalTrap> signal_trap; | ||
584 | 59 | |||
585 | 60 | // Our io_service instance exposed to remote agents. | ||
586 | 61 | boost::asio::io_service io_service; | ||
587 | 62 | |||
588 | 63 | // We keep the io_service alive and introduce some artificial | ||
589 | 64 | // work. | ||
590 | 65 | boost::asio::io_service::work keep_alive; | ||
591 | 66 | |||
592 | 67 | // We execute the io_service on a pool of worker threads. | ||
593 | 68 | std::vector<std::thread> pool; | ||
594 | 69 | }; | ||
595 | 70 | } | ||
596 | 71 | } | ||
597 | 72 | |||
598 | 73 | #endif // CORE_TRUST_RUNTIME_H_ | ||
599 | 0 | 74 | ||
600 | === modified file 'tests/CMakeLists.txt' | |||
601 | --- tests/CMakeLists.txt 2014-11-14 12:17:24 +0000 | |||
602 | +++ tests/CMakeLists.txt 2016-01-03 20:28:56 +0000 | |||
603 | @@ -46,6 +46,9 @@ | |||
604 | 46 | add_executable( | 46 | add_executable( |
605 | 47 | remote_agent_test | 47 | remote_agent_test |
606 | 48 | remote_agent_test.cpp | 48 | remote_agent_test.cpp |
607 | 49 | |||
608 | 50 | ${CMAKE_SOURCE_DIR}/src/core/trust/runtime.h | ||
609 | 51 | ${CMAKE_SOURCE_DIR}/src/core/trust/runtime.cpp | ||
610 | 49 | ) | 52 | ) |
611 | 50 | 53 | ||
612 | 51 | add_executable( | 54 | add_executable( |
613 | 52 | 55 | ||
614 | === modified file 'tests/remote_agent_test.cpp' | |||
615 | --- tests/remote_agent_test.cpp 2015-08-14 09:53:12 +0000 | |||
616 | +++ tests/remote_agent_test.cpp 2016-01-03 20:28:56 +0000 | |||
617 | @@ -30,6 +30,8 @@ | |||
618 | 30 | #include <core/dbus/asio/executor.h> | 30 | #include <core/dbus/asio/executor.h> |
619 | 31 | #include <core/dbus/fixture.h> | 31 | #include <core/dbus/fixture.h> |
620 | 32 | 32 | ||
621 | 33 | #include <core/trust/runtime.h> | ||
622 | 34 | |||
623 | 33 | #include <gmock/gmock.h> | 35 | #include <gmock/gmock.h> |
624 | 34 | #include <gtest/gtest.h> | 36 | #include <gtest/gtest.h> |
625 | 35 | 37 | ||
626 | @@ -792,6 +794,12 @@ | |||
627 | 792 | { | 794 | { |
628 | 793 | struct DBus : public core::dbus::testing::Fixture | 795 | struct DBus : public core::dbus::testing::Fixture |
629 | 794 | { | 796 | { |
630 | 797 | core::dbus::Bus::Ptr session_bus_with_executor() | ||
631 | 798 | { | ||
632 | 799 | auto sb = session_bus(); | ||
633 | 800 | sb->install_executor(core::dbus::asio::make_executor(sb, core::trust::Runtime::instance().io_service)); | ||
634 | 801 | return sb; | ||
635 | 802 | } | ||
636 | 795 | }; | 803 | }; |
637 | 796 | 804 | ||
638 | 797 | std::string service_name | 805 | std::string service_name |
639 | @@ -804,10 +812,6 @@ | |||
640 | 804 | { | 812 | { |
641 | 805 | using namespace ::testing; | 813 | using namespace ::testing; |
642 | 806 | 814 | ||
643 | 807 | core::testing::CrossProcessSync | ||
644 | 808 | stub_ready, // signals stub --| I'm ready |--> skeleton | ||
645 | 809 | skeleton_ready; // signals skeleton --| I'm ready |--> stub | ||
646 | 810 | |||
647 | 811 | auto app = core::posix::fork([]() | 815 | auto app = core::posix::fork([]() |
648 | 812 | { | 816 | { |
649 | 813 | while(true) std::this_thread::sleep_for(std::chrono::milliseconds{500}); | 817 | while(true) std::this_thread::sleep_for(std::chrono::milliseconds{500}); |
650 | @@ -825,7 +829,50 @@ | |||
651 | 825 | const core::trust::Uid app_uid{::getuid()}; | 829 | const core::trust::Uid app_uid{::getuid()}; |
652 | 826 | const core::trust::Pid app_pid{app.pid()}; | 830 | const core::trust::Pid app_pid{app.pid()}; |
653 | 827 | 831 | ||
655 | 828 | auto stub = core::posix::fork([this, app_uid, app_pid, answer, &stub_ready, &skeleton_ready]() | 832 | auto skeleton = core::posix::fork([this, answer]() |
656 | 833 | { | ||
657 | 834 | auto bus = session_bus_with_executor(); | ||
658 | 835 | |||
659 | 836 | // We have to rely on a MockAgent to break the dependency on a running Mir instance. | ||
660 | 837 | auto mock_agent = std::make_shared<::testing::NiceMock<MockAgent>>(); | ||
661 | 838 | |||
662 | 839 | ON_CALL(*mock_agent, authenticate_request_with_parameters(_)) | ||
663 | 840 | .WillByDefault(Return(answer)); | ||
664 | 841 | |||
665 | 842 | std::string dbus_service_name = core::trust::remote::dbus::default_service_name_prefix + std::string{"."} + service_name; | ||
666 | 843 | |||
667 | 844 | auto service = core::dbus::Service::use_service(bus, dbus_service_name); | ||
668 | 845 | auto object = service->object_for_path(core::dbus::types::ObjectPath | ||
669 | 846 | { | ||
670 | 847 | core::trust::remote::dbus::default_agent_registry_path | ||
671 | 848 | }); | ||
672 | 849 | |||
673 | 850 | core::dbus::DBus daemon{bus}; | ||
674 | 851 | |||
675 | 852 | core::trust::remote::dbus::Agent::Skeleton::Configuration config | ||
676 | 853 | { | ||
677 | 854 | mock_agent, | ||
678 | 855 | object, | ||
679 | 856 | daemon.make_service_watcher(dbus_service_name), | ||
680 | 857 | service, | ||
681 | 858 | bus, | ||
682 | 859 | core::trust::remote::helpers::aa_get_task_con_app_id_resolver() | ||
683 | 860 | }; | ||
684 | 861 | |||
685 | 862 | auto skeleton = std::make_shared<core::trust::remote::dbus::Agent::Skeleton>(std::move(config)); | ||
686 | 863 | |||
687 | 864 | core::trust::Runtime::instance().run(); | ||
688 | 865 | return core::posix::exit::Status::success; | ||
689 | 866 | }, core::posix::StandardStream::empty); | ||
690 | 867 | |||
691 | 868 | |||
692 | 869 | // stubf models a trusted helper, with the following simplified | ||
693 | 870 | // mode of operation: | ||
694 | 871 | // (1.) Helper claims its unique name on the bus. | ||
695 | 872 | // (2.) Helper installs an AgentRegistry::Skeleton. | ||
696 | 873 | // (3.) Helper learns about per-user trust::Agent instances on the bus. | ||
697 | 874 | // (4.) Helper issues requests for authentication. | ||
698 | 875 | auto stubf = [this, app_uid, app_pid, answer]() | ||
699 | 829 | { | 876 | { |
700 | 830 | core::trust::Agent::RequestParameters ref_params | 877 | core::trust::Agent::RequestParameters ref_params |
701 | 831 | { | 878 | { |
702 | @@ -836,10 +883,7 @@ | |||
703 | 836 | "just an example description" | 883 | "just an example description" |
704 | 837 | }; | 884 | }; |
705 | 838 | 885 | ||
710 | 839 | auto bus = session_bus(); | 886 | auto bus = session_bus_with_executor(); |
707 | 840 | bus->install_executor(core::dbus::asio::make_executor(bus)); | ||
708 | 841 | |||
709 | 842 | std::thread worker{[bus]() { bus->run(); }}; | ||
711 | 843 | 887 | ||
712 | 844 | std::string dbus_service_name = core::trust::remote::dbus::default_service_name_prefix + std::string{"."} + service_name; | 888 | std::string dbus_service_name = core::trust::remote::dbus::default_service_name_prefix + std::string{"."} + service_name; |
713 | 845 | 889 | ||
714 | @@ -857,76 +901,24 @@ | |||
715 | 857 | 901 | ||
716 | 858 | auto stub = std::make_shared<core::trust::remote::dbus::Agent::Stub>(config); | 902 | auto stub = std::make_shared<core::trust::remote::dbus::Agent::Stub>(config); |
717 | 859 | 903 | ||
720 | 860 | stub_ready.try_signal_ready_for(std::chrono::milliseconds{1000}); | 904 | std::this_thread::sleep_for(std::chrono::seconds(1)); |
719 | 861 | skeleton_ready.wait_for_signal_ready_for(std::chrono::milliseconds{1000}); | ||
721 | 862 | 905 | ||
722 | 863 | for (unsigned int i = 0; i < 100; i++) | 906 | for (unsigned int i = 0; i < 100; i++) |
723 | 864 | EXPECT_EQ(answer, stub->authenticate_request_with_parameters(ref_params)); | 907 | EXPECT_EQ(answer, stub->authenticate_request_with_parameters(ref_params)); |
724 | 865 | 908 | ||
725 | 866 | bus->stop(); | ||
726 | 867 | |||
727 | 868 | if (worker.joinable()) | ||
728 | 869 | worker.join(); | ||
729 | 870 | |||
730 | 871 | return Test::HasFailure() ? | 909 | return Test::HasFailure() ? |
731 | 872 | core::posix::exit::Status::failure : | 910 | core::posix::exit::Status::failure : |
732 | 873 | core::posix::exit::Status::success; | 911 | core::posix::exit::Status::success; |
789 | 874 | }, core::posix::StandardStream::empty); | 912 | }; |
790 | 875 | 913 | ||
791 | 876 | auto skeleton = core::posix::fork([this, answer, &stub_ready, &skeleton_ready]() | 914 | std::this_thread::sleep_for(std::chrono::seconds(2)); |
792 | 877 | { | 915 | auto stub = core::posix::fork(stubf, core::posix::StandardStream::empty); |
793 | 878 | auto trap = core::posix::trap_signals_for_all_subsequent_threads({core::posix::Signal::sig_term}); | 916 | EXPECT_TRUE(ProcessExitedSuccessfully(stub.wait_for(core::posix::wait::Flags::untraced))); |
794 | 879 | 917 | ||
795 | 880 | trap->signal_raised().connect([trap](core::posix::Signal) | 918 | std::this_thread::sleep_for(std::chrono::seconds(2)); |
796 | 881 | { | 919 | stub = core::posix::fork(stubf, core::posix::StandardStream::empty); |
797 | 882 | trap->stop(); | 920 | EXPECT_TRUE(ProcessExitedSuccessfully(stub.wait_for(core::posix::wait::Flags::untraced))); |
798 | 883 | }); | 921 | |
743 | 884 | |||
744 | 885 | auto bus = session_bus(); | ||
745 | 886 | bus->install_executor(core::dbus::asio::make_executor(bus)); | ||
746 | 887 | |||
747 | 888 | std::thread worker{[bus]() { bus->run(); }}; | ||
748 | 889 | |||
749 | 890 | // We have to rely on a MockAgent to break the dependency on a running Mir instance. | ||
750 | 891 | auto mock_agent = std::make_shared<::testing::NiceMock<MockAgent>>(); | ||
751 | 892 | |||
752 | 893 | ON_CALL(*mock_agent, authenticate_request_with_parameters(_)) | ||
753 | 894 | .WillByDefault(Return(answer)); | ||
754 | 895 | |||
755 | 896 | std::string dbus_service_name = core::trust::remote::dbus::default_service_name_prefix + std::string{"."} + service_name; | ||
756 | 897 | |||
757 | 898 | stub_ready.wait_for_signal_ready_for(std::chrono::milliseconds{1000}); | ||
758 | 899 | |||
759 | 900 | auto service = core::dbus::Service::use_service(bus, dbus_service_name); | ||
760 | 901 | auto object = service->object_for_path(core::dbus::types::ObjectPath | ||
761 | 902 | { | ||
762 | 903 | core::trust::remote::dbus::default_agent_registry_path | ||
763 | 904 | }); | ||
764 | 905 | |||
765 | 906 | core::trust::remote::dbus::Agent::Skeleton::Configuration config | ||
766 | 907 | { | ||
767 | 908 | mock_agent, | ||
768 | 909 | object, | ||
769 | 910 | service, | ||
770 | 911 | bus, | ||
771 | 912 | core::trust::remote::helpers::aa_get_task_con_app_id_resolver() | ||
772 | 913 | }; | ||
773 | 914 | |||
774 | 915 | auto skeleton = std::make_shared<core::trust::remote::dbus::Agent::Skeleton>(config); | ||
775 | 916 | |||
776 | 917 | skeleton_ready.try_signal_ready_for(std::chrono::milliseconds{1000}); | ||
777 | 918 | |||
778 | 919 | trap->run(); | ||
779 | 920 | |||
780 | 921 | bus->stop(); | ||
781 | 922 | |||
782 | 923 | if (worker.joinable()) | ||
783 | 924 | worker.join(); | ||
784 | 925 | |||
785 | 926 | return core::posix::exit::Status::success; | ||
786 | 927 | }, core::posix::StandardStream::empty); | ||
787 | 928 | |||
788 | 929 | EXPECT_TRUE(ProcessExitedSuccessfully(stub.wait_for(core::posix::wait::Flags::untraced))); | ||
799 | 930 | skeleton.send_signal_or_throw(core::posix::Signal::sig_term); | 922 | skeleton.send_signal_or_throw(core::posix::Signal::sig_term); |
800 | 931 | EXPECT_TRUE(ProcessExitedSuccessfully(skeleton.wait_for(core::posix::wait::Flags::untraced))); | 923 | EXPECT_TRUE(ProcessExitedSuccessfully(skeleton.wait_for(core::posix::wait::Flags::untraced))); |
801 | 932 | 924 |