Merge lp:~ted/upstart/dbus-arguments into lp:upstart

Proposed by Ted Gould
Status: Merged
Merged at revision: 1513
Proposed branch: lp:~ted/upstart/dbus-arguments
Merge into: lp:upstart
Prerequisite: lp:~ted/upstart/session-jobs
Diff against target: 140 lines (+97/-1)
2 files modified
extra/man/dbus-event.7 (+5/-1)
extra/upstart-dbus-bridge.c (+92/-0)
To merge this branch: bzr merge lp:~ted/upstart/dbus-arguments
Reviewer Review Type Date Requested Status
James Hunt Approve
Review via email: mp+172385@code.launchpad.net

Commit message

Add DBus signal arguments to the Upstart event.

Description of the change

Takes the dbus message and if it has any string arguments adds them to the Upstart event so that other jobs can filter and use them directly.

To post a comment you must log in.
Revision history for this message
James Hunt (jamesodhunt) wrote :

This looks good. A few comments:

- It needs an update to extra/man/dbus-event.7 to explain the ARG%d string arguments.

- I think that we should consider supporting all non-aggregate basic types (except maybe BYTE) since types such as BOOLEAN and the numerics could be equally useful.

- Since we've already released upstart 1.9 including the upstart-dbus-bridge, we need to think about how to handle/break/deprecate the existing 'dbus' event. Allowing the event name to be configurable (lp:~ted/upstart/dbus-configure-event) may be the best way to do it I guess, although the ideal would be to able to support:

  dbus BUS=system SIGNAL=...
  dbus BUS=session SIGNAL=...
  dbus BUS=unix:abstract=/com/ubuntu/upstart-session/1000/2536 SIGNAL=...

... rather than:

  dbus-system SIGNAL=...
  dbus-session SIGNAL=...
  dbus-???? SIGNAL=...

However, if we just switched to that, we'd break any jobs that specify positional values in conditions like 'start on dbus NameAcquired SENDER=...'.

It would lead to slightly more verbose job conditions, but maybe we could change the event to 'message-bug' or similar?:

  message-bus TYPE=dbus BUS=system SIGNAL=...

Revision history for this message
Steve Langasek (vorlon) wrote :

On Mon, Jul 08, 2013 at 03:33:30PM -0000, James Hunt wrote:

> - Since we've already released upstart 1.9 including the
> upstart-dbus-bridge, we need to think about how to
> handle/break/deprecate the existing 'dbus' event.

Considering this was pushed to trunk in advance of resolving this multiple
bus question on the grounds that it was useful in its current form and only
needed extended, yes.

> Allowing the event name to be configurable
> (lp:~ted/upstart/dbus-configure-event) may be the best way to do it I
> guess, although the ideal would be to able to support:

> dbus BUS=system SIGNAL=...
> dbus BUS=session SIGNAL=...
> dbus BUS=unix:abstract=/com/ubuntu/upstart-session/1000/2536 SIGNAL=...

I agree that this would be preferred, not just for compatibility but I think
in terms of overall semantics for such an event.

Revision history for this message
Ted Gould (ted) wrote :

On Mon, 2013-07-08 at 09:39 -0700, Steve Langasek wrote:

> On Mon, Jul 08, 2013 at 03:33:30PM -0000, James Hunt wrote:
>
> > - Since we've already released upstart 1.9 including the
> > upstart-dbus-bridge, we need to think about how to
> > handle/break/deprecate the existing 'dbus' event.
>
> Considering this was pushed to trunk in advance of resolving this multiple
> bus question on the grounds that it was useful in its current form and only
> needed extended, yes.
>
> > Allowing the event name to be configurable
> > (lp:~ted/upstart/dbus-configure-event) may be the best way to do it I
> > guess, although the ideal would be to able to support:
>
> > dbus BUS=system SIGNAL=...
> > dbus BUS=session SIGNAL=...
> > dbus BUS=unix:abstract=/com/ubuntu/upstart-session/1000/2536 SIGNAL=...
>
> I agree that this would be preferred, not just for compatibility but I think
> in terms of overall semantics for such an event.

