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

Requested reviews:
  Upstart Reviewers (upstart-reviewers)

For more details, see:
https://code.launchpad.net/~stgraber/upstart/upstart-dbus-events/+merge/139726

This branch implements two new signals:
 - Restarted
   Emitted after upstart has restarted.
 - EventEmitted
   Emitted whenever an event is emitted, two parameters are set, one is a list
   of all the environment variables and values, the other is the blocking
   state of the event.

I also extended the current testsuite to test for the EventEmitted signal.
Doing this caught a bug in libnih where it'd fail with an assert when passed an
empty list for the 'as' type.
This has since been fixed in the libnih Ubuntu package.

There's currently no tests for the Restarted event as I wasn't too sure where
to put one, considering that the test would depend on the presence of the DBUS
system bus and of a running upstart with re-exec support.
The system bus is required for the Restarted event as it's almost impossible to
re-attach to the private bus quickly enough to receive the Restarted event.
-- 
https://code.launchpad.net/~stgraber/upstart/upstart-dbus-events/+merge/139726
Your team Upstart Reviewers is requested to review the proposed merge of 
lp:~stgraber/upstart/upstart-dbus-events into lp:upstart.
=== modified file 'dbus/com.ubuntu.Upstart.xml'
--- dbus/com.ubuntu.Upstart.xml	2012-12-07 18:26:43 +0000
+++ dbus/com.ubuntu.Upstart.xml	2012-12-13 15:23:30 +0000
@@ -50,6 +50,15 @@
       <arg name="job" type="o" />
     </signal>
 
+    <!-- Signal for events being emitted -->
+    <signal name="EventEmitted">
+      <arg name="name" type="s" />
+      <arg name="env" type="as" />
+    </signal>
+
+    <!-- Signal emitted after upstart restarted and reconnected to DBUS -->
+    <signal name="Restarted" />
+
     <!-- Event emission -->
     <method name="EmitEvent">
       <annotation name="com.netsplit.Nih.Method.Async" value="true" />

=== modified file 'init/event.c'
--- init/event.c	2012-10-10 13:24:51 +0000
+++ init/event.c	2012-12-13 15:23:30 +0000
@@ -42,6 +42,7 @@
 #include "event.h"
 #include "job.h"
 #include "blocked.h"
+#include "control.h"
 #include "errors.h"
 
 #include "com.ubuntu.Upstart.h"
@@ -283,6 +284,15 @@
 	nih_assert (event->progress == EVENT_PENDING);
 
 	nih_info (_("Handling %s event"), event->name);
+
+	NIH_LIST_FOREACH (control_conns, iter) {
+		NihListEntry   *entry = (NihListEntry *)iter;
+		DBusConnection *conn = (DBusConnection *)entry->data;
+
+		NIH_ZERO (control_emit_event_emitted (conn, DBUS_PATH_UPSTART,
+											  event->name, event->env));
+	}
+
 	event->progress = EVENT_HANDLING;
 
 	event_pending_handle_jobs (event);

=== modified file 'init/main.c'
--- init/main.c	2012-11-07 15:17:58 +0000
+++ init/main.c	2012-12-13 15:23:30 +0000
@@ -52,6 +52,8 @@
 #include <nih/error.h>
 #include <nih/logging.h>
 
+#include "dbus/upstart.h"
+
 #include "paths.h"
 #include "events.h"
 #include "system.h"
@@ -62,6 +64,7 @@
 #include "control.h"
 #include "state.h"
 
+#include "com.ubuntu.Upstart.h"
 
 /* Prototypes for static functions */
 #ifndef DEBUG
@@ -598,6 +601,16 @@
 		 * disabled by the term_handler */
 		sigemptyset (&mask);
 		sigprocmask (SIG_SETMASK, &mask, NULL);
+
+		/* Emit the Restarted signal so that any listing Instance Init
+		 * knows that it needs to restart too.
+		 */
+		NIH_LIST_FOREACH (control_conns, iter) {
+			NihListEntry   *entry = (NihListEntry *)iter;
+			DBusConnection *conn = (DBusConnection *)entry->data;
+
+			NIH_ZERO (control_emit_restarted (conn, DBUS_PATH_UPSTART));
+		}
 	}
 
 	if (disable_sessions)

=== modified file 'init/tests/test_event.c'
--- init/tests/test_event.c	2011-12-09 14:07:11 +0000
+++ init/tests/test_event.c	2012-12-13 15:23:30 +0000
@@ -20,6 +20,7 @@
  */
 
 #include <nih/test.h>
+#include <nih-dbus/test_dbus.h>
 
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -32,6 +33,8 @@
 #include <nih/main.h>
 #include <nih/error.h>
 
+#include "dbus/upstart.h"
+
 #include "control.h"
 #include "job.h"
 #include "event.h"
@@ -135,11 +138,39 @@
 test_poll (void)
 {
 	Event *event = NULL;
+	pid_t           dbus_pid;
+	DBusError       dbus_error;
+	DBusConnection *conn, *client_conn;
+	DBusMessage    *message;
+	NihListEntry   *entry;
 
 	TEST_FUNCTION ("event_poll");
+	nih_error_init ();
+	nih_timer_init ();
+	nih_main_loop_init ();
+	control_init ();
 	job_class_init ();
+
+	/* Check that when a D-Bus connection is open, the new instance
+	 * is registered on that connection as an object and the InstanceAdded
+	 * signal is emitted.
+	 */
+	TEST_FEATURE ("with D-Bus connection");
+	dbus_error_init (&dbus_error);
+
+	TEST_DBUS (dbus_pid);
+	TEST_DBUS_OPEN (conn);
+	TEST_DBUS_OPEN (client_conn);
+
+	dbus_bus_add_match (client_conn, "type='signal'", &dbus_error);
+	assert (! dbus_error_is_set (&dbus_error));
+
 	control_init ();
 
+	entry = nih_list_entry_new (NULL);
+	entry->data = conn;
+	nih_list_add (control_conns, &entry->entry);
+
 
 	/* Check that a pending event which does not get blocked goes
 	 * straight though and gets freed.
@@ -154,6 +185,12 @@
 
 		event_poll ();
 
+		TEST_DBUS_MESSAGE (client_conn, message);
+		TEST_TRUE (dbus_message_is_signal (message, DBUS_INTERFACE_UPSTART,
+						   "EventEmitted"));
+
+		dbus_message_unref (message);
+
 		TEST_FREE (event);
 	}
 
@@ -213,6 +250,14 @@
 
 		TEST_FREE (event);
 	}
+
+	nih_free (entry);
+
+	TEST_DBUS_CLOSE (conn);
+	TEST_DBUS_CLOSE (client_conn);
+	TEST_DBUS_END (dbus_pid);
+
+	dbus_shutdown ();
 }
 
 

=== modified file 'init/tests/test_event_operator.c'
--- init/tests/test_event_operator.c	2012-09-21 16:08:44 +0000
+++ init/tests/test_event_operator.c	2012-12-13 15:23:30 +0000
@@ -26,6 +26,7 @@
 #include <nih/string.h>
 #include <nih/tree.h>
 
+#include "control.h"
 #include "event_operator.h"
 #include "blocked.h"
 #include "parse_job.h"
@@ -843,6 +844,8 @@
 	Event         *event;
 	int            ret;
 
+	control_init ();
+
 	TEST_FUNCTION ("event_operator_handle");
 	oper1 = event_operator_new (NULL, EVENT_OR, NULL, NULL);
 	oper2 = event_operator_new (NULL, EVENT_AND, NULL, NULL);

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

Reply via email to