Merge lp:~xnox/upstart/no-classes into lp:upstart

Proposed by Dimitri John Ledkov
Status: Rejected
Rejected by: Dimitri John Ledkov
Proposed branch: lp:~xnox/upstart/no-classes
Merge into: lp:upstart
Diff against target: 393 lines (+86/-182)
5 files modified
extra/Makefile.am (+1/-1)
extra/conf-session/upstart-udev-bridge.conf (+22/-0)
extra/conf/upstart-event-bridge.conf (+0/-15)
extra/upstart-local-bridge.c (+0/-161)
extra/upstart-udev-bridge.c (+63/-5)
To merge this branch: bzr merge lp:~xnox/upstart/no-classes
Reviewer Review Type Date Requested Status
James Hunt Pending
Martin Pitt Pending
Upstart Reviewers Pending
Review via email: mp+245948@code.launchpad.net
To post a comment you must log in.
lp:~xnox/upstart/no-classes updated
1666. By Dimitri John Ledkov

Make udev-bridge suitable for user sessions.

1667. By Dimitri John Ledkov

upstart-event-bridge makes no-sense on the system init.

1668. By Dimitri John Ledkov

Implement user pidfile handling, and skip syslog for user daemon.

Unmerged revisions

1668. By Dimitri John Ledkov

Implement user pidfile handling, and skip syslog for user daemon.

1667. By Dimitri John Ledkov

upstart-event-bridge makes no-sense on the system init.

1666. By Dimitri John Ledkov

Make udev-bridge suitable for user sessions.

1665. By Dimitri John Ledkov

