Merge lp:~alan-griffiths/unity-system-compositor/private-mir-connection into lp:unity-system-compositor

Proposed by Alan Griffiths
Status: Work in progress
Proposed branch: lp:~alan-griffiths/unity-system-compositor/private-mir-connection
Merge into: lp:unity-system-compositor
Diff against target: 213 lines (+69/-19)
5 files modified
debian/control (+2/-0)
src/dm_connection.cpp (+48/-3)
src/dm_connection.h (+7/-5)
src/system_compositor.cpp (+11/-11)
src/system_compositor.h (+1/-0)
To merge this branch: bzr merge lp:~alan-griffiths/unity-system-compositor/private-mir-connection
Reviewer Review Type Date Requested Status
Unity System Compositor Development Team Pending
Review via email: mp+203097@code.launchpad.net

Commit message

Description of the change

To post a comment you must log in.

Unmerged revisions

112. By Alan Griffiths

merge lp:~robert-ancell/unity-system-compositor/private-mir-connection

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2014-01-02 21:28:20 +0000
3+++ debian/control 2014-01-24 15:20:41 +0000
4@@ -32,6 +32,8 @@
5 Architecture: any
6 Depends: ${misc:Depends},
7 ${shlibs:Depends},
8+ xserver-xorg-xmir,
9+Breaks: lightdm (<< 1.8.2)
10 Description: System compositor for Ubuntu
11 System compositor used by the Mir display server in Ubuntu. If the Unity
12 System Compositor can't start, LightDM will fallback to plain Xorg display
13
14=== modified file 'src/dm_connection.cpp'
15--- src/dm_connection.cpp 2013-07-09 19:18:59 +0000
16+++ src/dm_connection.cpp 2014-01-24 15:20:41 +0000
17@@ -37,7 +37,7 @@
18
19 void DMConnection::read_header()
20 {
21- ba::async_read(from_dm_pipe,
22+ ba::async_read(dm_socket,
23 ba::buffer(message_header_bytes),
24 boost::bind(&DMConnection::on_read_header,
25 this,
26@@ -49,7 +49,7 @@
27 if (!ec)
28 {
29 size_t const payload_length = message_header_bytes[2] << 8 | message_header_bytes[3];
30- ba::async_read(from_dm_pipe,
31+ ba::async_read(dm_socket,
32 message_payload_buffer,
33 ba::transfer_exactly(payload_length),
34 boost::bind(&DMConnection::on_read_payload,
35@@ -100,6 +100,17 @@
36 handler->set_next_session(client_name);
37 break;
38 }
39+ case USCMessageID::add_session:
40+ {
41+ std::cerr << "add_session" << std::endl;
42+ if (handler)
43+ {
44+ auto fd = handler->add_session();
45+ send(USCMessageID::session_added, "");
46+ send_fd(fd);
47+ }
48+ break;
49+ }
50 default:
51 std::cerr << "Ignoring unknown message " << (uint16_t) message_id << " with " << payload_length << " octets" << std::endl;
52 break;
53@@ -128,5 +139,39 @@
54 std::copy(body.begin(), body.end(), write_buffer.begin() + sizeof header_bytes);
55
56 // FIXME: Make asynchronous
57- ba::write(to_dm_pipe, ba::buffer(write_buffer));
58+ ba::write(dm_socket, ba::buffer(write_buffer));
59+}
60+
61+void DMConnection::send_fd(int fd)
62+{
63+ char dummy_iov_data = '\0';
64+ struct iovec iov;
65+ struct msghdr header;
66+ struct cmsghdr *control_header;
67+ int *control_data;
68+ void *message;
69+
70+ /* Send dummy data */
71+ iov.iov_base = &dummy_iov_data;
72+ iov.iov_len = 1;
73+
74+ /* Send control message with file descriptor */
75+ memset (&header, 0, sizeof (header));
76+ header.msg_iov = &iov;
77+ header.msg_iovlen = 1;
78+ header.msg_controllen = sizeof (struct cmsghdr) + sizeof (int);
79+ message = malloc (header.msg_controllen);
80+ header.msg_control = message;
81+ control_header = CMSG_FIRSTHDR (&header);
82+ control_header->cmsg_len = header.msg_controllen;
83+ control_header->cmsg_level = SOL_SOCKET;
84+ control_header->cmsg_type = SCM_RIGHTS;
85+
86+ control_data = (int*) CMSG_DATA (control_header);
87+ *control_data = fd;
88+
89+ if (sendmsg (dm_socket.native_handle(), &header, 0) < 0)
90+ std::cerr << "Failed to send file descriptor: " << strerror (errno) << std::endl;
91+
92+ free (message);
93 }
94
95=== modified file 'src/dm_connection.h'
96--- src/dm_connection.h 2013-11-13 13:53:51 +0000
97+++ src/dm_connection.h 2014-01-24 15:20:41 +0000
98@@ -26,6 +26,7 @@
99 public:
100 virtual void set_active_session(std::string client_name) = 0;
101 virtual void set_next_session(std::string client_name) = 0;
102+ virtual int add_session() = 0;
103 };
104
105 enum class USCMessageID
106@@ -36,14 +37,15 @@
107 session_connected = 3,
108 set_active_session = 4,
109 set_next_session = 5,
110+ add_session = 6,
111+ session_added = 7,
112 };
113
114 class DMConnection
115 {
116 public:
117- DMConnection(boost::asio::io_service& io_service, int from_dm_fd, int to_dm_fd) :
118- from_dm_pipe(io_service, from_dm_fd),
119- to_dm_pipe(io_service, to_dm_fd) {};
120+ DMConnection(boost::asio::io_service& io_service, int dm_socket_fd) :
121+ dm_socket(io_service, dm_socket_fd) {};
122
123 void set_handler(DMMessageHandler *handler)
124 {
125@@ -56,8 +58,7 @@
126
127 private:
128 DMMessageHandler *handler;
129- boost::asio::posix::stream_descriptor from_dm_pipe;
130- boost::asio::posix::stream_descriptor to_dm_pipe;
131+ boost::asio::posix::stream_descriptor dm_socket;
132 static size_t const size_of_header = 4;
133 unsigned char message_header_bytes[size_of_header];
134 boost::asio::streambuf message_payload_buffer;
135@@ -67,6 +68,7 @@
136 void on_read_header(const boost::system::error_code& ec);
137 void on_read_payload(const boost::system::error_code& ec);
138 void send(USCMessageID id, std::string const& body);
139+ void send_fd(int fd);
140 };
141
142 #endif /* DM_CONNECTION_H_ */
143
144=== modified file 'src/system_compositor.cpp'
145--- src/system_compositor.cpp 2013-11-22 16:53:52 +0000
146+++ src/system_compositor.cpp 2014-01-24 15:20:41 +0000
147@@ -27,6 +27,7 @@
148 #include <mir/shell/session.h>
149 #include <mir/shell/focus_controller.h>
150 #include <mir/input/cursor_listener.h>
151+#include <mir/frontend/connector.h>
152
153 #include <cerrno>
154 #include <iostream>
155@@ -91,21 +92,15 @@
156 : mir::DefaultServerConfiguration(argc, (char const **)argv), compositor{compositor}
157 {
158 add_options()
159- ("from-dm-fd", po::value<int>(), "File descriptor of read end of pipe from display manager [int]")
160- ("to-dm-fd", po::value<int>(), "File descriptor of write end of pipe to display manager [int]")
161+ ("dm-socket-fd", po::value<int>(), "File descriptor of socket to display manager [int]")
162 ("blacklist", po::value<std::string>(), "Video blacklist regex to use")
163 ("version", "Show version of Unity System Compositor")
164 ("public-socket", po::value<bool>(), "Make the socket file publicly writable");
165 }
166
167- int from_dm_fd()
168- {
169- return the_options()->get("from-dm-fd", -1);
170- }
171-
172- int to_dm_fd()
173- {
174- return the_options()->get("to-dm-fd", -1);
175+ int dm_socket_fd()
176+ {
177+ return the_options()->get("dm-socket-fd", -1);
178 }
179
180 bool show_version()
181@@ -237,7 +232,7 @@
182 return;
183 }
184
185- dm_connection = std::make_shared<DMConnection>(io_service, config->from_dm_fd(), config->to_dm_fd());
186+ dm_connection = std::make_shared<DMConnection>(io_service, config->dm_socket_fd());
187
188 struct ScopeGuard
189 {
190@@ -312,6 +307,11 @@
191 std::cerr << "Unable to set next session, unknown client name " << client_name << std::endl;
192 }
193
194+int SystemCompositor::add_session()
195+{
196+ return config->the_connector()->client_socket_fd();
197+}
198+
199 void SystemCompositor::main()
200 {
201 // Make socket world-writable, since users need to talk to us. No worries
202
203=== modified file 'src/system_compositor.h'
204--- src/system_compositor.h 2013-11-22 16:53:52 +0000
205+++ src/system_compositor.h 2014-01-24 15:20:41 +0000
206@@ -42,6 +42,7 @@
207
208 void set_active_session(std::string client_name);
209 void set_next_session(std::string client_name);
210+ int add_session();
211 void main();
212 void qt_main(int argc, char **argv);
213 };

Subscribers

People subscribed via source and target branches