You guys are commenting on the wrong branch :-)

Changed it to add the bus name on the event here:

https://code.launchpad.net/~ted/upstart/dbus-configure-event/+merge/172381

Then adjusted the jobs here:

https://code.launchpad.net/~ted/upstart/session-jobs/+merge/172384

I made the bus name configurable because there has generally been talk
in the dbus community before about creating a "user" bus. That would be
one per-user independent of sessions. I figured this would allow us to
have other named buses as well. Perhaps a "unity" bus or something like
that, without having to put the full abstract path in.

Revision history for this message
Ted Gould (ted) wrote :

On Mon, 2013-07-08 at 15:33 +0000, James Hunt wrote:

> - It needs an update to extra/man/dbus-event.7 to explain the ARG%d
> string arguments.

Fixed in r1504

> - I think that we should consider supporting all non-aggregate basic
> types (except maybe BYTE) since types such as BOOLEAN and the numerics
> could be equally useful.

Fixed in r1505

lp:~ted/upstart/dbus-arguments updated
1504. By Ted Gould

Adding man page for the arguments

1505. By Ted Gould

Handle basic types

Revision history for this message
James Hunt (jamesodhunt) wrote :

LGTM.

review: Approve
Revision history for this message
James Hunt (jamesodhunt) wrote :

Hmm - back-peddling half-a step, we can't technically add one of those session jobs yet as it uses the as-yet-unavailable --event option. In fact, might make more sense to just add those to the Ubuntu package in debian/user-conf/ like we've done for the file bridge.

Revision history for this message
Ted Gould (ted) wrote :

On Tue, 2013-07-09 at 16:58 +0000, James Hunt wrote:

> Hmm - back-peddling half-a step, we can't technically add one of those
> session jobs yet as it uses the as-yet-unavailable --event option. In
> fact, might make more sense to just add those to the Ubuntu package in
> debian/user-conf/ like we've done for the file bridge.

I'm confused, what is the --event option? I don't mind moving the
files, but it seems a bit silly to not give them to everyone whether
they use them or not.

lp:~ted/upstart/dbus-arguments updated
1506. By Ted Gould

Merge updated session-jobs

Revision history for this message
James Hunt (jamesodhunt) wrote :