upstart-local-bridge: drop unused job-class parsing code.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extra/Makefile.am'
2--- extra/Makefile.am 2013-10-31 18:19:46 +0000
3+++ extra/Makefile.am 2015-01-11 01:45:53 +0000
4@@ -23,6 +23,7 @@
5 conf-session/upstart-event-bridge.conf \
6 conf-session/upstart-file-bridge.conf \
7 conf-session/re-exec.conf \
8+ conf-session/upstart-udev-bridge.conf \
9 conf-session/upstart-dbus-session-bridge.conf \
10 conf-session/upstart-dbus-system-bridge.conf
11
12@@ -33,7 +34,6 @@
13
14 dist_init_DATA = \
15 conf/upstart-socket-bridge.conf \
16- conf/upstart-event-bridge.conf \
17 conf/upstart-file-bridge.conf \
18 conf/upstart-dbus-bridge.conf
19
20
21=== added file 'extra/conf-session/upstart-udev-bridge.conf'
22--- extra/conf-session/upstart-udev-bridge.conf 1970-01-01 00:00:00 +0000
23+++ extra/conf-session/upstart-udev-bridge.conf 2015-01-11 01:45:53 +0000
24@@ -0,0 +1,22 @@
25+# upstart-udev-bridge - Bridge udev events into session upstart
26+#
27+# This helper daemon receives udev events from the netlink socket and
28+# emits equivalent Upstart events.
29+
30+description "Bridge udev events into upstart"
31+
32+# From upstart-udev-bridge itself
33+emits *-device-added
34+emits *-device-removed
35+emits *-device-changed
36+# From http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/libudev-udev-device.html
37+emits *-device-online
38+emits *-device-offline
39+
40+start on starting udev
41+stop on stopped udev
42+
43+expect daemon
44+respawn
45+
46+exec upstart-udev-bridge --daemon --user
47
48=== removed file 'extra/conf/upstart-event-bridge.conf'
49--- extra/conf/upstart-event-bridge.conf 2013-01-22 20:08:29 +0000
50+++ extra/conf/upstart-event-bridge.conf 1970-01-01 00:00:00 +0000
51@@ -1,15 +0,0 @@
52-# upstart-event-bridge - Bridge system upstarts events into session upstart
53-#
54-# This helper daemon receives system upstart events from the DBus system bus
55-# and emits equivalent events (with a :sys:) prefix to the session bus
56-
57-description "Bridge Upstart system events into session Upstart"
58-
59-emits :sys:*
60-
61-start on started dbus
62-stop on stopped dbus
63-
64-respawn
65-
66-exec upstart-event-bridge
67
68=== modified file 'extra/upstart-local-bridge.c'
69--- extra/upstart-local-bridge.c 2013-10-04 21:34:25 +0000
70+++ extra/upstart-local-bridge.c 2015-01-11 01:45:53 +0000
71@@ -48,21 +48,6 @@
72
73 #include "dbus/upstart.h"
74 #include "com.ubuntu.Upstart.h"
75-#include "com.ubuntu.Upstart.Job.h"
76-
77-/**
78- * Job:
79- *
80- * @entry: list header,
81- * @path: D-Bus path for a job.
82- *
83- * Representation of an Upstart Job.
84- *
85- **/
86-typedef struct job {
87- NihList entry;
88- char *path;
89-} Job;
90
91 /**
92 * Socket:
93@@ -100,10 +85,6 @@
94 struct ucred ucred;
95 } ClientConnection;
96
97-static void upstart_job_added (void *data, NihDBusMessage *message,
98- const char *job);
99-static void upstart_job_removed (void *data, NihDBusMessage *message,
100- const char *job);
101 static void upstart_connect (void);
102 static void upstart_disconnected (DBusConnection *connection);
103
104@@ -134,13 +115,6 @@
105 static int daemonise = FALSE;
106
107 /**
108- * jobs:
109- *
110- * Jobs that we're monitoring.
111- **/
112-static NihHash *jobs = NULL;
113-
114-/**
115 * upstart:
116 *
117 * Proxy to Upstart daemon.
118@@ -273,9 +247,6 @@
119 exit (1);
120 }
121
122- /* Allocate jobs hash table */
123- jobs = NIH_MUST (nih_hash_string_new (NULL, 0));
124-
125 sock = create_socket (NULL);
126 if (! sock) {
127 nih_fatal ("%s %s",
128@@ -326,100 +297,11 @@
129 return ret;
130 }
131
132-static void
133-upstart_job_added (void *data,
134- NihDBusMessage *message,
135- const char *job_class_path)
136-{
137- nih_local NihDBusProxy *job_class = NULL;
138- nih_local char ***start_on = NULL;
139- nih_local char ***stop_on = NULL;
140- Job *job;
141-
142- nih_assert (job_class_path != NULL);
143-
144- /* Obtain a proxy to the job */
145- job_class = nih_dbus_proxy_new (NULL, upstart->connection,
146- upstart->name, job_class_path,
147- NULL, NULL);
148- if (! job_class) {
149- NihError *err;
150-
151- err = nih_error_get ();
152- nih_error ("Could not create proxy for job %s: %s",
153- job_class_path, err->message);
154- nih_free (err);
155-
156- return;
157- }
158-
159- job_class->auto_start = FALSE;
160-
161- /* Obtain the start_on and stop_on properties of the job */
162- if (job_class_get_start_on_sync (NULL, job_class, &start_on) < 0) {
163- NihError *err;
164-
165- err = nih_error_get ();
166- nih_error ("Could not obtain job start condition %s: %s",
167- job_class_path, err->message);
168- nih_free (err);
169-
170- return;
171- }
172-
173- if (job_class_get_stop_on_sync (NULL, job_class, &stop_on) < 0) {
174- NihError *err;
175-
176- err = nih_error_get ();
177- nih_error ("Could not obtain job stop condition %s: %s",
178- job_class_path, err->message);
179- nih_free (err);
180-
181- return;
182- }
183-
184- /* Free any existing record for the job (should never happen,
185- * but worth being safe).
186- */
187- job = (Job *)nih_hash_lookup (jobs, job_class_path);
188- if (job)
189- nih_free (job);
190-
191- /* Create new record for the job */
192- job = NIH_MUST (nih_new (NULL, Job));
193- job->path = NIH_MUST (nih_strdup (job, job_class_path));
194-
195- nih_list_init (&job->entry);
196-
197- nih_debug ("Job got added %s", job_class_path);
198-
199- nih_alloc_set_destructor (job, nih_list_destroy);
200-
201- /* Add all jobs */
202- nih_hash_add (jobs, &job->entry);
203-}
204-
205-static void
206-upstart_job_removed (void *data,
207- NihDBusMessage *message,
208- const char *job_path)
209-{
210- Job *job;
211-
212- nih_assert (job_path != NULL);
213-
214- job = (Job *)nih_hash_lookup (jobs, job_path);
215- if (job) {
216- nih_debug ("Job went away %s", job_path);
217- nih_free (job);
218- }
219-}
220
221 static void
222 upstart_connect (void)
223 {
224 DBusConnection *connection;
225- char **job_class_paths;
226
227 /* Initialise the connection to Upstart */
228 connection = NIH_SHOULD (nih_dbus_connect (DBUS_ADDRESS_UPSTART, upstart_disconnected));
229@@ -449,49 +331,6 @@
230 }
231
232 nih_debug ("Connected to Upstart");
233-
234- /* Connect signals to be notified when jobs come and go */
235- if (! nih_dbus_proxy_connect (upstart, &upstart_com_ubuntu_Upstart0_6, "JobAdded",
236- (NihDBusSignalHandler)upstart_job_added, NULL)) {
237- NihError *err;
238-
239- err = nih_error_get ();
240- nih_fatal ("%s: %s", _("Could not create JobAdded signal connection"),
241- err->message);
242- nih_free (err);
243-
244- exit (1);
245- }
246-
247- if (! nih_dbus_proxy_connect (upstart, &upstart_com_ubuntu_Upstart0_6, "JobRemoved",
248- (NihDBusSignalHandler)upstart_job_removed, NULL)) {
249- NihError *err;
250-
251- err = nih_error_get ();
252- nih_fatal ("%s: %s", _("Could not create JobRemoved signal connection"),
253- err->message);
254- nih_free (err);
255-
256- exit (1);
257- }
258-
259- /* Request a list of all current jobs */
260- if (upstart_get_all_jobs_sync (NULL, upstart, &job_class_paths) < 0) {
261- NihError *err;
262-
263- err = nih_error_get ();
264- nih_fatal ("%s: %s", _("Could not obtain job list"),
265- err->message);
266- nih_free (err);
267-
268- exit (1);
269- }
270-
271- for (char **job_class_path = job_class_paths;
272- job_class_path && *job_class_path; job_class_path++)
273- upstart_job_added (NULL, NULL, *job_class_path);
274-
275- nih_free (job_class_paths);
276 }
277
278 static void
279
280=== modified file 'extra/upstart-udev-bridge.c'
281--- extra/upstart-udev-bridge.c 2011-12-15 16:14:06 +0000
282+++ extra/upstart-udev-bridge.c 2015-01-11 01:45:53 +0000
283@@ -69,6 +69,15 @@
284 static NihDBusProxy *upstart = NULL;
285
286 /**
287+ * user:
288+ *
289+ * If TRUE, run in User Session mode connecting to the Session Init
290+ * rather than PID 1. In this mode, certain relative paths are also
291+ * expanded.
292+ **/
293+static int user = FALSE;
294+
295+/**
296 * no_strip_udev_data:
297 *
298 * If TRUE, do not modify any udev message data (old behaviour).
299@@ -86,6 +95,8 @@
300 NULL, NULL, &daemonise, NULL },
301 { 0, "no-strip", N_("Do not strip non-printable bytes from udev message data"),
302 NULL, NULL, &no_strip_udev_data, NULL },
303+ { 0, "user", N_("Connect to user session"),
304+ NULL, NULL, &user, NULL },
305
306 NIH_OPTION_LAST
307 };
308@@ -97,6 +108,11 @@
309 {
310 char ** args;
311 DBusConnection * connection;
312+ char * pidfile_path = NULL;
313+ char * pidfile = NULL;
314+ char *user_session_addr = NULL;
315+ nih_local char ** user_session_path = NULL;
316+ char * path_element = NULL;
317 struct udev * udev;
318 struct udev_monitor *udev_monitor;
319 int ret;
320@@ -113,8 +129,19 @@
321 if (! args)
322 exit (1);
323
324+ if (user) {
325+ user_session_addr = getenv ("UPSTART_SESSION");
326+ if (! user_session_addr) {
327+ nih_fatal (_("UPSTART_SESSION isn't set in environment"));
328+ exit (EXIT_FAILURE);
329+ }
330+ }
331+
332 /* Initialise the connection to Upstart */
333- connection = NIH_SHOULD (nih_dbus_connect (DBUS_ADDRESS_UPSTART, upstart_disconnected));
334+ connection = NIH_SHOULD (nih_dbus_connect (user
335+ ? user_session_addr
336+ : DBUS_ADDRESS_UPSTART,
337+ upstart_disconnected));
338 if (! connection) {
339 NihError *err;
340
341@@ -153,6 +180,35 @@
342
343 /* Become daemon */
344 if (daemonise) {
345+ /* Deal with the pidfile location when becoming a daemon.
346+ * We need to be able to run one bridge per upstart daemon.
347+ * Store the PID file in XDG_RUNTIME_DIR or HOME and include the pid of
348+ * the Upstart instance (last part of the DBus path) in the filename.
349+ */
350+
351+ if (user) {
352+ /* Extract PID from UPSTART_SESSION */
353+ user_session_path = nih_str_split (NULL, user_session_addr, "/", TRUE);
354+
355+ for (int i = 0; user_session_path && user_session_path[i]; i++)
356+ path_element = user_session_path[i];
357+
358+ if (! path_element) {
359+ nih_fatal (_("Invalid value for UPSTART_SESSION"));
360+ exit (1);
361+ }
362+
363+ pidfile_path = getenv ("XDG_RUNTIME_DIR");
364+ if (!pidfile_path)
365+ pidfile_path = getenv ("HOME");
366+
367+ if (pidfile_path) {
368+ NIH_MUST (nih_strcat_sprintf (&pidfile, NULL, "%s/%s.%s.pid",
369+ pidfile_path, program_invocation_short_name, path_element));
370+ nih_main_set_pidfile (pidfile);
371+ }
372+ }
373+
374 if (nih_main_daemonise () < 0) {
375 NihError *err;
376
377@@ -163,10 +219,12 @@
378
379 exit (1);
380 }
381-
382- /* Send all logging output to syslog */
383- openlog (program_name, LOG_PID, LOG_DAEMON);
384- nih_log_set_logger (nih_logger_syslog);
385+
386+ if (!user) {
387+ /* Send all logging output to syslog for system bridge */
388+ openlog (program_name, LOG_PID, LOG_DAEMON);
389+ nih_log_set_logger (nih_logger_syslog);
390+ }
391 }
392
393 /* Handle TERM and INT signals gracefully */

Subscribers

People subscribed via source and target branches