Merge lp:~brandontschaefer/libertine/maliit-server-proxy into lp:libertine

Proposed by Brandon Schaefer
Status: Merged
Approved by: Christopher Townsend
Approved revision: 232
Merged at revision: 233
Proposed branch: lp:~brandontschaefer/libertine/maliit-server-proxy
Merge into: lp:libertine
Diff against target: 255 lines (+124/-31)
4 files modified
debian/control (+2/-0)
python/libertine/Libertine.py (+3/-1)
tools/libertine-launch (+36/-12)
tools/libertine-session-bridge (+83/-18)
To merge this branch: bzr merge lp:~brandontschaefer/libertine/maliit-server-proxy
Reviewer Review Type Date Requested Status
Christopher Townsend Approve
Libertine CI Bot continuous-integration Approve
Review via email: mp+294301@code.launchpad.net

Commit message

Set up a new proxy socket for the maliit server.

Description of the change

Set up a new proxy socket for the maliit server.

We now setup a mapping between the host socket and the address so when we find a socket in the mapping we can send it up to create a new connection for that address and socket.

We also attempt a bit more error handling if we cannot find dbus or maliit socket. Attempt to clean it up if something goes wrong.

The maliit server is not required, so we dont exit if we fail. DBus is.

To post a comment you must log in.
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Broke something will have to look at

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Ok turns out, if you attempt to get the dbus address *before* you open to socket you'll have a bad time. Though im still not 100% why we cant ask for the env variable (though i tired and it didnt work) Soo theres a reason :).

So right now we've two types of proxy sockets, required and optional.

Required:
DBus socket

Optional:
Maliit socket

The optional one, we pass an any exception we hit while attempting to creating it and just attempt to move on. If its a major issue such as memory something else with hit that exception. The key part is we clean up the socket if any errors happen now. Which with real file sockets is annoying to deal with :)

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
229. By Brandon Schaefer

* We now depend on python3-dbus
* Missing new line

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
230. By Brandon Schaefer

* Opps need build depends!

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

I seem to remember that some package or packages have to be installed inside the container as well to make this work. Do we need to seed any packages for this?

review: Needs Information
231. By Brandon Schaefer

* Seed maliit input contexts gtk/qt

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Approve (continuous-integration)
232. By Brandon Schaefer

* Dont seed these packages until they are working!

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

Ok, looks good to me for getting the base parts of this in.

