Merge lp:~jamesodhunt/upstart/bug-1235649 into lp:upstart

Proposed by James Hunt on 2013-10-25
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
Reviewer Review Type Date Requested Status
Dimitri John Ledkov 2013-10-25 Approve on 2013-11-04
Review via email: mp+192703@code.launchpad.net
To post a comment you must log in.
Dimitri John Ledkov (xnox) wrote :

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.

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_BUS_ADDRESS

Dimitri John Ledkov (xnox) :
review: Approve
lp:~jamesodhunt/upstart/bug-1235649 updated on 2013-11-04
1548. By James Hunt on 2013-11-04

* Sync with lp:upstart.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2013-11-03 02:56:57 +0000
+++ ChangeLog 2013-11-04 11:44:32 +0000
@@ -1,10 +1,3 @@
12013-10-25 Steve Langasek <steve.langasek@ubuntu.com>
2
3 * init/main.c, init/system.c, init/system.h: allow mount options
4 to be passed to system_mount(), and pass the right options when
5 mounting /dev/pts to match the permissions set by either
6 initramfs-tools or mountall. LP: #1244763.
7
82013-11-03 James Hunt <james.hunt@ubuntu.com>12013-11-03 James Hunt <james.hunt@ubuntu.com>
92
10 * init/job_class.c:3 * init/job_class.c:
@@ -59,6 +52,44 @@
59 * scripts/tests/test_pyupstart_session_init.py: Added file bridge tests52 * scripts/tests/test_pyupstart_session_init.py: Added file bridge tests
60 for directory creation, modification and deletion.53 for directory creation, modification and deletion.
6154
552013-10-25 James Hunt <james.hunt@ubuntu.com>
56
57 * dbus/com.ubuntu.Upstart.xml: Added 'NotifyDBusAddress' method.
58 * init/control.c:
59 - control_bus_open(): Connect to the D-Bus bus specified
60 by control_bus_address when running as a Session Init (LP: #1203595, #1235649).
61 - control_disconnected(): Display calculated bus type rather than hard-coding.
62 - control_handle_bus_type(): Removed.
63 - control_get_bus_type(): Determine type of D-Bus bus that will be used.
64 - control_notify_dbus_address(): Implementation of D-Bus 'NotifyDBusAddress' method
65 that sets control_bus_address.
66 * init/main.c:
67 - main():
68 - Just check USE_SESSION_BUS_ENV variable rather than calling
69 control_handle_bus_type().
70 - Don't register SIGUSR1 handler for Session Init.
71 - usr1_handler(): Display calculated bus type rather than hard-coding.
72 * init/test_control.c: Updated strings used by tests which check error
73 messages to include 'D-Bus'.
74 * util/initctl.c: Added new 'notify-dbus-address' command.
75 * util/man/initctl.8:
76 - Documentation for new 'notify-dbus-address' command.
77 - reset-env: Troff fix.
78 - Explain '--user' implicit in user mode.
79 * util/tests/test_initctl.c: test_dbus_connection(): New function providing
80 the following new tests:
81 - "ensure non-priv non-Session Init connects to D-Bus session bus on startup".
82 - "ensure Session Init does not connect to D-Bus session bus on startup".
83 - "ensure Session Init connects to D-Bus session bus when notified".
84 - "ensure Session Init does not connect to another bus when notified twice".
85
862013-10-25 Steve Langasek <steve.langasek@ubuntu.com>
87
88 * init/main.c, init/system.c, init/system.h: allow mount options
89 to be passed to system_mount(), and pass the right options when
90 mounting /dev/pts to match the permissions set by either
91 initramfs-tools or mountall. LP: #1244763.
92
622013-10-24 James Hunt <james.hunt@ubuntu.com>932013-10-24 James Hunt <james.hunt@ubuntu.com>
6394
64 * init/environ.c: Comment.95 * init/environ.c: Comment.
@@ -79,7 +110,7 @@
79110
802013-10-23 Dmitrijs Ledkovs <xnox@ubuntu.com>1112013-10-23 Dmitrijs Ledkovs <xnox@ubuntu.com>
81112
82 * extra/upstart-socket-bridge.c: use SOCKET_PATH in our event113 * extra/upstart-socket-bridge.c: use SOCKET_PATH in our event
83 environment, instead of clobbering PATH. (LP: #1235480)114 environment, instead of clobbering PATH. (LP: #1235480)
84115
852013-10-23 James Hunt <james.hunt@ubuntu.com>1162013-10-23 James Hunt <james.hunt@ubuntu.com>
86117
=== modified file 'dbus/com.ubuntu.Upstart.xml'
--- dbus/com.ubuntu.Upstart.xml 2013-02-08 16:15:23 +0000
+++ dbus/com.ubuntu.Upstart.xml 2013-11-04 11:44:32 +0000
@@ -103,6 +103,10 @@
103 <method name="NotifyDiskWriteable">103 <method name="NotifyDiskWriteable">
104 </method>104 </method>
105105
106 <method name="NotifyDBusAddress">
107 <arg name="address" type="s" direction="in" />
108 </method>
109
106 <method name="EndSession"/>110 <method name="EndSession"/>
107111
108 <!-- Basic information about Upstart -->112 <!-- Basic information about Upstart -->
109113
=== modified file 'init/control.c'
--- init/control.c 2013-04-22 10:30:09 +0000
+++ init/control.c 2013-11-04 11:44:32 +0000
@@ -81,11 +81,19 @@
81 *81 *
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.
83 *83 *
84 * Used for testing.84 * Used for testing to simulate (as far as possible) a system-like init
85 * when running as a non-priv user (but not as a Session Init).
85 **/86 **/
86int use_session_bus = FALSE;87int use_session_bus = FALSE;
8788
88/**89/**
90 * dbus_bus_type:
91 *
92 * Type of D-Bus bus to connect to.
93 **/
94DBusBusType dbus_bus_type;
95
96/**
89 * control_server_address:97 * control_server_address:
90 *98 *
91 * Address on which the control server may be reached.99 * Address on which the control server may be reached.
@@ -100,6 +108,13 @@
100DBusServer *control_server = NULL;108DBusServer *control_server = NULL;
101109
102/**110/**
111 * control_bus_address:
112 *
113 * Address on which the control bus may be reached.
114 **/
115char *control_bus_address = NULL;
116
117/**
103 * control_bus:118 * control_bus:
104 *119 *
105 * Open connection to a D-Bus bus. The connection may be opened with120 * Open connection to a D-Bus bus. The connection may be opened with
@@ -236,7 +251,6 @@
236 control_server = NULL;251 control_server = NULL;
237}252}
238253
239
240/**254/**
241 * control_bus_open:255 * control_bus_open:
242 *256 *
@@ -256,17 +270,37 @@
256270
257 nih_assert (control_bus == NULL);271 nih_assert (control_bus == NULL);
258272
273 dbus_error_init (&error);
274
259 control_init ();275 control_init ();
260276
261 control_handle_bus_type ();277 dbus_bus_type = control_get_bus_type ();
262278
263 /* Connect to the D-Bus System Bus and hook everything up into279 /* Connect to the appropriate D-Bus bus and hook everything up into
264 * our own main loop automatically.280 * our own main loop automatically.
265 */281 */
266 conn = nih_dbus_bus (use_session_bus ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM,282 if (user_mode && control_bus_address) {
267 control_disconnected);283 conn = nih_dbus_connect (control_bus_address, control_disconnected);
268 if (! conn)284 if (! conn)
269 return -1;285 return -1;
286
287 if (! dbus_bus_register (conn, &error)) {
288 nih_dbus_error_raise (error.name, error.message);
289 dbus_error_free (&error);
290 return -1;
291 }
292
293 nih_debug ("Connected to notified D-Bus bus");
294 } else {
295 conn = nih_dbus_bus (use_session_bus ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM,
296 control_disconnected);
297 if (! conn)
298 return -1;
299
300 nih_debug ("Connected to D-Bus %s bus",
301 dbus_bus_type == DBUS_BUS_SESSION
302 ? "session" : "system");
303 }
270304
271 /* Register objects on the bus. */305 /* Register objects on the bus. */
272 control_register_all (conn);306 control_register_all (conn);
@@ -275,7 +309,6 @@
275 * appears on the bus, clients can assume we're ready to talk to309 * appears on the bus, clients can assume we're ready to talk to
276 * them.310 * them.
277 */311 */
278 dbus_error_init (&error);
279 ret = dbus_bus_request_name (conn, DBUS_SERVICE_UPSTART,312 ret = dbus_bus_request_name (conn, DBUS_SERVICE_UPSTART,
280 DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);313 DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);
281 if (ret < 0) {314 if (ret < 0) {
@@ -345,7 +378,13 @@
345378
346 dbus_error_init (&error);379 dbus_error_init (&error);
347380
348 nih_warn (_("Disconnected from system bus"));381 if (user_mode && control_bus_address) {
382 nih_warn (_("Disconnected from notified D-Bus bus"));
383 } else {
384 nih_warn (_("Disconnected from D-Bus %s bus"),
385 dbus_bus_type == DBUS_BUS_SESSION
386 ? "session" : "system");
387 }
349388
350 control_bus = NULL;389 control_bus = NULL;
351 }390 }
@@ -817,19 +856,20 @@
817}856}
818857
819/**858/**
820 * control_handle_bus_type:859 * control_get_bus_type:
821 *860 *
822 * Determine D-Bus bus type to connect to.861 * Determine D-Bus bus type to connect to.
862 *
863 * Returns: Type of D-Bus bus to connect to.
823 **/864 **/
824void865DBusBusType
825control_handle_bus_type (void)866control_get_bus_type (void)
826{867{
827 if (getenv (USE_SESSION_BUS_ENV))868 return (use_session_bus || user_mode)
828 use_session_bus = TRUE;869 ? DBUS_BUS_SESSION
870 : DBUS_BUS_SYSTEM;
871}
829872
830 if (use_session_bus)
831 nih_debug ("Using session bus");
832}
833/**873/**
834 * control_notify_disk_writeable:874 * control_notify_disk_writeable:
835 * @data: not used,875 * @data: not used,
@@ -882,6 +922,59 @@
882}922}
883923
884/**924/**
925 * control_notify_dbus_address:
926 * @data: not used,
927 * @message: D-Bus connection and message received,
928 * @address: Address of D-Bus to connect to.
929 *
930 * Implements the NotifyDBusAddress method of the
931 * com.ubuntu.Upstart interface.
932 *
933 * Called to allow the Session Init to connect to the D-Bus
934 * Session Bus when available.
935 *
936 * Returns: zero on success, negative value on raised error.
937 **/
938int
939control_notify_dbus_address (void *data,
940 NihDBusMessage *message,
941 const char *address)
942{
943 nih_assert (message);
944 nih_assert (address);
945
946 if (getpid () == 1) {
947 nih_dbus_error_raise_printf (
948 DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
949 _("Not permissible to notify D-Bus address for PID 1"));
950 return -1;
951 }
952
953 if (! control_check_permission (message)) {
954 nih_dbus_error_raise_printf (
955 DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
956 _("You do not have permission to notify D-Bus address"));
957 return -1;
958 }
959
960 /* Ignore as already connected */
961 if (control_bus)
962 return 0;
963
964 control_bus_address = nih_strdup (NULL, address);
965 if (! control_bus_address) {
966 nih_dbus_error_raise_printf (DBUS_ERROR_NO_MEMORY,
967 _("Out of Memory"));
968 return -1;
969 }
970
971 if (control_bus_open () < 0)
972 return -1;
973
974 return 0;
975}
976
977/**
885 * control_bus_flush:978 * control_bus_flush:
886 *979 *
887 * Drain any remaining messages in the D-Bus queue.980 * Drain any remaining messages in the D-Bus queue.
888981
=== modified file 'init/control.h'
--- init/control.h 2013-05-08 16:21:08 +0000
+++ init/control.h 2013-11-04 11:44:32 +0000
@@ -134,7 +134,8 @@
134 const char *log_priority)134 const char *log_priority)
135 __attribute__ ((warn_unused_result));135 __attribute__ ((warn_unused_result));
136136
137void control_handle_bus_type (void);137DBusBusType control_get_bus_type (void)
138 __attribute__ ((warn_unused_result));
138139
139void control_prepare_reexec (void);140void control_prepare_reexec (void);
140141
@@ -157,8 +158,18 @@
157 __attribute__ ((warn_unused_result));158 __attribute__ ((warn_unused_result));
158159
159void control_notify_event_emitted (Event *event);160void control_notify_event_emitted (Event *event);
161
160void control_notify_restarted (void);162void control_notify_restarted (void);
161163
164int control_notify_disk_writeable (void *data,
165 NihDBusMessage *message)
166 __attribute__ ((warn_unused_result));
167
168int control_notify_dbus_address (void *data,
169 NihDBusMessage *message,
170 const char *address)
171 __attribute__ ((warn_unused_result));
172
162int control_set_env (void *data,173int control_set_env (void *data,
163 NihDBusMessage *message,174 NihDBusMessage *message,
164 char * const *job_details,175 char * const *job_details,
165176
=== modified file 'init/main.c'
--- init/main.c 2013-11-03 02:56:57 +0000
+++ init/main.c 2013-11-04 11:44:32 +0000
@@ -128,6 +128,7 @@
128extern int default_console;128extern int default_console;
129extern int write_state_file;129extern int write_state_file;
130extern char *log_dir;130extern char *log_dir;
131extern DBusBusType dbus_bus_type;
131extern mode_t initial_umask;132extern mode_t initial_umask;
132133
133/**134/**
@@ -213,7 +214,8 @@
213 if (disable_job_logging)214 if (disable_job_logging)
214 nih_debug ("Job logging disabled");215 nih_debug ("Job logging disabled");
215216
216 control_handle_bus_type ();217 if (getenv (USE_SESSION_BUS_ENV))
218 use_session_bus = TRUE;
217219
218 if (! user_mode)220 if (! user_mode)
219 no_inherit_env = TRUE;221 no_inherit_env = TRUE;
@@ -447,9 +449,14 @@
447 nih_signal_set_handler (SIGHUP, nih_signal_handler);449 nih_signal_set_handler (SIGHUP, nih_signal_handler);
448 NIH_MUST (nih_signal_add_handler (NULL, SIGHUP, hup_handler, NULL));450 NIH_MUST (nih_signal_add_handler (NULL, SIGHUP, hup_handler, NULL));
449451
450 /* SIGUSR1 instructs us to reconnect to D-Bus */452 /* Session Inits only reconnect to D-Bus when notified
451 nih_signal_set_handler (SIGUSR1, nih_signal_handler);453 * via their private socket.
452 NIH_MUST (nih_signal_add_handler (NULL, SIGUSR1, usr1_handler, NULL));454 */
455 if (! user_mode) {
456 /* SIGUSR1 instructs us to reconnect to D-Bus */
457 nih_signal_set_handler (SIGUSR1, nih_signal_handler);
458 NIH_MUST (nih_signal_add_handler (NULL, SIGUSR1, usr1_handler, NULL));
459 }
453460
454 /* SIGTERM instructs us to re-exec ourselves when running as PID461 /* SIGTERM instructs us to re-exec ourselves when running as PID
455 * 1, or to exit when running as a Session Init; this signal should462 * 1, or to exit when running as a Session Init; this signal should
@@ -941,15 +948,23 @@
941usr1_handler (void *data,948usr1_handler (void *data,
942 NihSignal *signal)949 NihSignal *signal)
943{950{
951 nih_assert (! user_mode);
952
944 if (! control_bus) {953 if (! control_bus) {
945 nih_info (_("Reconnecting to system bus"));954 char *dbus_bus_name;
955
956 dbus_bus_name = dbus_bus_type == DBUS_BUS_SESSION
957 ? "session" : "system";
958
959 nih_info (_("Reconnecting to D-Bus %s bus"),
960 dbus_bus_name);
946961
947 if (control_bus_open () < 0) {962 if (control_bus_open () < 0) {
948 NihError *err;963 NihError *err;
949964
950 err = nih_error_get ();965 err = nih_error_get ();
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"),
952 err->message);967 dbus_bus_name, err->message);
953 nih_free (err);968 nih_free (err);
954 }969 }
955 }970 }
956971
=== modified file 'init/tests/test_control.c'
--- init/tests/test_control.c 2012-09-09 21:27:24 +0000
+++ init/tests/test_control.c 2013-11-04 11:44:32 +0000
@@ -821,7 +821,7 @@
821821
822 TEST_LIST_EMPTY (control_conns);822 TEST_LIST_EMPTY (control_conns);
823823
824 TEST_FILE_EQ (output, "test: Disconnected from system bus\n");824 TEST_FILE_EQ (output, "test: Disconnected from D-Bus system bus\n");
825 TEST_FILE_END (output);825 TEST_FILE_END (output);
826 TEST_FILE_RESET (output);826 TEST_FILE_RESET (output);
827827
@@ -879,7 +879,7 @@
879879
880 TEST_LIST_EMPTY (control_conns);880 TEST_LIST_EMPTY (control_conns);
881881
882 TEST_FILE_EQ (output, "test: Disconnected from system bus\n");882 TEST_FILE_EQ (output, "test: Disconnected from D-Bus system bus\n");
883 TEST_FILE_END (output);883 TEST_FILE_END (output);
884 TEST_FILE_RESET (output);884 TEST_FILE_RESET (output);
885885
886886
=== modified file 'util/initctl.c'
--- util/initctl.c 2013-07-21 23:54:16 +0000
+++ util/initctl.c 2013-11-04 11:44:32 +0000
@@ -342,8 +342,7 @@
342 use_dbus = getuid () ? TRUE : FALSE;342 use_dbus = getuid () ? TRUE : FALSE;
343 if (use_dbus >= 0 && dbus_bus_type < 0)343 if (use_dbus >= 0 && dbus_bus_type < 0)
344 dbus_bus_type = DBUS_BUS_SYSTEM;344 dbus_bus_type = DBUS_BUS_SYSTEM;
345 }345 } else {
346 else {
347 if (! user_addr) {346 if (! user_addr) {
348 nih_error ("UPSTART_SESSION isn't set in the environment. "347 nih_error ("UPSTART_SESSION isn't set in the environment. "
349 "Unable to locate the Upstart instance.");348 "Unable to locate the Upstart instance.");
@@ -353,7 +352,6 @@
353 use_dbus = FALSE;352 use_dbus = FALSE;
354 }353 }
355354
356
357 dbus_error_init (&dbus_error);355 dbus_error_init (&dbus_error);
358 if (use_dbus) {356 if (use_dbus) {
359 if (! dest_name)357 if (! dest_name)
@@ -387,6 +385,7 @@
387 return NULL;385 return NULL;
388 }386 }
389 }387 }
388
390 dbus_error_free (&dbus_error);389 dbus_error_free (&dbus_error);
391390
392 upstart = nih_dbus_proxy_new (parent, connection,391 upstart = nih_dbus_proxy_new (parent, connection,
@@ -1987,6 +1986,51 @@
19871986
19881987
1989/**1988/**
1989 * notify_dbus_address_action:
1990 * @command: NihCommand invoked,
1991 * @args: command-line arguments.
1992 *
1993 * This function is called for the "notify-dbus-address" command.
1994 *
1995 * Returns: command exit status.
1996 **/
1997int
1998notify_dbus_address_action (NihCommand *command,
1999 char * const *args)
2000{
2001 nih_local NihDBusProxy *upstart = NULL;
2002 NihError *err;
2003 char *address = NULL;
2004
2005 nih_assert (command != NULL);
2006 nih_assert (args != NULL);
2007
2008 if (! args[0]) {
2009 fprintf (stderr, _("%s: missing D-Bus address\n"), program_name);
2010 nih_main_suggest_help ();
2011 return 1;
2012 }
2013
2014 address = args[0];
2015
2016 upstart = upstart_open (NULL);
2017 if (! upstart)
2018 return 1;
2019
2020 if (upstart_notify_dbus_address_sync (NULL, upstart, address) < 0)
2021 goto error;
2022
2023 return 0;
2024
2025error:
2026 err = nih_error_get ();
2027 nih_error ("%s", err->message);
2028 nih_free (err);
2029
2030 return 1;
2031}
2032
2033/**
1990 * list_sessions_action:2034 * list_sessions_action:
1991 * @command: NihCommand invoked,2035 * @command: NihCommand invoked,
1992 * @args: command-line arguments.2036 * @args: command-line arguments.
@@ -2827,7 +2871,7 @@
2827 * Command-line options accepted for all arguments.2871 * Command-line options accepted for all arguments.
2828 **/2872 **/
2829static NihOption options[] = {2873static NihOption options[] = {
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)"),
2831 NULL, NULL, NULL, dbus_bus_type_setter },2875 NULL, NULL, NULL, dbus_bus_type_setter },
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"),
2833 NULL, NULL, NULL, dbus_bus_type_setter },2877 NULL, NULL, NULL, dbus_bus_type_setter },
@@ -3193,6 +3237,11 @@
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" ),
3194 NULL, usage_options, usage_action },3238 NULL, usage_options, usage_action },
31953239
3240 { "notify-dbus-address", NULL,
3241 N_("Inform Upstart of D-Bus address to connect to."),
3242 N_("Run to allow Upstart to provide services over D-Bus."),
3243 NULL, NULL, notify_dbus_address_action},
3244
3196 { "notify-disk-writeable", NULL,3245 { "notify-disk-writeable", NULL,
3197 N_("Inform Upstart that disk is now writeable."),3246 N_("Inform Upstart that disk is now writeable."),
3198 N_("Run to ensure output from jobs ending before "3247 N_("Run to ensure output from jobs ending before "
31993248
=== modified file 'util/man/initctl.8'
--- util/man/initctl.8 2013-05-31 15:41:20 +0000
+++ util/man/initctl.8 2013-11-04 11:44:32 +0000
@@ -42,14 +42,19 @@
42.B \-\-user42.B \-\-user
43User mode. In this mode, initctl will talk to the43User mode. In this mode, initctl will talk to the
44.BR init (8)44.BR init (8)
45daemon using the D\-Bus private socket defined in the UPSTART_SESSION45daemon using the D\-Bus private socket defined in the
46.B UPSTART_SESSION
46environment variable.47environment variable.
48
49Note that if the
50.B UPSTART_SESSION
51variable is defined, this option is implied.
47.\"52.\"
48.TP53.TP
49.B \-\-session54.B \-\-session
50Connect to55Connect to
51.BR init (8)56.BR init (8)
52daemon using the D\-Bus session bus (for testing purposes only).57daemon using the existing D\-Bus session bus (for testing purposes only).
53.\"58.\"
54.TP59.TP
55.B \-\-system60.B \-\-system
@@ -555,6 +560,18 @@
555.RE560.RE
556.\"561.\"
557.TP562.TP
563.B notify\-dbus\-address
564Notify the
565.BR init (8)
566daemon of the D\-Bus address it should use to connect to.
567
568This command is only permitted when running in
569.B User Session Mode.
570See
571.BR init (5)
572for further details.
573.\"
574.TP
558.B list\-env575.B list\-env
559.RI [ OPTIONS "]576.RI [ OPTIONS "]
560577
@@ -608,7 +625,7 @@
608Adds or updates a variable in a job environment table. Variables set625Adds or updates a variable in a job environment table. Variables set
609in this way will apply to all subsequently-starting jobs.626in this way will apply to all subsequently-starting jobs.
610627
611This command is only permitted When running in628This command is only permitted when running in
612.B User Session Mode.629.B User Session Mode.
613See 630See
614.BR init (5)631.BR init (5)
@@ -640,7 +657,7 @@
640Remove the specified variable from a job environment table. If the657Remove the specified variable from a job environment table. If the
641variable does not already exist in the table, no change will be made.658variable does not already exist in the table, no change will be made.
642659
643This command is only permitted When running in660This command is only permitted when running in
644.B User Session Mode.661.B User Session Mode.
645See 662See
646.BR init (5)663.BR init (5)
@@ -667,12 +684,12 @@
667.\"684.\"
668.TP685.TP
669.B reset\-env686.B reset\-env
670.R [ OPTIONS ]687.RI [ OPTIONS ]
671688
672Discards all changes make to a job environment table, setting it back689Discards all changes make to a job environment table, setting it back
673to its default set of variables and values.690to its default set of variables and values.
674691
675This command is only permitted When running in692This command is only permitted when running in
676.B User Session Mode.693.B User Session Mode.
677See 694See
678.BR init (5)695.BR init (5)
679696
=== modified file 'util/tests/test_initctl.c'
--- util/tests/test_initctl.c 2013-10-18 09:13:36 +0000
+++ util/tests/test_initctl.c 2013-11-04 11:44:32 +0000
@@ -16790,6 +16790,215 @@
16790 TEST_EQ (rmdir (logdir), 0);16790 TEST_EQ (rmdir (logdir), 0);
16791}16791}
1679216792
16793void
16794test_dbus_connection (void)
16795{
16796 size_t lines;
16797 pid_t dbus_pid = 0;
16798 pid_t dbus_pid2 = 0;
16799 pid_t upstart_pid = 0;
16800 nih_local char *cmd = NULL;
16801 char **output;
16802 nih_local char *dbus_session_address = NULL;
16803 nih_local char *dbus_session_address2 = NULL;
16804 nih_local char *upstart_session = NULL;
16805 char *address;
16806
16807 TEST_GROUP ("D-Bus connection");
16808
16809 /*********************************************************************/
16810 TEST_FEATURE ("ensure non-priv non-Session Init connects to D-Bus session bus on startup");
16811
16812 /* Start a dbus-daemon */
16813 TEST_DBUS (dbus_pid);
16814
16815 /* Not required */
16816 assert0 (unsetenv ("DBUS_SYSTEM_BUS_ADDRESS"));
16817
16818 TEST_TRUE (getenv ("DBUS_SESSION_BUS_ADDRESS"));
16819
16820 START_UPSTART (upstart_pid, FALSE);
16821
16822 cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ());
16823 TEST_NE_P (cmd, NULL);
16824 RUN_COMMAND (NULL, cmd, &output, &lines);
16825 TEST_EQ (lines, 1);
16826 TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*");
16827 nih_free (output);
16828
16829 STOP_UPSTART (upstart_pid);
16830 TEST_DBUS_END (dbus_pid);
16831
16832 /*********************************************************************/
16833 TEST_FEATURE ("ensure Session Init does not connect to D-Bus session bus on startup");
16834
16835 /* Start a dbus-daemon */
16836 TEST_DBUS (dbus_pid);
16837
16838 /* Not required */
16839 assert0 (unsetenv ("DBUS_SYSTEM_BUS_ADDRESS"));
16840
16841 TEST_TRUE (getenv ("DBUS_SESSION_BUS_ADDRESS"));
16842
16843 START_UPSTART (upstart_pid, TRUE);
16844
16845 address = getenv ("DBUS_SESSION_BUS_ADDRESS");
16846 TEST_NE_P (address, NULL);
16847 dbus_session_address = nih_strdup (NULL, address);
16848 TEST_NE_P (dbus_session_address, NULL);
16849
16850 /* Stop initctl using this route */
16851 assert0 (unsetenv ("DBUS_SESSION_BUS_ADDRESS"));
16852
16853 /* Check we can query the version via the private socket */
16854 cmd = nih_sprintf (NULL, "%s version 2>&1", get_initctl_binary ());
16855 TEST_NE_P (cmd, NULL);
16856 RUN_COMMAND (NULL, cmd, &output, &lines);
16857 TEST_EQ (lines, 1);
16858 TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*");
16859 nih_free (output);
16860
16861 /* Unset to stop initctl finding upstart via this route */
16862 assert0 (unsetenv ("UPSTART_SESSION"));
16863
16864 /* Re-apply in the test environment */
16865 assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_session_address, 1));
16866
16867 /* Although there is a D-Bus session bus available, the Session
16868 * Init should not connect to it. Check this by trying to query
16869 * the running version via the D-Bus session bus.
16870 */
16871 cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ());
16872 TEST_NE_P (cmd, NULL);
16873 RUN_COMMAND (NULL, cmd, &output, &lines);
16874 TEST_EQ (lines, 1);
16875 TEST_STR_MATCH (output[0], "initctl: Name \"com.ubuntu.Upstart\" does not exist*");
16876 nih_free (output);
16877
16878 STOP_UPSTART (upstart_pid);
16879 TEST_DBUS_END (dbus_pid);
16880
16881 /*********************************************************************/
16882 TEST_FEATURE ("ensure Session Init connects to D-Bus session bus when notified");
16883
16884 /* Start a dbus-daemon */
16885 TEST_DBUS (dbus_pid);
16886
16887 address = getenv ("DBUS_SESSION_BUS_ADDRESS");
16888 TEST_NE_P (address, NULL);
16889 dbus_session_address = nih_strdup (NULL, address);
16890 TEST_NE_P (dbus_session_address, NULL);
16891
16892 /* Not required */
16893 assert0 (unsetenv ("DBUS_SYSTEM_BUS_ADDRESS"));
16894 assert0 (unsetenv ("DBUS_SESSION_BUS_ADDRESS"));
16895
16896 START_UPSTART (upstart_pid, TRUE);
16897
16898 /* Pass the D-Bus session bus address to the Session Init */
16899 cmd = nih_sprintf (NULL, "%s notify-dbus-address \"%s\" 2>&1",
16900 get_initctl_binary (), dbus_session_address);
16901 TEST_NE_P (cmd, NULL);
16902 RUN_COMMAND (NULL, cmd, &output, &lines);
16903 TEST_EQ (lines, 0);
16904
16905 /* Re-apply in the test environment */
16906 assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_session_address, 1));
16907
16908 /* It should now be possible to query the running version via
16909 * the D-Bus session bus.
16910 */
16911 cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ());
16912 TEST_NE_P (cmd, NULL);
16913 RUN_COMMAND (NULL, cmd, &output, &lines);
16914 TEST_EQ (lines, 1);
16915 TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*");
16916 nih_free (output);
16917
16918 STOP_UPSTART (upstart_pid);
16919 TEST_DBUS_END (dbus_pid);
16920
16921 /*********************************************************************/
16922 TEST_FEATURE ("ensure Session Init does not connect to another bus when notified twice");
16923
16924 /* Start first dbus-daemon */
16925 TEST_DBUS (dbus_pid);
16926
16927 /* Save its address */
16928 address = getenv ("DBUS_SESSION_BUS_ADDRESS");
16929 TEST_NE_P (address, NULL);
16930 dbus_session_address = nih_strdup (NULL, address);
16931 TEST_NE_P (dbus_session_address, NULL);
16932
16933 /* Start second dbus-daemon */
16934 TEST_DBUS (dbus_pid2);
16935
16936 /* Save its address */
16937 address = getenv ("DBUS_SESSION_BUS_ADDRESS");
16938 TEST_NE_P (address, NULL);
16939 dbus_session_address2 = nih_strdup (NULL, address);
16940 TEST_NE_P (dbus_session_address2, NULL);
16941
16942 assert0 (unsetenv ("DBUS_SYSTEM_BUS_ADDRESS"));
16943 assert0 (unsetenv ("DBUS_SESSION_BUS_ADDRESS"));
16944
16945 START_UPSTART (upstart_pid, TRUE);
16946
16947 /* Pass the first D-Bus session bus address to the Session Init */
16948 cmd = nih_sprintf (NULL, "%s notify-dbus-address \"%s\" 2>&1",
16949 get_initctl_binary (), dbus_session_address);
16950 TEST_NE_P (cmd, NULL);
16951 RUN_COMMAND (NULL, cmd, &output, &lines);
16952 TEST_EQ (lines, 0);
16953
16954 /* Re-apply in the test environment */
16955 assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_session_address, 1));
16956
16957 /* It should now be possible to query the running version via
16958 * the D-Bus session bus.
16959 */
16960 cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ());
16961 TEST_NE_P (cmd, NULL);
16962 RUN_COMMAND (NULL, cmd, &output, &lines);
16963 TEST_EQ (lines, 1);
16964 TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*");
16965 nih_free (output);
16966
16967 /* Pass the second D-Bus session bus address to the Session Init */
16968 cmd = nih_sprintf (NULL, "%s notify-dbus-address \"%s\" 2>&1",
16969 get_initctl_binary (), dbus_session_address2);
16970 TEST_NE_P (cmd, NULL);
16971 RUN_COMMAND (NULL, cmd, &output, &lines);
16972 TEST_EQ (lines, 0);
16973
16974 /* Check that the Session Init still responds on the first address */
16975 cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ());
16976 TEST_NE_P (cmd, NULL);
16977 RUN_COMMAND (NULL, cmd, &output, &lines);
16978 TEST_EQ (lines, 1);
16979 TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*");
16980 nih_free (output);
16981
16982 /* Stop the 1st daemon */
16983 TEST_DBUS_END (dbus_pid);
16984
16985 /* Switch to the 2nd daemon */
16986 assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_session_address2, 1));
16987
16988 /* Ensure the Session Init isn't responding on this address */
16989 cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ());
16990 TEST_NE_P (cmd, NULL);
16991 RUN_COMMAND (NULL, cmd, &output, &lines);
16992 TEST_EQ (lines, 1);
16993 TEST_STR_MATCH (output[0], "initctl: Name \"com.ubuntu.Upstart\" does not exist*");
16994 nih_free (output);
16995
16996 STOP_UPSTART (upstart_pid);
16997
16998 /* Stop the 2nd daemon */
16999 TEST_DBUS_END (dbus_pid2);
17000}
17001
16793int17002int
16794main (int argc,17003main (int argc,
16795 char *argv[])17004 char *argv[])
@@ -16834,5 +17043,7 @@
16834 test_notify_disk_writeable ();17043 test_notify_disk_writeable ();
16835 }17044 }
1683617045
17046 test_dbus_connection ();
17047
16837 return 0;17048 return 0;
16838}17049}

Subscribers

People subscribed via source and target branches