Stéphane Graber has proposed merging 
lp:~stgraber/upstart/upstart-session-socket into lp:upstart.

Requested reviews:
  Upstart Reviewers (upstart-reviewers)

For more details, see:
https://code.launchpad.net/~stgraber/upstart/upstart-session-socket/+merge/143344

This branch implements the UPSTART_SESSION variable from the user session
specification.

Upstart will now always listen to a private DBus socket.
The system instance remains on its usual /com/ubuntu/upstart address.
The user instances use /com/ubuntu/upstart-session/%uid/%pid

The path is then exported as UPSTART_SESSION in the job environments, so
that jobs can call initctl and talk to upstart without requiring DBus.


A new --user flag is also added to initctl, when passed, it'll make initctl
use the socket defined in UPSTART_SESSION if present or otherwise will
fallback to the DBus session bus.
-- 
https://code.launchpad.net/~stgraber/upstart/upstart-session-socket/+merge/143344
Your team Upstart Reviewers is requested to review the proposed merge of 
lp:~stgraber/upstart/upstart-session-socket into lp:upstart.
=== modified file 'init/control.c'
--- init/control.c	2012-12-17 11:45:28 +0000
+++ init/control.c	2013-01-15 16:23:20 +0000
@@ -80,7 +80,7 @@
  *
  * Address on which the control server may be reached.
  **/
-const char *control_server_address = DBUS_ADDRESS_UPSTART;
+char *control_server_address = NULL;
 
 /**
  * control_server:
@@ -116,6 +116,14 @@
 {
 	if (! control_conns)
 		control_conns = NIH_MUST (nih_list_new (NULL));
+
+	if (! control_server_address) {
+		if (use_session_bus)
+			NIH_MUST (nih_strcat_sprintf(&control_server_address, NULL,
+					    "%s-session/%d/%d", DBUS_ADDRESS_UPSTART, getuid(), getpid()));
+		else
+			NIH_MUST (nih_strcat_sprintf(&control_server_address, NULL, DBUS_ADDRESS_UPSTART));
+	}
 }
 
 

=== modified file 'init/job_process.c'
--- init/job_process.c	2012-12-18 09:02:24 +0000
+++ init/job_process.c	2013-01-15 16:23:20 +0000
@@ -65,6 +65,7 @@
 #include "job_class.h"
 #include "job.h"
 #include "errors.h"
+#include "control.h"
 
 
 /**
@@ -126,6 +127,8 @@
 static void job_process_trace_fork      (Job *job, ProcessType process);
 static void job_process_trace_exec      (Job *job, ProcessType process);
 
+extern int          use_session_bus;
+extern char         *control_server_address;
 
 /**
  * job_process_run:
@@ -275,6 +278,9 @@
 			       "UPSTART_JOB=%s", job->class->name));
 	NIH_MUST (environ_set (&env, NULL, &envc, TRUE,
 			       "UPSTART_INSTANCE=%s", job->name));
+	if (use_session_bus)
+		NIH_MUST (environ_set (&env, NULL, &envc, TRUE,
+			       "UPSTART_SESSION=%s", control_server_address));
 
 	/* If we're about to spawn the main job and we expect it to become
 	 * a daemon or fork before we can move out of spawned, we need to

=== modified file 'init/main.c'
--- init/main.c	2012-12-18 14:09:55 +0000
+++ init/main.c	2013-01-15 16:23:20 +0000
@@ -549,19 +549,17 @@
 	conf_reload ();
 
 	/* Create a listening server for private connections. */
-	if (use_session_bus == FALSE) {
-		while (control_server_open () < 0) {
-			NihError *err;
+	while (control_server_open () < 0) {
+		NihError *err;
 
-			err = nih_error_get ();
-			if (err->number != ENOMEM) {
-				nih_warn ("%s: %s", _("Unable to listen for private connections"),
-					err->message);
-				nih_free (err);
-				break;
-			}
+		err = nih_error_get ();
+		if (err->number != ENOMEM) {
+			nih_warn ("%s: %s", _("Unable to listen for private connections"),
+				err->message);
 			nih_free (err);
+			break;
 		}
+		nih_free (err);
 	}
 
 	/* Open connection to the appropriate D-Bus bus; we normally expect this to

=== modified file 'util/initctl.c'
--- util/initctl.c	2012-03-16 21:02:13 +0000
+++ util/initctl.c	2013-01-15 16:23:20 +0000
@@ -145,6 +145,13 @@
 int dbus_bus_type = -1;
 
 /**
+ * user_mode:
+ *
+ * If TRUE, upstart runs in user session mode.
+ **/
+static int user_mode = FALSE;
+
+/**
  * dest_name:
  *
  * Name on the D-Bus system bus that the message should be sent to when
@@ -292,10 +299,21 @@
 	DBusConnection *connection;
 	NihDBusProxy *  upstart;
 
-	if (use_dbus < 0)
-		use_dbus = getuid () ? TRUE : FALSE;
-	if (use_dbus >= 0 && dbus_bus_type < 0)
-		dbus_bus_type = DBUS_BUS_SYSTEM;
+	if (!user_mode) {
+		if (use_dbus < 0)
+			use_dbus = getuid () ? TRUE : FALSE;
+		if (use_dbus >= 0 && dbus_bus_type < 0)
+			dbus_bus_type = DBUS_BUS_SYSTEM;
+	}
+	else {
+		if (getenv("UPSTART_SESSION") && use_dbus <= 0) {
+			use_dbus = FALSE;
+			dest_address = getenv("UPSTART_SESSION");
+		}
+		else if (dbus_bus_type < 0)
+			dbus_bus_type = DBUS_BUS_SESSION;
+	}
+
 
 	dbus_error_init (&dbus_error);
 	if (use_dbus) {
@@ -2356,6 +2374,8 @@
 	  NULL, NULL, NULL, dbus_bus_type_setter },
 	{ 0, "dest", N_("destination well-known name on D-Bus bus"),
 	  NULL, "NAME", &dest_name, NULL },
+	{ 0, "user", N_("start in user mode (as used for user sessions)"),
+		NULL, NULL, &user_mode, NULL },
 
 	NIH_OPTION_LAST
 };

-- 
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel

Reply via email to