Merge lp:~jamesodhunt/upstart/bug-1235649 into lp:upstart
- bug-1235649
- Merge into trunk
Proposed by
James Hunt
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 1554 | ||||||||
Proposed branch: | lp:~jamesodhunt/upstart/bug-1235649 | ||||||||
Merge into: | lp:upstart | ||||||||
Diff against target: |
817 lines (+477/-46) 9 files modified
ChangeLog (+39/-8) dbus/com.ubuntu.Upstart.xml (+4/-0) init/control.c (+111/-18) init/control.h (+12/-1) init/main.c (+22/-7) init/tests/test_control.c (+2/-2) util/initctl.c (+53/-4) util/man/initctl.8 (+23/-6) util/tests/test_initctl.c (+211/-0) |
||||||||
To merge this branch: | bzr merge lp:~jamesodhunt/upstart/bug-1235649 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Dimitri John Ledkov | Approve | ||
Review via email: mp+192703@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote : | # |
Revision history for this message
James Hunt (jamesodhunt) wrote : | # |
Hi Dmitrijs,
> Will it be possible to publish method call NotifyDBusAddress over Private socket only
Aside from modifying the way we auto-generate the D-Bus bindings, I'm not sure. It is admittedly an annoyance, but harmless.
> User-session init integration question, will it be expected for user-session dbus job to invoke
> initctl notify-dbus-address in post-start?
Yes, we simply need to add the following to dbus.conf:
initctl notify-dbus-address $DBUS_SESSION_
Revision history for this message
Dimitri John Ledkov (xnox) : | # |
review:
Approve
- 1548. By James Hunt
-
* Sync with lp:upstart.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ChangeLog' | |||
2 | --- ChangeLog 2013-11-03 02:56:57 +0000 | |||
3 | +++ ChangeLog 2013-11-04 11:44:32 +0000 | |||
4 | @@ -1,10 +1,3 @@ | |||
5 | 1 | 2013-10-25 Steve Langasek <steve.langasek@ubuntu.com> | ||
6 | 2 | |||
7 | 3 | * init/main.c, init/system.c, init/system.h: allow mount options | ||
8 | 4 | to be passed to system_mount(), and pass the right options when | ||
9 | 5 | mounting /dev/pts to match the permissions set by either | ||
10 | 6 | initramfs-tools or mountall. LP: #1244763. | ||
11 | 7 | |||
12 | 8 | 2013-11-03 James Hunt <james.hunt@ubuntu.com> | 1 | 2013-11-03 James Hunt <james.hunt@ubuntu.com> |
13 | 9 | 2 | ||
14 | 10 | * init/job_class.c: | 3 | * init/job_class.c: |
15 | @@ -59,6 +52,44 @@ | |||
16 | 59 | * scripts/tests/test_pyupstart_session_init.py: Added file bridge tests | 52 | * scripts/tests/test_pyupstart_session_init.py: Added file bridge tests |
17 | 60 | for directory creation, modification and deletion. | 53 | for directory creation, modification and deletion. |
18 | 61 | 54 | ||
19 | 55 | 2013-10-25 James Hunt <james.hunt@ubuntu.com> | ||
20 | 56 | |||
21 | 57 | * dbus/com.ubuntu.Upstart.xml: Added 'NotifyDBusAddress' method. | ||
22 | 58 | * init/control.c: | ||
23 | 59 | - control_bus_open(): Connect to the D-Bus bus specified | ||
24 | 60 | by control_bus_address when running as a Session Init (LP: #1203595, #1235649). | ||
25 | 61 | - control_disconnected(): Display calculated bus type rather than hard-coding. | ||
26 | 62 | - control_handle_bus_type(): Removed. | ||
27 | 63 | - control_get_bus_type(): Determine type of D-Bus bus that will be used. | ||
28 | 64 | - control_notify_dbus_address(): Implementation of D-Bus 'NotifyDBusAddress' method | ||
29 | 65 | that sets control_bus_address. | ||
30 | 66 | * init/main.c: | ||
31 | 67 | - main(): | ||
32 | 68 | - Just check USE_SESSION_BUS_ENV variable rather than calling | ||
33 | 69 | control_handle_bus_type(). | ||
34 | 70 | - Don't register SIGUSR1 handler for Session Init. | ||
35 | 71 | - usr1_handler(): Display calculated bus type rather than hard-coding. | ||
36 | 72 | * init/test_control.c: Updated strings used by tests which check error | ||
37 | 73 | messages to include 'D-Bus'. | ||
38 | 74 | * util/initctl.c: Added new 'notify-dbus-address' command. | ||
39 | 75 | * util/man/initctl.8: | ||
40 | 76 | - Documentation for new 'notify-dbus-address' command. | ||
41 | 77 | - reset-env: Troff fix. | ||
42 | 78 | - Explain '--user' implicit in user mode. | ||
43 | 79 | * util/tests/test_initctl.c: test_dbus_connection(): New function providing | ||
44 | 80 | the following new tests: | ||
45 | 81 | - "ensure non-priv non-Session Init connects to D-Bus session bus on startup". | ||
46 | 82 | - "ensure Session Init does not connect to D-Bus session bus on startup". | ||
47 | 83 | - "ensure Session Init connects to D-Bus session bus when notified". | ||
48 | 84 | - "ensure Session Init does not connect to another bus when notified twice". | ||
49 | 85 | |||
50 | 86 | 2013-10-25 Steve Langasek <steve.langasek@ubuntu.com> | ||
51 | 87 | |||
52 | 88 | * init/main.c, init/system.c, init/system.h: allow mount options | ||
53 | 89 | to be passed to system_mount(), and pass the right options when | ||
54 | 90 | mounting /dev/pts to match the permissions set by either | ||
55 | 91 | initramfs-tools or mountall. LP: #1244763. | ||
56 | 92 | |||
57 | 62 | 2013-10-24 James Hunt <james.hunt@ubuntu.com> | 93 | 2013-10-24 James Hunt <james.hunt@ubuntu.com> |
58 | 63 | 94 | ||
59 | 64 | * init/environ.c: Comment. | 95 | * init/environ.c: Comment. |
60 | @@ -79,7 +110,7 @@ | |||
61 | 79 | 110 | ||
62 | 80 | 2013-10-23 Dmitrijs Ledkovs <xnox@ubuntu.com> | 111 | 2013-10-23 Dmitrijs Ledkovs <xnox@ubuntu.com> |
63 | 81 | 112 | ||
65 | 82 | * extra/upstart-socket-bridge.c: use SOCKET_PATH in our event | 113 | * extra/upstart-socket-bridge.c: use SOCKET_PATH in our event |
66 | 83 | environment, instead of clobbering PATH. (LP: #1235480) | 114 | environment, instead of clobbering PATH. (LP: #1235480) |
67 | 84 | 115 | ||
68 | 85 | 2013-10-23 James Hunt <james.hunt@ubuntu.com> | 116 | 2013-10-23 James Hunt <james.hunt@ubuntu.com> |
69 | 86 | 117 | ||
70 | === modified file 'dbus/com.ubuntu.Upstart.xml' | |||
71 | --- dbus/com.ubuntu.Upstart.xml 2013-02-08 16:15:23 +0000 | |||
72 | +++ dbus/com.ubuntu.Upstart.xml 2013-11-04 11:44:32 +0000 | |||
73 | @@ -103,6 +103,10 @@ | |||
74 | 103 | <method name="NotifyDiskWriteable"> | 103 | <method name="NotifyDiskWriteable"> |
75 | 104 | </method> | 104 | </method> |
76 | 105 | 105 | ||
77 | 106 | <method name="NotifyDBusAddress"> | ||
78 | 107 | <arg name="address" type="s" direction="in" /> | ||
79 | 108 | </method> | ||
80 | 109 | |||
81 | 106 | <method name="EndSession"/> | 110 | <method name="EndSession"/> |
82 | 107 | 111 | ||
83 | 108 | <!-- Basic information about Upstart --> | 112 | <!-- Basic information about Upstart --> |
84 | 109 | 113 | ||
85 | === modified file 'init/control.c' | |||
86 | --- init/control.c 2013-04-22 10:30:09 +0000 | |||
87 | +++ init/control.c 2013-11-04 11:44:32 +0000 | |||
88 | @@ -81,11 +81,19 @@ | |||
89 | 81 | * | 81 | * |
90 | 82 | * If TRUE, connect to the D-Bus session bus rather than the system bus. | 82 | * If TRUE, connect to the D-Bus session bus rather than the system bus. |
91 | 83 | * | 83 | * |
93 | 84 | * Used for testing. | 84 | * Used for testing to simulate (as far as possible) a system-like init |
94 | 85 | * when running as a non-priv user (but not as a Session Init). | ||
95 | 85 | **/ | 86 | **/ |
96 | 86 | int use_session_bus = FALSE; | 87 | int use_session_bus = FALSE; |
97 | 87 | 88 | ||
98 | 88 | /** | 89 | /** |
99 | 90 | * dbus_bus_type: | ||
100 | 91 | * | ||
101 | 92 | * Type of D-Bus bus to connect to. | ||
102 | 93 | **/ | ||
103 | 94 | DBusBusType dbus_bus_type; | ||
104 | 95 | |||
105 | 96 | /** | ||
106 | 89 | * control_server_address: | 97 | * control_server_address: |
107 | 90 | * | 98 | * |
108 | 91 | * Address on which the control server may be reached. | 99 | * Address on which the control server may be reached. |
109 | @@ -100,6 +108,13 @@ | |||
110 | 100 | DBusServer *control_server = NULL; | 108 | DBusServer *control_server = NULL; |
111 | 101 | 109 | ||
112 | 102 | /** | 110 | /** |
113 | 111 | * control_bus_address: | ||
114 | 112 | * | ||
115 | 113 | * Address on which the control bus may be reached. | ||
116 | 114 | **/ | ||
117 | 115 | char *control_bus_address = NULL; | ||
118 | 116 | |||
119 | 117 | /** | ||
120 | 103 | * control_bus: | 118 | * control_bus: |
121 | 104 | * | 119 | * |
122 | 105 | * Open connection to a D-Bus bus. The connection may be opened with | 120 | * Open connection to a D-Bus bus. The connection may be opened with |
123 | @@ -236,7 +251,6 @@ | |||
124 | 236 | control_server = NULL; | 251 | control_server = NULL; |
125 | 237 | } | 252 | } |
126 | 238 | 253 | ||
127 | 239 | |||
128 | 240 | /** | 254 | /** |
129 | 241 | * control_bus_open: | 255 | * control_bus_open: |
130 | 242 | * | 256 | * |
131 | @@ -256,17 +270,37 @@ | |||
132 | 256 | 270 | ||
133 | 257 | nih_assert (control_bus == NULL); | 271 | nih_assert (control_bus == NULL); |
134 | 258 | 272 | ||
135 | 273 | dbus_error_init (&error); | ||
136 | 274 | |||
137 | 259 | control_init (); | 275 | control_init (); |
138 | 260 | 276 | ||
140 | 261 | control_handle_bus_type (); | 277 | dbus_bus_type = control_get_bus_type (); |
141 | 262 | 278 | ||
143 | 263 | /* Connect to the D-Bus System Bus and hook everything up into | 279 | /* Connect to the appropriate D-Bus bus and hook everything up into |
144 | 264 | * our own main loop automatically. | 280 | * our own main loop automatically. |
145 | 265 | */ | 281 | */ |
150 | 266 | conn = nih_dbus_bus (use_session_bus ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, | 282 | if (user_mode && control_bus_address) { |
151 | 267 | control_disconnected); | 283 | conn = nih_dbus_connect (control_bus_address, control_disconnected); |
152 | 268 | if (! conn) | 284 | if (! conn) |
153 | 269 | return -1; | 285 | return -1; |
154 | 286 | |||
155 | 287 | if (! dbus_bus_register (conn, &error)) { | ||
156 | 288 | nih_dbus_error_raise (error.name, error.message); | ||
157 | 289 | dbus_error_free (&error); | ||
158 | 290 | return -1; | ||
159 | 291 | } | ||
160 | 292 | |||
161 | 293 | nih_debug ("Connected to notified D-Bus bus"); | ||
162 | 294 | } else { | ||
163 | 295 | conn = nih_dbus_bus (use_session_bus ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, | ||
164 | 296 | control_disconnected); | ||
165 | 297 | if (! conn) | ||
166 | 298 | return -1; | ||
167 | 299 | |||
168 | 300 | nih_debug ("Connected to D-Bus %s bus", | ||
169 | 301 | dbus_bus_type == DBUS_BUS_SESSION | ||
170 | 302 | ? "session" : "system"); | ||
171 | 303 | } | ||
172 | 270 | 304 | ||
173 | 271 | /* Register objects on the bus. */ | 305 | /* Register objects on the bus. */ |
174 | 272 | control_register_all (conn); | 306 | control_register_all (conn); |
175 | @@ -275,7 +309,6 @@ | |||
176 | 275 | * appears on the bus, clients can assume we're ready to talk to | 309 | * appears on the bus, clients can assume we're ready to talk to |
177 | 276 | * them. | 310 | * them. |
178 | 277 | */ | 311 | */ |
179 | 278 | dbus_error_init (&error); | ||
180 | 279 | ret = dbus_bus_request_name (conn, DBUS_SERVICE_UPSTART, | 312 | ret = dbus_bus_request_name (conn, DBUS_SERVICE_UPSTART, |
181 | 280 | DBUS_NAME_FLAG_DO_NOT_QUEUE, &error); | 313 | DBUS_NAME_FLAG_DO_NOT_QUEUE, &error); |
182 | 281 | if (ret < 0) { | 314 | if (ret < 0) { |
183 | @@ -345,7 +378,13 @@ | |||
184 | 345 | 378 | ||
185 | 346 | dbus_error_init (&error); | 379 | dbus_error_init (&error); |
186 | 347 | 380 | ||
188 | 348 | nih_warn (_("Disconnected from system bus")); | 381 | if (user_mode && control_bus_address) { |
189 | 382 | nih_warn (_("Disconnected from notified D-Bus bus")); | ||
190 | 383 | } else { | ||
191 | 384 | nih_warn (_("Disconnected from D-Bus %s bus"), | ||
192 | 385 | dbus_bus_type == DBUS_BUS_SESSION | ||
193 | 386 | ? "session" : "system"); | ||
194 | 387 | } | ||
195 | 349 | 388 | ||
196 | 350 | control_bus = NULL; | 389 | control_bus = NULL; |
197 | 351 | } | 390 | } |
198 | @@ -817,19 +856,20 @@ | |||
199 | 817 | } | 856 | } |
200 | 818 | 857 | ||
201 | 819 | /** | 858 | /** |
203 | 820 | * control_handle_bus_type: | 859 | * control_get_bus_type: |
204 | 821 | * | 860 | * |
205 | 822 | * Determine D-Bus bus type to connect to. | 861 | * Determine D-Bus bus type to connect to. |
206 | 862 | * | ||
207 | 863 | * Returns: Type of D-Bus bus to connect to. | ||
208 | 823 | **/ | 864 | **/ |
211 | 824 | void | 865 | DBusBusType |
212 | 825 | control_handle_bus_type (void) | 866 | control_get_bus_type (void) |
213 | 826 | { | 867 | { |
216 | 827 | if (getenv (USE_SESSION_BUS_ENV)) | 868 | return (use_session_bus || user_mode) |
217 | 828 | use_session_bus = TRUE; | 869 | ? DBUS_BUS_SESSION |
218 | 870 | : DBUS_BUS_SYSTEM; | ||
219 | 871 | } | ||
220 | 829 | 872 | ||
221 | 830 | if (use_session_bus) | ||
222 | 831 | nih_debug ("Using session bus"); | ||
223 | 832 | } | ||
224 | 833 | /** | 873 | /** |
225 | 834 | * control_notify_disk_writeable: | 874 | * control_notify_disk_writeable: |
226 | 835 | * @data: not used, | 875 | * @data: not used, |
227 | @@ -882,6 +922,59 @@ | |||
228 | 882 | } | 922 | } |
229 | 883 | 923 | ||
230 | 884 | /** | 924 | /** |
231 | 925 | * control_notify_dbus_address: | ||
232 | 926 | * @data: not used, | ||
233 | 927 | * @message: D-Bus connection and message received, | ||
234 | 928 | * @address: Address of D-Bus to connect to. | ||
235 | 929 | * | ||
236 | 930 | * Implements the NotifyDBusAddress method of the | ||
237 | 931 | * com.ubuntu.Upstart interface. | ||
238 | 932 | * | ||
239 | 933 | * Called to allow the Session Init to connect to the D-Bus | ||
240 | 934 | * Session Bus when available. | ||
241 | 935 | * | ||
242 | 936 | * Returns: zero on success, negative value on raised error. | ||
243 | 937 | **/ | ||
244 | 938 | int | ||
245 | 939 | control_notify_dbus_address (void *data, | ||
246 | 940 | NihDBusMessage *message, | ||
247 | 941 | const char *address) | ||
248 | 942 | { | ||
249 | 943 | nih_assert (message); | ||
250 | 944 | nih_assert (address); | ||
251 | 945 | |||
252 | 946 | if (getpid () == 1) { | ||
253 | 947 | nih_dbus_error_raise_printf ( | ||
254 | 948 | DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", | ||
255 | 949 | _("Not permissible to notify D-Bus address for PID 1")); | ||
256 | 950 | return -1; | ||
257 | 951 | } | ||
258 | 952 | |||
259 | 953 | if (! control_check_permission (message)) { | ||
260 | 954 | nih_dbus_error_raise_printf ( | ||
261 | 955 | DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", | ||
262 | 956 | _("You do not have permission to notify D-Bus address")); | ||
263 | 957 | return -1; | ||
264 | 958 | } | ||
265 | 959 | |||
266 | 960 | /* Ignore as already connected */ | ||
267 | 961 | if (control_bus) | ||
268 | 962 | return 0; | ||
269 | 963 | |||
270 | 964 | control_bus_address = nih_strdup (NULL, address); | ||
271 | 965 | if (! control_bus_address) { | ||
272 | 966 | nih_dbus_error_raise_printf (DBUS_ERROR_NO_MEMORY, | ||
273 | 967 | _("Out of Memory")); | ||
274 | 968 | return -1; | ||
275 | 969 | } | ||
276 | 970 | |||
277 | 971 | if (control_bus_open () < 0) | ||
278 | 972 | return -1; | ||
279 | 973 | |||
280 | 974 | return 0; | ||
281 | 975 | } | ||
282 | 976 | |||
283 | 977 | /** | ||
284 | 885 | * control_bus_flush: | 978 | * control_bus_flush: |
285 | 886 | * | 979 | * |
286 | 887 | * Drain any remaining messages in the D-Bus queue. | 980 | * Drain any remaining messages in the D-Bus queue. |
287 | 888 | 981 | ||
288 | === modified file 'init/control.h' | |||
289 | --- init/control.h 2013-05-08 16:21:08 +0000 | |||
290 | +++ init/control.h 2013-11-04 11:44:32 +0000 | |||
291 | @@ -134,7 +134,8 @@ | |||
292 | 134 | const char *log_priority) | 134 | const char *log_priority) |
293 | 135 | __attribute__ ((warn_unused_result)); | 135 | __attribute__ ((warn_unused_result)); |
294 | 136 | 136 | ||
296 | 137 | void control_handle_bus_type (void); | 137 | DBusBusType control_get_bus_type (void) |
297 | 138 | __attribute__ ((warn_unused_result)); | ||
298 | 138 | 139 | ||
299 | 139 | void control_prepare_reexec (void); | 140 | void control_prepare_reexec (void); |
300 | 140 | 141 | ||
301 | @@ -157,8 +158,18 @@ | |||
302 | 157 | __attribute__ ((warn_unused_result)); | 158 | __attribute__ ((warn_unused_result)); |
303 | 158 | 159 | ||
304 | 159 | void control_notify_event_emitted (Event *event); | 160 | void control_notify_event_emitted (Event *event); |
305 | 161 | |||
306 | 160 | void control_notify_restarted (void); | 162 | void control_notify_restarted (void); |
307 | 161 | 163 | ||
308 | 164 | int control_notify_disk_writeable (void *data, | ||
309 | 165 | NihDBusMessage *message) | ||
310 | 166 | __attribute__ ((warn_unused_result)); | ||
311 | 167 | |||
312 | 168 | int control_notify_dbus_address (void *data, | ||
313 | 169 | NihDBusMessage *message, | ||
314 | 170 | const char *address) | ||
315 | 171 | __attribute__ ((warn_unused_result)); | ||
316 | 172 | |||
317 | 162 | int control_set_env (void *data, | 173 | int control_set_env (void *data, |
318 | 163 | NihDBusMessage *message, | 174 | NihDBusMessage *message, |
319 | 164 | char * const *job_details, | 175 | char * const *job_details, |
320 | 165 | 176 | ||
321 | === modified file 'init/main.c' | |||
322 | --- init/main.c 2013-11-03 02:56:57 +0000 | |||
323 | +++ init/main.c 2013-11-04 11:44:32 +0000 | |||
324 | @@ -128,6 +128,7 @@ | |||
325 | 128 | extern int default_console; | 128 | extern int default_console; |
326 | 129 | extern int write_state_file; | 129 | extern int write_state_file; |
327 | 130 | extern char *log_dir; | 130 | extern char *log_dir; |
328 | 131 | extern DBusBusType dbus_bus_type; | ||
329 | 131 | extern mode_t initial_umask; | 132 | extern mode_t initial_umask; |
330 | 132 | 133 | ||
331 | 133 | /** | 134 | /** |
332 | @@ -213,7 +214,8 @@ | |||
333 | 213 | if (disable_job_logging) | 214 | if (disable_job_logging) |
334 | 214 | nih_debug ("Job logging disabled"); | 215 | nih_debug ("Job logging disabled"); |
335 | 215 | 216 | ||
337 | 216 | control_handle_bus_type (); | 217 | if (getenv (USE_SESSION_BUS_ENV)) |
338 | 218 | use_session_bus = TRUE; | ||
339 | 217 | 219 | ||
340 | 218 | if (! user_mode) | 220 | if (! user_mode) |
341 | 219 | no_inherit_env = TRUE; | 221 | no_inherit_env = TRUE; |
342 | @@ -447,9 +449,14 @@ | |||
343 | 447 | nih_signal_set_handler (SIGHUP, nih_signal_handler); | 449 | nih_signal_set_handler (SIGHUP, nih_signal_handler); |
344 | 448 | NIH_MUST (nih_signal_add_handler (NULL, SIGHUP, hup_handler, NULL)); | 450 | NIH_MUST (nih_signal_add_handler (NULL, SIGHUP, hup_handler, NULL)); |
345 | 449 | 451 | ||
349 | 450 | /* SIGUSR1 instructs us to reconnect to D-Bus */ | 452 | /* Session Inits only reconnect to D-Bus when notified |
350 | 451 | nih_signal_set_handler (SIGUSR1, nih_signal_handler); | 453 | * via their private socket. |
351 | 452 | NIH_MUST (nih_signal_add_handler (NULL, SIGUSR1, usr1_handler, NULL)); | 454 | */ |
352 | 455 | if (! user_mode) { | ||
353 | 456 | /* SIGUSR1 instructs us to reconnect to D-Bus */ | ||
354 | 457 | nih_signal_set_handler (SIGUSR1, nih_signal_handler); | ||
355 | 458 | NIH_MUST (nih_signal_add_handler (NULL, SIGUSR1, usr1_handler, NULL)); | ||
356 | 459 | } | ||
357 | 453 | 460 | ||
358 | 454 | /* SIGTERM instructs us to re-exec ourselves when running as PID | 461 | /* SIGTERM instructs us to re-exec ourselves when running as PID |
359 | 455 | * 1, or to exit when running as a Session Init; this signal should | 462 | * 1, or to exit when running as a Session Init; this signal should |
360 | @@ -941,15 +948,23 @@ | |||
361 | 941 | usr1_handler (void *data, | 948 | usr1_handler (void *data, |
362 | 942 | NihSignal *signal) | 949 | NihSignal *signal) |
363 | 943 | { | 950 | { |
364 | 951 | nih_assert (! user_mode); | ||
365 | 952 | |||
366 | 944 | if (! control_bus) { | 953 | if (! control_bus) { |
368 | 945 | nih_info (_("Reconnecting to system bus")); | 954 | char *dbus_bus_name; |
369 | 955 | |||
370 | 956 | dbus_bus_name = dbus_bus_type == DBUS_BUS_SESSION | ||
371 | 957 | ? "session" : "system"; | ||
372 | 958 | |||
373 | 959 | nih_info (_("Reconnecting to D-Bus %s bus"), | ||
374 | 960 | dbus_bus_name); | ||
375 | 946 | 961 | ||
376 | 947 | if (control_bus_open () < 0) { | 962 | if (control_bus_open () < 0) { |
377 | 948 | NihError *err; | 963 | NihError *err; |
378 | 949 | 964 | ||
379 | 950 | err = nih_error_get (); | 965 | err = nih_error_get (); |
382 | 951 | nih_warn ("%s: %s", _("Unable to connect to the system bus"), | 966 | nih_warn (_("Unable to connect to the D-Bus %s bus: %s"), |
383 | 952 | err->message); | 967 | dbus_bus_name, err->message); |
384 | 953 | nih_free (err); | 968 | nih_free (err); |
385 | 954 | } | 969 | } |
386 | 955 | } | 970 | } |
387 | 956 | 971 | ||
388 | === modified file 'init/tests/test_control.c' | |||
389 | --- init/tests/test_control.c 2012-09-09 21:27:24 +0000 | |||
390 | +++ init/tests/test_control.c 2013-11-04 11:44:32 +0000 | |||
391 | @@ -821,7 +821,7 @@ | |||
392 | 821 | 821 | ||
393 | 822 | TEST_LIST_EMPTY (control_conns); | 822 | TEST_LIST_EMPTY (control_conns); |
394 | 823 | 823 | ||
396 | 824 | TEST_FILE_EQ (output, "test: Disconnected from system bus\n"); | 824 | TEST_FILE_EQ (output, "test: Disconnected from D-Bus system bus\n"); |
397 | 825 | TEST_FILE_END (output); | 825 | TEST_FILE_END (output); |
398 | 826 | TEST_FILE_RESET (output); | 826 | TEST_FILE_RESET (output); |
399 | 827 | 827 | ||
400 | @@ -879,7 +879,7 @@ | |||
401 | 879 | 879 | ||
402 | 880 | TEST_LIST_EMPTY (control_conns); | 880 | TEST_LIST_EMPTY (control_conns); |
403 | 881 | 881 | ||
405 | 882 | TEST_FILE_EQ (output, "test: Disconnected from system bus\n"); | 882 | TEST_FILE_EQ (output, "test: Disconnected from D-Bus system bus\n"); |
406 | 883 | TEST_FILE_END (output); | 883 | TEST_FILE_END (output); |
407 | 884 | TEST_FILE_RESET (output); | 884 | TEST_FILE_RESET (output); |
408 | 885 | 885 | ||
409 | 886 | 886 | ||
410 | === modified file 'util/initctl.c' | |||
411 | --- util/initctl.c 2013-07-21 23:54:16 +0000 | |||
412 | +++ util/initctl.c 2013-11-04 11:44:32 +0000 | |||
413 | @@ -342,8 +342,7 @@ | |||
414 | 342 | use_dbus = getuid () ? TRUE : FALSE; | 342 | use_dbus = getuid () ? TRUE : FALSE; |
415 | 343 | if (use_dbus >= 0 && dbus_bus_type < 0) | 343 | if (use_dbus >= 0 && dbus_bus_type < 0) |
416 | 344 | dbus_bus_type = DBUS_BUS_SYSTEM; | 344 | dbus_bus_type = DBUS_BUS_SYSTEM; |
419 | 345 | } | 345 | } else { |
418 | 346 | else { | ||
420 | 347 | if (! user_addr) { | 346 | if (! user_addr) { |
421 | 348 | nih_error ("UPSTART_SESSION isn't set in the environment. " | 347 | nih_error ("UPSTART_SESSION isn't set in the environment. " |
422 | 349 | "Unable to locate the Upstart instance."); | 348 | "Unable to locate the Upstart instance."); |
423 | @@ -353,7 +352,6 @@ | |||
424 | 353 | use_dbus = FALSE; | 352 | use_dbus = FALSE; |
425 | 354 | } | 353 | } |
426 | 355 | 354 | ||
427 | 356 | |||
428 | 357 | dbus_error_init (&dbus_error); | 355 | dbus_error_init (&dbus_error); |
429 | 358 | if (use_dbus) { | 356 | if (use_dbus) { |
430 | 359 | if (! dest_name) | 357 | if (! dest_name) |
431 | @@ -387,6 +385,7 @@ | |||
432 | 387 | return NULL; | 385 | return NULL; |
433 | 388 | } | 386 | } |
434 | 389 | } | 387 | } |
435 | 388 | |||
436 | 390 | dbus_error_free (&dbus_error); | 389 | dbus_error_free (&dbus_error); |
437 | 391 | 390 | ||
438 | 392 | upstart = nih_dbus_proxy_new (parent, connection, | 391 | upstart = nih_dbus_proxy_new (parent, connection, |
439 | @@ -1987,6 +1986,51 @@ | |||
440 | 1987 | 1986 | ||
441 | 1988 | 1987 | ||
442 | 1989 | /** | 1988 | /** |
443 | 1989 | * notify_dbus_address_action: | ||
444 | 1990 | * @command: NihCommand invoked, | ||
445 | 1991 | * @args: command-line arguments. | ||
446 | 1992 | * | ||
447 | 1993 | * This function is called for the "notify-dbus-address" command. | ||
448 | 1994 | * | ||
449 | 1995 | * Returns: command exit status. | ||
450 | 1996 | **/ | ||
451 | 1997 | int | ||
452 | 1998 | notify_dbus_address_action (NihCommand *command, | ||
453 | 1999 | char * const *args) | ||
454 | 2000 | { | ||
455 | 2001 | nih_local NihDBusProxy *upstart = NULL; | ||
456 | 2002 | NihError *err; | ||
457 | 2003 | char *address = NULL; | ||
458 | 2004 | |||
459 | 2005 | nih_assert (command != NULL); | ||
460 | 2006 | nih_assert (args != NULL); | ||
461 | 2007 | |||
462 | 2008 | if (! args[0]) { | ||
463 | 2009 | fprintf (stderr, _("%s: missing D-Bus address\n"), program_name); | ||
464 | 2010 | nih_main_suggest_help (); | ||
465 | 2011 | return 1; | ||
466 | 2012 | } | ||
467 | 2013 | |||
468 | 2014 | address = args[0]; | ||
469 | 2015 | |||
470 | 2016 | upstart = upstart_open (NULL); | ||
471 | 2017 | if (! upstart) | ||
472 | 2018 | return 1; | ||
473 | 2019 | |||
474 | 2020 | if (upstart_notify_dbus_address_sync (NULL, upstart, address) < 0) | ||
475 | 2021 | goto error; | ||
476 | 2022 | |||
477 | 2023 | return 0; | ||
478 | 2024 | |||
479 | 2025 | error: | ||
480 | 2026 | err = nih_error_get (); | ||
481 | 2027 | nih_error ("%s", err->message); | ||
482 | 2028 | nih_free (err); | ||
483 | 2029 | |||
484 | 2030 | return 1; | ||
485 | 2031 | } | ||
486 | 2032 | |||
487 | 2033 | /** | ||
488 | 1990 | * list_sessions_action: | 2034 | * list_sessions_action: |
489 | 1991 | * @command: NihCommand invoked, | 2035 | * @command: NihCommand invoked, |
490 | 1992 | * @args: command-line arguments. | 2036 | * @args: command-line arguments. |
491 | @@ -2827,7 +2871,7 @@ | |||
492 | 2827 | * Command-line options accepted for all arguments. | 2871 | * Command-line options accepted for all arguments. |
493 | 2828 | **/ | 2872 | **/ |
494 | 2829 | static NihOption options[] = { | 2873 | static NihOption options[] = { |
496 | 2830 | { 0, "session", N_("use D-Bus session bus to connect to init daemon (for testing)"), | 2874 | { 0, "session", N_("use existing D-Bus session bus to connect to init daemon (for testing)"), |
497 | 2831 | NULL, NULL, NULL, dbus_bus_type_setter }, | 2875 | NULL, NULL, NULL, dbus_bus_type_setter }, |
498 | 2832 | { 0, "system", N_("use D-Bus system bus to connect to init daemon"), | 2876 | { 0, "system", N_("use D-Bus system bus to connect to init daemon"), |
499 | 2833 | NULL, NULL, NULL, dbus_bus_type_setter }, | 2877 | NULL, NULL, NULL, dbus_bus_type_setter }, |
500 | @@ -3193,6 +3237,11 @@ | |||
501 | 3193 | N_("JOB is the name of the job which usage is to be shown.\n" ), | 3237 | N_("JOB is the name of the job which usage is to be shown.\n" ), |
502 | 3194 | NULL, usage_options, usage_action }, | 3238 | NULL, usage_options, usage_action }, |
503 | 3195 | 3239 | ||
504 | 3240 | { "notify-dbus-address", NULL, | ||
505 | 3241 | N_("Inform Upstart of D-Bus address to connect to."), | ||
506 | 3242 | N_("Run to allow Upstart to provide services over D-Bus."), | ||
507 | 3243 | NULL, NULL, notify_dbus_address_action}, | ||
508 | 3244 | |||
509 | 3196 | { "notify-disk-writeable", NULL, | 3245 | { "notify-disk-writeable", NULL, |
510 | 3197 | N_("Inform Upstart that disk is now writeable."), | 3246 | N_("Inform Upstart that disk is now writeable."), |
511 | 3198 | N_("Run to ensure output from jobs ending before " | 3247 | N_("Run to ensure output from jobs ending before " |
512 | 3199 | 3248 | ||
513 | === modified file 'util/man/initctl.8' | |||
514 | --- util/man/initctl.8 2013-05-31 15:41:20 +0000 | |||
515 | +++ util/man/initctl.8 2013-11-04 11:44:32 +0000 | |||
516 | @@ -42,14 +42,19 @@ | |||
517 | 42 | .B \-\-user | 42 | .B \-\-user |
518 | 43 | User mode. In this mode, initctl will talk to the | 43 | User mode. In this mode, initctl will talk to the |
519 | 44 | .BR init (8) | 44 | .BR init (8) |
521 | 45 | daemon using the D\-Bus private socket defined in the UPSTART_SESSION | 45 | daemon using the D\-Bus private socket defined in the |
522 | 46 | .B UPSTART_SESSION | ||
523 | 46 | environment variable. | 47 | environment variable. |
524 | 48 | |||
525 | 49 | Note that if the | ||
526 | 50 | .B UPSTART_SESSION | ||
527 | 51 | variable is defined, this option is implied. | ||
528 | 47 | .\" | 52 | .\" |
529 | 48 | .TP | 53 | .TP |
530 | 49 | .B \-\-session | 54 | .B \-\-session |
531 | 50 | Connect to | 55 | Connect to |
532 | 51 | .BR init (8) | 56 | .BR init (8) |
534 | 52 | daemon using the D\-Bus session bus (for testing purposes only). | 57 | daemon using the existing D\-Bus session bus (for testing purposes only). |
535 | 53 | .\" | 58 | .\" |
536 | 54 | .TP | 59 | .TP |
537 | 55 | .B \-\-system | 60 | .B \-\-system |
538 | @@ -555,6 +560,18 @@ | |||
539 | 555 | .RE | 560 | .RE |
540 | 556 | .\" | 561 | .\" |
541 | 557 | .TP | 562 | .TP |
542 | 563 | .B notify\-dbus\-address | ||
543 | 564 | Notify the | ||
544 | 565 | .BR init (8) | ||
545 | 566 | daemon of the D\-Bus address it should use to connect to. | ||
546 | 567 | |||
547 | 568 | This command is only permitted when running in | ||
548 | 569 | .B User Session Mode. | ||
549 | 570 | See | ||
550 | 571 | .BR init (5) | ||
551 | 572 | for further details. | ||
552 | 573 | .\" | ||
553 | 574 | .TP | ||
554 | 558 | .B list\-env | 575 | .B list\-env |
555 | 559 | .RI [ OPTIONS "] | 576 | .RI [ OPTIONS "] |
556 | 560 | 577 | ||
557 | @@ -608,7 +625,7 @@ | |||
558 | 608 | Adds or updates a variable in a job environment table. Variables set | 625 | Adds or updates a variable in a job environment table. Variables set |
559 | 609 | in this way will apply to all subsequently-starting jobs. | 626 | in this way will apply to all subsequently-starting jobs. |
560 | 610 | 627 | ||
562 | 611 | This command is only permitted When running in | 628 | This command is only permitted when running in |
563 | 612 | .B User Session Mode. | 629 | .B User Session Mode. |
564 | 613 | See | 630 | See |
565 | 614 | .BR init (5) | 631 | .BR init (5) |
566 | @@ -640,7 +657,7 @@ | |||
567 | 640 | Remove the specified variable from a job environment table. If the | 657 | Remove the specified variable from a job environment table. If the |
568 | 641 | variable does not already exist in the table, no change will be made. | 658 | variable does not already exist in the table, no change will be made. |
569 | 642 | 659 | ||
571 | 643 | This command is only permitted When running in | 660 | This command is only permitted when running in |
572 | 644 | .B User Session Mode. | 661 | .B User Session Mode. |
573 | 645 | See | 662 | See |
574 | 646 | .BR init (5) | 663 | .BR init (5) |
575 | @@ -667,12 +684,12 @@ | |||
576 | 667 | .\" | 684 | .\" |
577 | 668 | .TP | 685 | .TP |
578 | 669 | .B reset\-env | 686 | .B reset\-env |
580 | 670 | .R [ OPTIONS ] | 687 | .RI [ OPTIONS ] |
581 | 671 | 688 | ||
582 | 672 | Discards all changes make to a job environment table, setting it back | 689 | Discards all changes make to a job environment table, setting it back |
583 | 673 | to its default set of variables and values. | 690 | to its default set of variables and values. |
584 | 674 | 691 | ||
586 | 675 | This command is only permitted When running in | 692 | This command is only permitted when running in |
587 | 676 | .B User Session Mode. | 693 | .B User Session Mode. |
588 | 677 | See | 694 | See |
589 | 678 | .BR init (5) | 695 | .BR init (5) |
590 | 679 | 696 | ||
591 | === modified file 'util/tests/test_initctl.c' | |||
592 | --- util/tests/test_initctl.c 2013-10-18 09:13:36 +0000 | |||
593 | +++ util/tests/test_initctl.c 2013-11-04 11:44:32 +0000 | |||
594 | @@ -16790,6 +16790,215 @@ | |||
595 | 16790 | TEST_EQ (rmdir (logdir), 0); | 16790 | TEST_EQ (rmdir (logdir), 0); |
596 | 16791 | } | 16791 | } |
597 | 16792 | 16792 | ||
598 | 16793 | void | ||
599 | 16794 | test_dbus_connection (void) | ||
600 | 16795 | { | ||
601 | 16796 | size_t lines; | ||
602 | 16797 | pid_t dbus_pid = 0; | ||
603 | 16798 | pid_t dbus_pid2 = 0; | ||
604 | 16799 | pid_t upstart_pid = 0; | ||
605 | 16800 | nih_local char *cmd = NULL; | ||
606 | 16801 | char **output; | ||
607 | 16802 | nih_local char *dbus_session_address = NULL; | ||
608 | 16803 | nih_local char *dbus_session_address2 = NULL; | ||
609 | 16804 | nih_local char *upstart_session = NULL; | ||
610 | 16805 | char *address; | ||
611 | 16806 | |||
612 | 16807 | TEST_GROUP ("D-Bus connection"); | ||
613 | 16808 | |||
614 | 16809 | /*********************************************************************/ | ||
615 | 16810 | TEST_FEATURE ("ensure non-priv non-Session Init connects to D-Bus session bus on startup"); | ||
616 | 16811 | |||
617 | 16812 | /* Start a dbus-daemon */ | ||
618 | 16813 | TEST_DBUS (dbus_pid); | ||
619 | 16814 | |||
620 | 16815 | /* Not required */ | ||
621 | 16816 | assert0 (unsetenv ("DBUS_SYSTEM_BUS_ADDRESS")); | ||
622 | 16817 | |||
623 | 16818 | TEST_TRUE (getenv ("DBUS_SESSION_BUS_ADDRESS")); | ||
624 | 16819 | |||
625 | 16820 | START_UPSTART (upstart_pid, FALSE); | ||
626 | 16821 | |||
627 | 16822 | cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ()); | ||
628 | 16823 | TEST_NE_P (cmd, NULL); | ||
629 | 16824 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
630 | 16825 | TEST_EQ (lines, 1); | ||
631 | 16826 | TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*"); | ||
632 | 16827 | nih_free (output); | ||
633 | 16828 | |||
634 | 16829 | STOP_UPSTART (upstart_pid); | ||
635 | 16830 | TEST_DBUS_END (dbus_pid); | ||
636 | 16831 | |||
637 | 16832 | /*********************************************************************/ | ||
638 | 16833 | TEST_FEATURE ("ensure Session Init does not connect to D-Bus session bus on startup"); | ||
639 | 16834 | |||
640 | 16835 | /* Start a dbus-daemon */ | ||
641 | 16836 | TEST_DBUS (dbus_pid); | ||
642 | 16837 | |||
643 | 16838 | /* Not required */ | ||
644 | 16839 | assert0 (unsetenv ("DBUS_SYSTEM_BUS_ADDRESS")); | ||
645 | 16840 | |||
646 | 16841 | TEST_TRUE (getenv ("DBUS_SESSION_BUS_ADDRESS")); | ||
647 | 16842 | |||
648 | 16843 | START_UPSTART (upstart_pid, TRUE); | ||
649 | 16844 | |||
650 | 16845 | address = getenv ("DBUS_SESSION_BUS_ADDRESS"); | ||
651 | 16846 | TEST_NE_P (address, NULL); | ||
652 | 16847 | dbus_session_address = nih_strdup (NULL, address); | ||
653 | 16848 | TEST_NE_P (dbus_session_address, NULL); | ||
654 | 16849 | |||
655 | 16850 | /* Stop initctl using this route */ | ||
656 | 16851 | assert0 (unsetenv ("DBUS_SESSION_BUS_ADDRESS")); | ||
657 | 16852 | |||
658 | 16853 | /* Check we can query the version via the private socket */ | ||
659 | 16854 | cmd = nih_sprintf (NULL, "%s version 2>&1", get_initctl_binary ()); | ||
660 | 16855 | TEST_NE_P (cmd, NULL); | ||
661 | 16856 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
662 | 16857 | TEST_EQ (lines, 1); | ||
663 | 16858 | TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*"); | ||
664 | 16859 | nih_free (output); | ||
665 | 16860 | |||
666 | 16861 | /* Unset to stop initctl finding upstart via this route */ | ||
667 | 16862 | assert0 (unsetenv ("UPSTART_SESSION")); | ||
668 | 16863 | |||
669 | 16864 | /* Re-apply in the test environment */ | ||
670 | 16865 | assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_session_address, 1)); | ||
671 | 16866 | |||
672 | 16867 | /* Although there is a D-Bus session bus available, the Session | ||
673 | 16868 | * Init should not connect to it. Check this by trying to query | ||
674 | 16869 | * the running version via the D-Bus session bus. | ||
675 | 16870 | */ | ||
676 | 16871 | cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ()); | ||
677 | 16872 | TEST_NE_P (cmd, NULL); | ||
678 | 16873 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
679 | 16874 | TEST_EQ (lines, 1); | ||
680 | 16875 | TEST_STR_MATCH (output[0], "initctl: Name \"com.ubuntu.Upstart\" does not exist*"); | ||
681 | 16876 | nih_free (output); | ||
682 | 16877 | |||
683 | 16878 | STOP_UPSTART (upstart_pid); | ||
684 | 16879 | TEST_DBUS_END (dbus_pid); | ||
685 | 16880 | |||
686 | 16881 | /*********************************************************************/ | ||
687 | 16882 | TEST_FEATURE ("ensure Session Init connects to D-Bus session bus when notified"); | ||
688 | 16883 | |||
689 | 16884 | /* Start a dbus-daemon */ | ||
690 | 16885 | TEST_DBUS (dbus_pid); | ||
691 | 16886 | |||
692 | 16887 | address = getenv ("DBUS_SESSION_BUS_ADDRESS"); | ||
693 | 16888 | TEST_NE_P (address, NULL); | ||
694 | 16889 | dbus_session_address = nih_strdup (NULL, address); | ||
695 | 16890 | TEST_NE_P (dbus_session_address, NULL); | ||
696 | 16891 | |||
697 | 16892 | /* Not required */ | ||
698 | 16893 | assert0 (unsetenv ("DBUS_SYSTEM_BUS_ADDRESS")); | ||
699 | 16894 | assert0 (unsetenv ("DBUS_SESSION_BUS_ADDRESS")); | ||
700 | 16895 | |||
701 | 16896 | START_UPSTART (upstart_pid, TRUE); | ||
702 | 16897 | |||
703 | 16898 | /* Pass the D-Bus session bus address to the Session Init */ | ||
704 | 16899 | cmd = nih_sprintf (NULL, "%s notify-dbus-address \"%s\" 2>&1", | ||
705 | 16900 | get_initctl_binary (), dbus_session_address); | ||
706 | 16901 | TEST_NE_P (cmd, NULL); | ||
707 | 16902 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
708 | 16903 | TEST_EQ (lines, 0); | ||
709 | 16904 | |||
710 | 16905 | /* Re-apply in the test environment */ | ||
711 | 16906 | assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_session_address, 1)); | ||
712 | 16907 | |||
713 | 16908 | /* It should now be possible to query the running version via | ||
714 | 16909 | * the D-Bus session bus. | ||
715 | 16910 | */ | ||
716 | 16911 | cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ()); | ||
717 | 16912 | TEST_NE_P (cmd, NULL); | ||
718 | 16913 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
719 | 16914 | TEST_EQ (lines, 1); | ||
720 | 16915 | TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*"); | ||
721 | 16916 | nih_free (output); | ||
722 | 16917 | |||
723 | 16918 | STOP_UPSTART (upstart_pid); | ||
724 | 16919 | TEST_DBUS_END (dbus_pid); | ||
725 | 16920 | |||
726 | 16921 | /*********************************************************************/ | ||
727 | 16922 | TEST_FEATURE ("ensure Session Init does not connect to another bus when notified twice"); | ||
728 | 16923 | |||
729 | 16924 | /* Start first dbus-daemon */ | ||
730 | 16925 | TEST_DBUS (dbus_pid); | ||
731 | 16926 | |||
732 | 16927 | /* Save its address */ | ||
733 | 16928 | address = getenv ("DBUS_SESSION_BUS_ADDRESS"); | ||
734 | 16929 | TEST_NE_P (address, NULL); | ||
735 | 16930 | dbus_session_address = nih_strdup (NULL, address); | ||
736 | 16931 | TEST_NE_P (dbus_session_address, NULL); | ||
737 | 16932 | |||
738 | 16933 | /* Start second dbus-daemon */ | ||
739 | 16934 | TEST_DBUS (dbus_pid2); | ||
740 | 16935 | |||
741 | 16936 | /* Save its address */ | ||
742 | 16937 | address = getenv ("DBUS_SESSION_BUS_ADDRESS"); | ||
743 | 16938 | TEST_NE_P (address, NULL); | ||
744 | 16939 | dbus_session_address2 = nih_strdup (NULL, address); | ||
745 | 16940 | TEST_NE_P (dbus_session_address2, NULL); | ||
746 | 16941 | |||
747 | 16942 | assert0 (unsetenv ("DBUS_SYSTEM_BUS_ADDRESS")); | ||
748 | 16943 | assert0 (unsetenv ("DBUS_SESSION_BUS_ADDRESS")); | ||
749 | 16944 | |||
750 | 16945 | START_UPSTART (upstart_pid, TRUE); | ||
751 | 16946 | |||
752 | 16947 | /* Pass the first D-Bus session bus address to the Session Init */ | ||
753 | 16948 | cmd = nih_sprintf (NULL, "%s notify-dbus-address \"%s\" 2>&1", | ||
754 | 16949 | get_initctl_binary (), dbus_session_address); | ||
755 | 16950 | TEST_NE_P (cmd, NULL); | ||
756 | 16951 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
757 | 16952 | TEST_EQ (lines, 0); | ||
758 | 16953 | |||
759 | 16954 | /* Re-apply in the test environment */ | ||
760 | 16955 | assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_session_address, 1)); | ||
761 | 16956 | |||
762 | 16957 | /* It should now be possible to query the running version via | ||
763 | 16958 | * the D-Bus session bus. | ||
764 | 16959 | */ | ||
765 | 16960 | cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ()); | ||
766 | 16961 | TEST_NE_P (cmd, NULL); | ||
767 | 16962 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
768 | 16963 | TEST_EQ (lines, 1); | ||
769 | 16964 | TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*"); | ||
770 | 16965 | nih_free (output); | ||
771 | 16966 | |||
772 | 16967 | /* Pass the second D-Bus session bus address to the Session Init */ | ||
773 | 16968 | cmd = nih_sprintf (NULL, "%s notify-dbus-address \"%s\" 2>&1", | ||
774 | 16969 | get_initctl_binary (), dbus_session_address2); | ||
775 | 16970 | TEST_NE_P (cmd, NULL); | ||
776 | 16971 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
777 | 16972 | TEST_EQ (lines, 0); | ||
778 | 16973 | |||
779 | 16974 | /* Check that the Session Init still responds on the first address */ | ||
780 | 16975 | cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ()); | ||
781 | 16976 | TEST_NE_P (cmd, NULL); | ||
782 | 16977 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
783 | 16978 | TEST_EQ (lines, 1); | ||
784 | 16979 | TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*"); | ||
785 | 16980 | nih_free (output); | ||
786 | 16981 | |||
787 | 16982 | /* Stop the 1st daemon */ | ||
788 | 16983 | TEST_DBUS_END (dbus_pid); | ||
789 | 16984 | |||
790 | 16985 | /* Switch to the 2nd daemon */ | ||
791 | 16986 | assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_session_address2, 1)); | ||
792 | 16987 | |||
793 | 16988 | /* Ensure the Session Init isn't responding on this address */ | ||
794 | 16989 | cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ()); | ||
795 | 16990 | TEST_NE_P (cmd, NULL); | ||
796 | 16991 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
797 | 16992 | TEST_EQ (lines, 1); | ||
798 | 16993 | TEST_STR_MATCH (output[0], "initctl: Name \"com.ubuntu.Upstart\" does not exist*"); | ||
799 | 16994 | nih_free (output); | ||
800 | 16995 | |||
801 | 16996 | STOP_UPSTART (upstart_pid); | ||
802 | 16997 | |||
803 | 16998 | /* Stop the 2nd daemon */ | ||
804 | 16999 | TEST_DBUS_END (dbus_pid2); | ||
805 | 17000 | } | ||
806 | 17001 | |||
807 | 16793 | int | 17002 | int |
808 | 16794 | main (int argc, | 17003 | main (int argc, |
809 | 16795 | char *argv[]) | 17004 | char *argv[]) |
810 | @@ -16834,5 +17043,7 @@ | |||
811 | 16834 | test_notify_disk_writeable (); | 17043 | test_notify_disk_writeable (); |
812 | 16835 | } | 17044 | } |
813 | 16836 | 17045 | ||
814 | 17046 | test_dbus_connection (); | ||
815 | 17047 | |||
816 | 16837 | return 0; | 17048 | return 0; |
817 | 16838 | } | 17049 | } |
So we are adding a DBus API, to tell session init which session DBus to connect to, once and only once. This message will then be delivered via private socket. Yet this method will be exposed as public api over DBus, which will always do nothing. Will it be possible to publish method call NotifyDBusAddress over Private socket only? I guess it's a very minor point.
User-session init integration question, will it be expected for user-session dbus job to invoke initctl notify-dbus-address in post-start?
Other than that, works as advertised.