review: Approve

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 2016-05-19 19:55:34 +0000
3+++ debian/control 2016-06-02 18:43:46 +0000
4@@ -22,6 +22,7 @@
5 python3-psutil,
6 python3-testtools,
7 python3-xdg,
8+ python3-dbus,
9 qtdeclarative5-dev
10 Standards-Version: 3.9.6
11 Homepage: https://launchpad.net/libertine
12@@ -32,6 +33,7 @@
13 python3-libertine-lxc,
14 qml-module-qtquick2,
15 qtdeclarative5-ubuntu-ui-toolkit-plugin,
16+ python3-dbus,
17 ${misc:Depends},
18 ${shlibs:Depends}
19 Description: sandbox for running deb-packaged X11 apps on Ubuntu Personal
20
21=== modified file 'python/libertine/Libertine.py'
22--- python/libertine/Libertine.py 2016-05-16 20:11:01 +0000
23+++ python/libertine/Libertine.py 2016-06-02 18:43:46 +0000
24@@ -77,7 +77,9 @@
25 self.container_type = 'unknown'
26 self.container_id = container_id
27 self.root_path = libertine.utils.get_libertine_container_rootfs_path(self.container_id)
28- self.default_packages = ['matchbox', 'libnss-extrausers', 'software-properties-common',
29+ self.default_packages = ['matchbox',
30+ 'libnss-extrausers',
31+ 'software-properties-common',
32 'humanity-icon-theme']
33
34 def create_libertine_container(self, password=None, multiarch=False, verbosity=1):
35
36=== modified file 'tools/libertine-launch'
37--- tools/libertine-launch 2016-05-05 20:41:46 +0000
38+++ tools/libertine-launch 2016-06-02 18:43:46 +0000
39@@ -25,18 +25,36 @@
40 from libertine import LibertineContainer
41
42
43-def set_dbus_session_socket_path():
44+def get_session_socket_path(session_socket_name):
45 unique_id = os.environ['DISPLAY'].strip(':')
46
47 if not os.path.exists(libertine.utils.get_libertine_runtime_dir()):
48 os.makedirs(libertine.utils.get_libertine_runtime_dir())
49
50- dbus_session_socket_path = (
51- os.path.join(libertine.utils.get_libertine_runtime_dir(), 'host_dbus_session' + unique_id))
52-
53- os.environ['DBUS_SESSION_BUS_ADDRESS'] = "unix:path=" + dbus_session_socket_path
54-
55- return dbus_session_socket_path
56+ session_socket_path = (
57+ os.path.join(libertine.utils.get_libertine_runtime_dir(), session_socket_name + unique_id))
58+
59+ return session_socket_path
60+
61+
62+def get_dbus_session_socket_path():
63+ return get_session_socket_path('host_dbus_session')
64+
65+
66+def get_maliit_session_socket_path():
67+ return get_session_socket_path('host_maliit_session')
68+
69+
70+def set_env_socket_path(session_socket_path, session_env):
71+ os.environ[session_env] = "unix:path=" + session_socket_path
72+
73+
74+def set_dbus_env_socket_path(socket_path):
75+ set_env_socket_path(socket_path, 'DBUS_SESSION_BUS_ADDRESS')
76+
77+
78+def set_maliit_env_socket_path(socket_path):
79+ set_env_socket_path(socket_path, 'MALIIT_SERVER_ADDRESS')
80
81
82 def launch_libertine_session_bridge(session_socket_path):
83@@ -74,11 +92,17 @@
84 if e in os.environ:
85 del os.environ[e]
86
87- session_socket_path = set_dbus_session_socket_path()
88-
89- session_bridge = launch_libertine_session_bridge(session_socket_path)
90-
91- detect_session_bridge_socket(session_socket_path)
92+ dbus_socket_path = get_dbus_session_socket_path()
93+ maliit_socket_path = get_maliit_session_socket_path()
94+ session_bridge_arguments = dbus_socket_path + ' ' + maliit_socket_path
95+
96+ session_bridge = launch_libertine_session_bridge(session_bridge_arguments)
97+
98+ set_dbus_env_socket_path(dbus_socket_path)
99+ set_maliit_env_socket_path(maliit_socket_path)
100+
101+ # should detect the maliit socket, but dont know if its around or not here.
102+ detect_session_bridge_socket(dbus_socket_path)
103
104 container = LibertineContainer(args.container_id)
105
106
107=== modified file 'tools/libertine-session-bridge'
108--- tools/libertine-session-bridge 2016-02-04 20:23:58 +0000
109+++ tools/libertine-session-bridge 2016-06-02 18:43:46 +0000
110@@ -1,5 +1,6 @@
111 #!/usr/bin/python3
112
113+import dbus
114 import libertine.utils
115 import os
116 import select
117@@ -9,15 +10,15 @@
118 from socket import *
119
120
121-def accept_new_connection():
122- newconn = container_dbus_session_sock.accept()[0]
123+def accept_new_connection(host_adder, container_sock):
124+ newconn = container_sock.accept()[0]
125 descriptors.append(newconn)
126
127- host_dbus_session_sock = socket(AF_UNIX, SOCK_STREAM)
128- host_dbus_session_sock.connect(host_dbus_session_addr)
129- descriptors.append(host_dbus_session_sock)
130+ host_sock = socket(AF_UNIX, SOCK_STREAM)
131+ host_sock.connect(host_adder)
132+ descriptors.append(host_sock)
133
134- socket_pairs.append([newconn, host_dbus_session_sock])
135+ socket_pairs.append([newconn, host_sock])
136
137
138 def get_socket_pair(socket):
139@@ -57,6 +58,26 @@
140 j.close()
141
142
143+def get_host_maliit_socket():
144+ address_bus_name = "org.maliit.server"
145+ address_object_path = "/org/maliit/server/address"
146+ address_interface = "org.maliit.Server.Address"
147+ address_property = "address"
148+
149+ session_bus = dbus.SessionBus()
150+ maliit_object = session_bus.get_object('org.maliit.server', '/org/maliit/server/address')
151+
152+ interface = dbus.Interface(maliit_object, dbus.PROPERTIES_IFACE)
153+ address = interface.Get('org.maliit.Server.Address', 'address')
154+
155+ partition_key = 'unix:abstract='
156+ address = address.split(',')[0]
157+ address = address.partition(partition_key)[2]
158+ address = "\0%s" % address
159+
160+ return address
161+
162+
163 def get_host_dbus_socket():
164 socket_key = "DBUS_SESSION_BUS_ADDRESS=unix:abstract="
165
166@@ -73,9 +94,13 @@
167
168
169 def socket_cleanup(signum, frame):
170- container_dbus_session_sock.close()
171+ for socket in descriptors:
172+ socket.close()
173+
174 close_all_connections()
175- os.remove(dbus_session_socket_path)
176+
177+ for socket_path in session_socket_paths:
178+ os.remove(socket_path)
179
180
181 def main_loop():
182@@ -94,8 +119,8 @@
183 if sock.fileno() == -1:
184 continue
185
186- if sock == container_dbus_session_sock:
187- accept_new_connection()
188+ if sock in host_session_socket_path_map:
189+ accept_new_connection(host_session_socket_path_map[sock], sock)
190
191 else:
192 data = sock.recv(4096)
193@@ -118,14 +143,54 @@
194 totalsent = totalsent + sent
195
196
197-dbus_session_socket_path = sys.argv[1]
198-
199-container_dbus_session_sock = socket(AF_UNIX, SOCK_STREAM)
200-container_dbus_session_sock.bind(dbus_session_socket_path)
201-container_dbus_session_sock.listen(5)
202-
203-host_dbus_session_addr = get_host_dbus_socket()
204-descriptors = [container_dbus_session_sock]
205+def create_socket(session_socket_path):
206+ try:
207+ sock = socket(AF_UNIX, SOCK_STREAM)
208+ except:
209+ sock = None
210+ else:
211+ try:
212+ sock.bind(session_socket_path)
213+ sock.listen(5)
214+ except:
215+ sock.close()
216+ sock = None
217+ else:
218+ return sock
219+
220+ return None
221+
222+
223+def create_container_socket(session_socket_path, get_host_session_path_function):
224+ container_session_sock = create_socket(session_socket_path)
225+
226+ if container_session_sock is not None:
227+ try:
228+ host_session_path = get_host_session_path_function()
229+ except:
230+ container_session_sock.close()
231+ container_session_sock = None
232+ raise
233+ else:
234+ host_session_socket_path_map.update({container_session_sock:host_session_path})
235+
236+ session_socket_paths.append(session_socket_path)
237+ descriptors.append(container_session_sock)
238+
239+
240+descriptors = []
241+host_session_socket_path_map = {}
242+session_socket_paths = []
243+
244+# Required sockets:
245+create_container_socket(sys.argv[1], get_host_dbus_socket)
246+
247+# Optional sockets:
248+try:
249+ create_container_socket(sys.argv[2], get_host_maliit_socket)
250+except:
251+ pass
252+
253 socket_pairs = []
254
255 main_loop()

Subscribers

People subscribed via source and target branches