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
=== modified file 'extra/Makefile.am'
--- extra/Makefile.am 2013-10-31 18:19:46 +0000
+++ extra/Makefile.am 2015-01-11 01:45:53 +0000
@@ -23,6 +23,7 @@
23 conf-session/upstart-event-bridge.conf \23 conf-session/upstart-event-bridge.conf \
24 conf-session/upstart-file-bridge.conf \24 conf-session/upstart-file-bridge.conf \
25 conf-session/re-exec.conf \25 conf-session/re-exec.conf \
26 conf-session/upstart-udev-bridge.conf \
26 conf-session/upstart-dbus-session-bridge.conf \27 conf-session/upstart-dbus-session-bridge.conf \
27 conf-session/upstart-dbus-system-bridge.conf28 conf-session/upstart-dbus-system-bridge.conf
2829
@@ -33,7 +34,6 @@
3334
34dist_init_DATA = \35dist_init_DATA = \
35 conf/upstart-socket-bridge.conf \36 conf/upstart-socket-bridge.conf \
36 conf/upstart-event-bridge.conf \
37 conf/upstart-file-bridge.conf \37 conf/upstart-file-bridge.conf \
38 conf/upstart-dbus-bridge.conf38 conf/upstart-dbus-bridge.conf
3939
4040
=== added file 'extra/conf-session/upstart-udev-bridge.conf'
--- extra/conf-session/upstart-udev-bridge.conf 1970-01-01 00:00:00 +0000
+++ extra/conf-session/upstart-udev-bridge.conf 2015-01-11 01:45:53 +0000
@@ -0,0 +1,22 @@
1# upstart-udev-bridge - Bridge udev events into session upstart
2#
3# This helper daemon receives udev events from the netlink socket and
4# emits equivalent Upstart events.
5
6description "Bridge udev events into upstart"
7
8# From upstart-udev-bridge itself
9emits *-device-added
10emits *-device-removed
11emits *-device-changed
12# From http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/libudev-udev-device.html
13emits *-device-online
14emits *-device-offline
15
16start on starting udev
17stop on stopped udev
18
19expect daemon
20respawn
21
22exec upstart-udev-bridge --daemon --user
023
=== removed file 'extra/conf/upstart-event-bridge.conf'
--- extra/conf/upstart-event-bridge.conf 2013-01-22 20:08:29 +0000
+++ extra/conf/upstart-event-bridge.conf 1970-01-01 00:00:00 +0000
@@ -1,15 +0,0 @@
1# upstart-event-bridge - Bridge system upstarts events into session upstart
2#
3# This helper daemon receives system upstart events from the DBus system bus
4# and emits equivalent events (with a :sys:) prefix to the session bus
5
6description "Bridge Upstart system events into session Upstart"
7
8emits :sys:*
9
10start on started dbus
11stop on stopped dbus
12
13respawn
14
15exec upstart-event-bridge
160
=== modified file 'extra/upstart-local-bridge.c'
--- extra/upstart-local-bridge.c 2013-10-04 21:34:25 +0000
+++ extra/upstart-local-bridge.c 2015-01-11 01:45:53 +0000
@@ -48,21 +48,6 @@
4848
49#include "dbus/upstart.h"49#include "dbus/upstart.h"
50#include "com.ubuntu.Upstart.h"50#include "com.ubuntu.Upstart.h"
51#include "com.ubuntu.Upstart.Job.h"
52
53/**
54 * Job:
55 *
56 * @entry: list header,
57 * @path: D-Bus path for a job.
58 *
59 * Representation of an Upstart Job.
60 *
61 **/
62typedef struct job {
63 NihList entry;
64 char *path;
65} Job;
6651
67/**52/**
68 * Socket:53 * Socket:
@@ -100,10 +85,6 @@
100 struct ucred ucred;85 struct ucred ucred;
101} ClientConnection;86} ClientConnection;
10287
103static void upstart_job_added (void *data, NihDBusMessage *message,
104 const char *job);
105static void upstart_job_removed (void *data, NihDBusMessage *message,
106 const char *job);
107static void upstart_connect (void);88static void upstart_connect (void);
108static void upstart_disconnected (DBusConnection *connection);89static void upstart_disconnected (DBusConnection *connection);
10990
@@ -134,13 +115,6 @@
134static int daemonise = FALSE;115static int daemonise = FALSE;
135116
136/**117/**
137 * jobs:
138 *
139 * Jobs that we're monitoring.
140 **/
141static NihHash *jobs = NULL;
142
143/**
144 * upstart:118 * upstart:
145 *119 *
146 * Proxy to Upstart daemon.120 * Proxy to Upstart daemon.
@@ -273,9 +247,6 @@
273 exit (1);247 exit (1);
274 }248 }
275249
276 /* Allocate jobs hash table */
277 jobs = NIH_MUST (nih_hash_string_new (NULL, 0));
278
279 sock = create_socket (NULL);250 sock = create_socket (NULL);
280 if (! sock) {251 if (! sock) {
281 nih_fatal ("%s %s",252 nih_fatal ("%s %s",
@@ -326,100 +297,11 @@
326 return ret;297 return ret;
327}298}
328299
329static void
330upstart_job_added (void *data,
331 NihDBusMessage *message,
332 const char *job_class_path)
333{
334 nih_local NihDBusProxy *job_class = NULL;
335 nih_local char ***start_on = NULL;
336 nih_local char ***stop_on = NULL;
337 Job *job;
338
339 nih_assert (job_class_path != NULL);
340
341 /* Obtain a proxy to the job */
342 job_class = nih_dbus_proxy_new (NULL, upstart->connection,
343 upstart->name, job_class_path,
344 NULL, NULL);
345 if (! job_class) {
346 NihError *err;
347
348 err = nih_error_get ();
349 nih_error ("Could not create proxy for job %s: %s",
350 job_class_path, err->message);
351 nih_free (err);
352
353 return;
354 }
355
356 job_class->auto_start = FALSE;
357
358 /* Obtain the start_on and stop_on properties of the job */
359 if (job_class_get_start_on_sync (NULL, job_class, &start_on) < 0) {
360 NihError *err;
361
362 err = nih_error_get ();
363 nih_error ("Could not obtain job start condition %s: %s",
364 job_class_path, err->message);
365 nih_free (err);
366
367 return;
368 }
369
370 if (job_class_get_stop_on_sync (NULL, job_class, &stop_on) < 0) {
371 NihError *err;
372
373 err = nih_error_get ();
374 nih_error ("Could not obtain job stop condition %s: %s",
375 job_class_path, err->message);
376 nih_free (err);
377
378 return;
379 }
380
381 /* Free any existing record for the job (should never happen,
382 * but worth being safe).
383 */
384 job = (Job *)nih_hash_lookup (jobs, job_class_path);
385 if (job)
386 nih_free (job);
387
388 /* Create new record for the job */
389 job = NIH_MUST (nih_new (NULL, Job));
390 job->path = NIH_MUST (nih_strdup (job, job_class_path));
391
392 nih_list_init (&job->entry);
393
394 nih_debug ("Job got added %s", job_class_path);
395
396 nih_alloc_set_destructor (job, nih_list_destroy);
397
398 /* Add all jobs */
399 nih_hash_add (jobs, &job->entry);
400}
401
402static void
403upstart_job_removed (void *data,
404 NihDBusMessage *message,
405 const char *job_path)
406{
407 Job *job;
408
409 nih_assert (job_path != NULL);
410
411 job = (Job *)nih_hash_lookup (jobs, job_path);
412 if (job) {
413 nih_debug ("Job went away %s", job_path);
414 nih_free (job);
415 }
416}
417300
418static void301static void
419upstart_connect (void)302upstart_connect (void)
420{303{
421 DBusConnection *connection;304 DBusConnection *connection;
422 char **job_class_paths;
423305
424 /* Initialise the connection to Upstart */306 /* Initialise the connection to Upstart */
425 connection = NIH_SHOULD (nih_dbus_connect (DBUS_ADDRESS_UPSTART, upstart_disconnected));307 connection = NIH_SHOULD (nih_dbus_connect (DBUS_ADDRESS_UPSTART, upstart_disconnected));
@@ -449,49 +331,6 @@
449 }331 }
450332
451 nih_debug ("Connected to Upstart");333 nih_debug ("Connected to Upstart");
452
453 /* Connect signals to be notified when jobs come and go */
454 if (! nih_dbus_proxy_connect (upstart, &upstart_com_ubuntu_Upstart0_6, "JobAdded",
455 (NihDBusSignalHandler)upstart_job_added, NULL)) {
456 NihError *err;
457
458 err = nih_error_get ();
459 nih_fatal ("%s: %s", _("Could not create JobAdded signal connection"),
460 err->message);
461 nih_free (err);
462
463 exit (1);
464 }
465
466 if (! nih_dbus_proxy_connect (upstart, &upstart_com_ubuntu_Upstart0_6, "JobRemoved",
467 (NihDBusSignalHandler)upstart_job_removed, NULL)) {
468 NihError *err;
469
470 err = nih_error_get ();
471 nih_fatal ("%s: %s", _("Could not create JobRemoved signal connection"),
472 err->message);
473 nih_free (err);
474
475 exit (1);
476 }
477
478 /* Request a list of all current jobs */
479 if (upstart_get_all_jobs_sync (NULL, upstart, &job_class_paths) < 0) {
480 NihError *err;
481
482 err = nih_error_get ();
483 nih_fatal ("%s: %s", _("Could not obtain job list"),
484 err->message);
485 nih_free (err);
486
487 exit (1);
488 }
489
490 for (char **job_class_path = job_class_paths;
491 job_class_path && *job_class_path; job_class_path++)
492 upstart_job_added (NULL, NULL, *job_class_path);
493
494 nih_free (job_class_paths);
495}334}
496335
497static void336static void
498337
=== modified file 'extra/upstart-udev-bridge.c'
--- extra/upstart-udev-bridge.c 2011-12-15 16:14:06 +0000
+++ extra/upstart-udev-bridge.c 2015-01-11 01:45:53 +0000
@@ -69,6 +69,15 @@
69static NihDBusProxy *upstart = NULL;69static NihDBusProxy *upstart = NULL;
7070
71/**71/**
72 * user:
73 *
74 * If TRUE, run in User Session mode connecting to the Session Init
75 * rather than PID 1. In this mode, certain relative paths are also
76 * expanded.
77 **/
78static int user = FALSE;
79
80/**
72 * no_strip_udev_data:81 * no_strip_udev_data:
73 *82 *
74 * If TRUE, do not modify any udev message data (old behaviour).83 * If TRUE, do not modify any udev message data (old behaviour).
@@ -86,6 +95,8 @@
86 NULL, NULL, &daemonise, NULL },95 NULL, NULL, &daemonise, NULL },
87 { 0, "no-strip", N_("Do not strip non-printable bytes from udev message data"),96 { 0, "no-strip", N_("Do not strip non-printable bytes from udev message data"),
88 NULL, NULL, &no_strip_udev_data, NULL },97 NULL, NULL, &no_strip_udev_data, NULL },
98 { 0, "user", N_("Connect to user session"),
99 NULL, NULL, &user, NULL },
89100
90 NIH_OPTION_LAST101 NIH_OPTION_LAST
91};102};
@@ -97,6 +108,11 @@
97{108{
98 char ** args;109 char ** args;
99 DBusConnection * connection;110 DBusConnection * connection;
111 char * pidfile_path = NULL;
112 char * pidfile = NULL;
113 char *user_session_addr = NULL;
114 nih_local char ** user_session_path = NULL;
115 char * path_element = NULL;
100 struct udev * udev;116 struct udev * udev;
101 struct udev_monitor *udev_monitor;117 struct udev_monitor *udev_monitor;
102 int ret;118 int ret;
@@ -113,8 +129,19 @@
113 if (! args)129 if (! args)
114 exit (1);130 exit (1);
115131
132 if (user) {
133 user_session_addr = getenv ("UPSTART_SESSION");
134 if (! user_session_addr) {
135 nih_fatal (_("UPSTART_SESSION isn't set in environment"));
136 exit (EXIT_FAILURE);
137 }
138 }
139
116 /* Initialise the connection to Upstart */140 /* Initialise the connection to Upstart */
117 connection = NIH_SHOULD (nih_dbus_connect (DBUS_ADDRESS_UPSTART, upstart_disconnected));141 connection = NIH_SHOULD (nih_dbus_connect (user
142 ? user_session_addr
143 : DBUS_ADDRESS_UPSTART,
144 upstart_disconnected));
118 if (! connection) {145 if (! connection) {
119 NihError *err;146 NihError *err;
120147
@@ -153,6 +180,35 @@
153180
154 /* Become daemon */181 /* Become daemon */
155 if (daemonise) {182 if (daemonise) {
183 /* Deal with the pidfile location when becoming a daemon.
184 * We need to be able to run one bridge per upstart daemon.
185 * Store the PID file in XDG_RUNTIME_DIR or HOME and include the pid of
186 * the Upstart instance (last part of the DBus path) in the filename.
187 */
188
189 if (user) {
190 /* Extract PID from UPSTART_SESSION */
191 user_session_path = nih_str_split (NULL, user_session_addr, "/", TRUE);
192
193 for (int i = 0; user_session_path && user_session_path[i]; i++)
194 path_element = user_session_path[i];
195
196 if (! path_element) {
197 nih_fatal (_("Invalid value for UPSTART_SESSION"));
198 exit (1);
199 }
200
201 pidfile_path = getenv ("XDG_RUNTIME_DIR");
202 if (!pidfile_path)
203 pidfile_path = getenv ("HOME");
204
205 if (pidfile_path) {
206 NIH_MUST (nih_strcat_sprintf (&pidfile, NULL, "%s/%s.%s.pid",
207 pidfile_path, program_invocation_short_name, path_element));
208 nih_main_set_pidfile (pidfile);
209 }
210 }
211
156 if (nih_main_daemonise () < 0) {212 if (nih_main_daemonise () < 0) {
157 NihError *err;213 NihError *err;
158214
@@ -163,10 +219,12 @@
163219
164 exit (1);220 exit (1);
165 }221 }
166222
167 /* Send all logging output to syslog */223 if (!user) {
168 openlog (program_name, LOG_PID, LOG_DAEMON);224 /* Send all logging output to syslog for system bridge */
169 nih_log_set_logger (nih_logger_syslog);225 openlog (program_name, LOG_PID, LOG_DAEMON);
226 nih_log_set_logger (nih_logger_syslog);
227 }
170 }228 }
171229
172 /* Handle TERM and INT signals gracefully */230 /* Handle TERM and INT signals gracefully */

Subscribers

People subscribed via source and target branches