Merge authors:
Stéphane Graber (stgraber)
Related merge proposals:
https://code.launchpad.net/~stgraber/upstart/upstart-dbus-events/+merge/139726
proposed by: Stéphane Graber (stgraber)
review: Needs Fixing - James Hunt (jamesodhunt)
------------------------------------------------------------
revno: 1409 [merge]
committer: James Hunt <[email protected]>
branch nick: upstart
timestamp: Mon 2012-12-17 13:47:32 +0000
message:
* Merge of lp:~stgraber/upstart/upstart-dbus-events.
modified:
dbus/com.ubuntu.Upstart.xml
init/control.c
init/control.h
init/event.c
init/main.c
init/tests/test_event.c
--
lp:upstart
https://code.launchpad.net/~upstart-devel/upstart/trunk
Your team Upstart Reviewers is subscribed to branch lp:upstart.
To unsubscribe from this branch go to
https://code.launchpad.net/~upstart-devel/upstart/trunk/+edit-subscription
=== 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-11-27 16:37:41 +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/control.c'
--- init/control.c 2012-12-07 18:26:43 +0000
+++ init/control.c 2012-12-17 11:45:28 +0000
@@ -55,6 +55,7 @@
#include "control.h"
#include "errors.h"
#include "state.h"
+#include "event.h"
#include "com.ubuntu.Upstart.h"
@@ -1067,3 +1068,42 @@
return 0;
}
+
+/**
+ * control_notify_event_emitted
+ *
+ * Re-emits an event over DBUS using the EventEmitted signal
+ **/
+void
+control_notify_event_emitted (Event *event)
+{
+ nih_assert (event != NULL);
+
+ control_init ();
+
+ 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));
+ }
+}
+
+/**
+ * control_notify_restarted
+ *
+ * DBUS signal sent when upstart has re-executed itself.
+ **/
+void
+control_notify_restarted (void)
+{
+ control_init ();
+
+ NIH_LIST_FOREACH (control_conns, iter) {
+ NihListEntry *entry = (NihListEntry *)iter;
+ DBusConnection *conn = (DBusConnection *)entry->data;
+
+ NIH_ZERO (control_emit_restarted (conn, DBUS_PATH_UPSTART));
+ }
+}
=== modified file 'init/control.h'
--- init/control.h 2012-12-07 18:26:43 +0000
+++ init/control.h 2012-12-14 23:43:15 +0000
@@ -30,6 +30,8 @@
#include <json.h>
+#include "event.h"
+
/**
* USE_SESSION_BUS_ENV:
*
@@ -113,6 +115,9 @@
int control_restart (void *data, NihDBusMessage *message)
__attribute__ ((warn_unused_result));
+void control_notify_event_emitted (Event *event);
+void control_notify_restarted (void);
+
NIH_END_EXTERN
#endif /* INIT_CONTROL_H */
=== modified file 'init/event.c'
--- init/event.c 2012-10-10 13:24:51 +0000
+++ init/event.c 2012-12-14 23:47:51 +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"
@@ -507,6 +508,8 @@
}
}
+ control_notify_event_emitted (event);
+
nih_free (event);
}
=== modified file 'init/main.c'
--- init/main.c 2012-12-07 21:39:17 +0000
+++ init/main.c 2012-12-17 13:47:32 +0000
@@ -605,6 +605,11 @@
* 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.
+ */
+ control_notify_restarted();
}
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-11-27 23:49:12 +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 ();
}
--
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/upstart-devel