Ted Gould has proposed merging lp:~ted/upstart/dbus-configure-event into 
lp:upstart.

Commit message:
Make the dbus-bridge event configurable.

Requested reviews:
  Upstart Reviewers (upstart-reviewers)

For more details, see:
https://code.launchpad.net/~ted/upstart/dbus-configure-event/+merge/172381

Makes the event that the dbus-bridge emits configurable so that some jobs can 
emit a differently named event.  (look at the dependent branches)
-- 
https://code.launchpad.net/~ted/upstart/dbus-configure-event/+merge/172381
Your team Upstart Reviewers is requested to review the proposed merge of 
lp:~ted/upstart/dbus-configure-event into lp:upstart.
=== modified file 'extra/upstart-dbus-bridge.c'
--- extra/upstart-dbus-bridge.c	2013-06-26 09:15:41 +0000
+++ extra/upstart-dbus-bridge.c	2013-07-01 17:53:27 +0000
@@ -44,14 +44,8 @@
 #include "com.ubuntu.Upstart.h"
 #include "com.ubuntu.Upstart.Job.h"
 
-/**
- * DBUS_EVENT:
- *
- * Name of event this program handles.
- **/
-#define DBUS_EVENT "dbus"
-
 /* Prototypes for static functions */
+static int               dbus_event_setter    (NihOption *option, const char *arg);
 static int               dbus_bus_setter      (NihOption *option, const char *arg);
 static void              dbus_disconnected    (DBusConnection *connection);
 static void              upstart_disconnected (DBusConnection *connection);
@@ -93,6 +87,13 @@
 DBusBusType dbus_bus = (DBusBusType)-1;
 
 /**
+ * dbus_event:
+ *
+ * type of event to emit.
+ **/
+static const char * dbus_event = NULL;
+
+/**
  * Structure we use for tracking jobs
  *
  * @entry: list header, 
@@ -128,6 +129,8 @@
 	  NULL, NULL, &always, NULL },
 	{ 0, "daemon", N_("Detach and run in the background"),
 	  NULL, NULL, &daemonise, NULL },
+	{ 0, "event", N_("Event to emit to Upstart Jobs"),
+	  NULL, "event name", NULL, dbus_event_setter },
 	{ 0, "user", N_("Connect to user session"),
 	  NULL, NULL, &user_mode, NULL },
 	{ 0, "session", N_("Use D-Bus session bus"),
@@ -173,6 +176,9 @@
 	if (dbus_bus == (DBusBusType)-1)
 		dbus_bus = user_mode ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM;
 
+	if (dbus_event == NULL) 
+		dbus_event = "dbus";
+
 	/* Connect to the chosen D-Bus bus */
 	dbus_connection = NIH_SHOULD (nih_dbus_bus (dbus_bus, dbus_disconnected));
 
@@ -376,6 +382,24 @@
 }
 
 /**  
+ * NihOption setter function to handle event name
+ *
+ * Returns: 0 on success
+ **/
+static int
+dbus_event_setter (NihOption *option, const char *arg)
+{
+	nih_assert (option);
+
+	if (arg == NULL || arg[0] == '\0' || arg[0] == ' ') {
+		return -1;
+	}
+
+	dbus_event = arg;
+	return 0;
+}
+
+/**  
  * NihOption setter function to handle selection of D-Bus bus type.
  *
  * Returns: 0 on success, -1 on invalid console type.
@@ -501,7 +525,7 @@
 		   path ? path : "");
 
 	pending_call = upstart_emit_event (upstart,
-			DBUS_EVENT, env, FALSE,
+			dbus_event, env, FALSE,
 			NULL, emit_event_error, NULL,
 			NIH_DBUS_TIMEOUT_NEVER);
 
@@ -590,13 +614,13 @@
 
 	/* Find out whether this job listens for any DBUS events */
 	for (char ***event = start_on; event && *event && **event; event++)
-		if (! strcmp (**event, DBUS_EVENT)) {
+		if (! strcmp (**event, dbus_event)) {
 			add = TRUE;
 			break;
 		}
 
 	for (char ***event = stop_on; ! add && event && *event && **event; event++)
-		if (! strcmp (**event, DBUS_EVENT)) {
+		if (! strcmp (**event, dbus_event)) {
 			add = TRUE;
 			break;
 		}
@@ -604,7 +628,7 @@
 	if (! add)
 		return;
 
-	nih_debug ("Job got added %s for event %s", job_class_path, DBUS_EVENT);
+	nih_debug ("Job got added %s for event %s", job_class_path, dbus_event);
 
 	/* Free any existing record for the job (should never happen,
 	 * but worth being safe).

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

Reply via email to