OK. We've now set precedent by adding other session jobs to extra/conf-session/ so LGTM. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extra/man/dbus-event.7'
2--- extra/man/dbus-event.7 2013-07-24 04:45:34 +0000
3+++ extra/man/dbus-event.7 2013-07-24 04:45:34 +0000
4@@ -11,6 +11,8 @@
5 .BI PATH\fR= PATH
6 .BI SENDER\fR= SENDER
7 .BI DESTINATION\fR= DESTINATION
8+.BI ARG0\fR= VALUE
9+.BI ARGN\fR= VALUE
10 .\"
11 .SH DESCRIPTION
12
13@@ -26,6 +28,8 @@
14 .B stop on
15 stanza is modified.
16
17+Arguments that are simple types (string, int, etc.) are translated into strings and placed as parameters on the event with the pattern ARG and the number representing the placement in the event prototype. Parameters that are not a simple type are skipped, with the number being incremented the same.
18+
19 The
20 .B BUS
21 parameter is optional and only set if the
22@@ -39,7 +43,7 @@
23 .\"
24 .SH EXAMPLES
25 .\"
26-.IP "start on dbus SIGNAL=NameAcquired INTERFACE=org.freedesktop.DBus PATH=/org/freedesktop/DBus SENDER=org.freedesktop.DBus"
27+.IP "start on dbus SIGNAL=NameAcquired INTERFACE=org.freedesktop.DBus PATH=/org/freedesktop/DBus SENDER=org.freedesktop.DBus ARG0=com.mycorp.foo"
28 Start job when a particular
29 .I NameAcquired
30 D-Bus signal is received.
31
32=== modified file 'extra/upstart-dbus-bridge.c'
33--- extra/upstart-dbus-bridge.c 2013-07-24 04:45:34 +0000
34+++ extra/upstart-dbus-bridge.c 2013-07-24 04:45:34 +0000
35@@ -443,6 +443,7 @@
36 int emit = FALSE;
37 DBusPendingCall *pending_call;
38 DBusError error;
39+ DBusMessageIter message_iter;
40 nih_local char **env = NULL;
41 const char *sender;
42 const char *destination;
43@@ -527,6 +528,97 @@
44 NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, var));
45 }
46
47+ if (dbus_message_iter_init (message, &message_iter)) {
48+ int current_type = DBUS_TYPE_INVALID;
49+ int arg_num = 0;
50+
51+ while ((current_type = dbus_message_iter_get_arg_type(&message_iter)) != DBUS_TYPE_INVALID) {
52+ nih_local char *var = NULL;
53+
54+ switch (current_type) {
55+ case DBUS_TYPE_BOOLEAN: {
56+ dbus_bool_t arg = 0;
57+ dbus_message_iter_get_basic(&message_iter, &arg);
58+
59+ var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%s", arg_num, arg ? "TRUE" : "FALSE"));
60+ break;
61+ }
62+ case DBUS_TYPE_INT16: {
63+ dbus_int16_t arg = 0;
64+ dbus_message_iter_get_basic(&message_iter, &arg);
65+
66+ var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%u", arg_num, arg));
67+ break;
68+ }
69+ case DBUS_TYPE_UINT16: {
70+ dbus_uint16_t arg = 0;
71+ dbus_message_iter_get_basic(&message_iter, &arg);
72+
73+ var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%d", arg_num, arg));
74+ break;
75+ }
76+ case DBUS_TYPE_INT32: {
77+ dbus_int32_t arg = 0;
78+ dbus_message_iter_get_basic(&message_iter, &arg);
79+
80+ var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%d", arg_num, arg));
81+ break;
82+ }
83+ case DBUS_TYPE_UINT32: {
84+ dbus_uint32_t arg = 0;
85+ dbus_message_iter_get_basic(&message_iter, &arg);
86+
87+ var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%u", arg_num, arg));
88+ break;
89+ }
90+ case DBUS_TYPE_INT64: {
91+ dbus_int64_t arg = 0;
92+ dbus_message_iter_get_basic(&message_iter, &arg);
93+
94+ var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%ld", arg_num, arg));
95+ break;
96+ }
97+ case DBUS_TYPE_UINT64: {
98+ dbus_uint64_t arg = 0;
99+ dbus_message_iter_get_basic(&message_iter, &arg);
100+
101+ var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%lu", arg_num, arg));
102+ break;
103+ }
104+ case DBUS_TYPE_DOUBLE: {
105+ double arg = 0;
106+ dbus_message_iter_get_basic(&message_iter, &arg);
107+
108+ var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%f", arg_num, arg));
109+ break;
110+ }
111+ case DBUS_TYPE_STRING: {
112+ const char * arg = NULL;
113+ dbus_message_iter_get_basic(&message_iter, &arg);
114+
115+ var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%s", arg_num, arg));
116+ break;
117+ }
118+ case DBUS_TYPE_OBJECT_PATH: {
119+ const char * arg = NULL;
120+ dbus_message_iter_get_basic(&message_iter, &arg);
121+
122+ var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%s", arg_num, arg));
123+ break;
124+ }
125+ /* NOTE: Only supporting strings for now, we can consider other
126+ types in the future by extending this switch */
127+ }
128+
129+ if (var != NULL) {
130+ NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, var));
131+ }
132+
133+ dbus_message_iter_next(&message_iter);
134+ arg_num++;
135+ }
136+ }
137+
138 nih_debug ("Received D-Bus signal: %s "
139 "(sender=%s, destination=%s, interface=%s, path=%s)",
140 signal ? signal : "",

Subscribers

People subscribed via source and target branches