Merge lp:~albaguirre/trust-store/fix-1377159 into lp:trust-store

Proposed by Alberto Aguirre
Status: Merged
Approved by: Thomas Voß
Approved revision: 46
Merged at revision: 44
Proposed branch: lp:~albaguirre/trust-store/fix-1377159
Merge into: lp:trust-store
Diff against target: 125 lines (+34/-12)
4 files modified
include/core/trust/mir_agent.h (+11/-1)
src/core/trust/daemon.cpp (+20/-6)
src/core/trust/daemon_skeleton_main.cpp (+1/-1)
src/core/trust/mir/agent.cpp (+2/-4)
To merge this branch: bzr merge lp:~albaguirre/trust-store/fix-1377159
Reviewer Review Type Date Requested Status
Thomas Voß (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+237147@code.launchpad.net

Commit message

Attempt mir connection more than once

Description of the change

Attempt mir connection more than once

This workarounds a race when unity8 is restarted, which I suppose restarts the ubuntu-location-service-trust-stored service but unity8's mirserver is not ready yet for connections.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
45. By Alberto Aguirre

Catch all exceptions during configuration.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
46. By Alberto Aguirre

add TODO for logging reconnection attempts

Revision history for this message
Thomas Voß (thomas-voss) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/core/trust/mir_agent.h'
2--- include/core/trust/mir_agent.h 2014-08-06 10:06:43 +0000
3+++ include/core/trust/mir_agent.h 2014-10-06 14:47:15 +0000
4@@ -22,6 +22,7 @@
5 #include <core/trust/visibility.h>
6
7 #include <memory>
8+#include <stdexcept>
9
10 // Forward declare the MirConnection type.
11 struct MirConnection;
12@@ -35,6 +36,15 @@
13
14 namespace mir
15 {
16+
17+class InvalidMirConnection : public std::runtime_error
18+{
19+public:
20+ explicit InvalidMirConnection(const char* what_arg)
21+ : std::runtime_error(what_arg)
22+ {}
23+};
24+
25 /**
26 * @brief Helper function building up a connection to Mir.
27 * @param endpoint The name of the endpoint exposed by the Mir instance.
28@@ -46,7 +56,7 @@
29 /**
30 * @brief create_agent_for_mir_connection creates a trust::Agent implementation leveraging Mir's trusted prompting API.
31 * @param connection An existing connection to a Mir instance.
32- * @throws std::logic_error if the connection object is NULL.
33+ * @throws InvalidMirConnection if the connection object is invalid.
34 */
35 CORE_TRUST_DLL_PUBLIC std::shared_ptr<core::trust::Agent> create_agent_for_mir_connection(MirConnection* connection);
36 }
37
38=== modified file 'src/core/trust/daemon.cpp'
39--- src/core/trust/daemon.cpp 2014-08-26 14:50:22 +0000
40+++ src/core/trust/daemon.cpp 2014-10-06 14:47:15 +0000
41@@ -41,6 +41,7 @@
42 #include <boost/program_options.hpp>
43
44 #include <thread>
45+#include <chrono>
46
47 namespace Options = boost::program_options;
48
49@@ -193,12 +194,25 @@
50
51 auto trusted_mir_socket = dict.at("trusted-mir-socket");
52
53- auto agent = core::trust::mir::create_agent_for_mir_connection(
54- core::trust::mir::connect(
55- trusted_mir_socket,
56- service_name));
57-
58- return agent;
59+ // TODO: log reconnection attempts
60+ int connection_attempts = 5;
61+ while (true)
62+ {
63+ try
64+ {
65+ return core::trust::mir::create_agent_for_mir_connection(
66+ core::trust::mir::connect(
67+ trusted_mir_socket,
68+ service_name));
69+ }
70+ catch (core::trust::mir::InvalidMirConnection const&)
71+ {
72+ if (--connection_attempts == 0)
73+ throw;
74+ }
75+ std::this_thread::sleep_for(std::chrono::seconds(1));
76+ std::cerr << "reattempt connection to mir..."<< std::endl;
77+ }
78 }
79 },
80 {
81
82=== modified file 'src/core/trust/daemon_skeleton_main.cpp'
83--- src/core/trust/daemon_skeleton_main.cpp 2014-08-13 13:44:10 +0000
84+++ src/core/trust/daemon_skeleton_main.cpp 2014-10-06 14:47:15 +0000
85@@ -31,7 +31,7 @@
86 try
87 {
88 configuration = core::trust::Daemon::Skeleton::Configuration::from_command_line(argc, argv);
89- } catch(const boost::exception& e)
90+ } catch(std::exception const& e)
91 {
92 std::cerr << "Error during initialization and startup: " << boost::diagnostic_information(e) << std::endl;
93 return EXIT_FAILURE;
94
95=== modified file 'src/core/trust/mir/agent.cpp'
96--- src/core/trust/mir/agent.cpp 2014-09-18 21:07:05 +0000
97+++ src/core/trust/mir/agent.cpp 2014-10-06 14:47:15 +0000
98@@ -17,8 +17,8 @@
99 */
100
101 #include "agent.h"
102-
103 #include "prompt_main.h"
104+#include <core/trust/mir_agent.h>
105
106 // For getuid
107 #include <fcntl.h>
108@@ -90,7 +90,7 @@
109 mir::ConnectionVirtualTable::ConnectionVirtualTable(MirConnection* connection)
110 : connection{connection}
111 {
112- if (mir_connection_is_valid(connection) == mir_false) throw std::runtime_error
113+ if (mir_connection_is_valid(connection) == mir_false) throw InvalidMirConnection
114 {
115 "Cannot create instance for invalid connection to Mir."
116 };
117@@ -267,8 +267,6 @@
118 return std::tie(lhs.application_id, lhs.description, lhs.fd) == std::tie(rhs.application_id, rhs.description, rhs.fd);
119 }
120
121-#include <core/trust/mir_agent.h>
122-
123 #include "config.h"
124
125 MirConnection* mir::connect(const std::string& endpoint, const std::string& name)

Subscribers

People subscribed via source and target branches