~daniel-sonck/upstart/cron-replacement

« back to all changes in this revision

Viewing changes to extra/upstart-socket-bridge.c

  • Committer: dsonck
  • Date: 2011-10-14 14:32:00 UTC
  • mfrom: (1282.1.47 upstart)
  • Revision ID: dsonck@daniel-desktop-20111014143200-ezekcd0k43ykog2l
Merged with the latest startup branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* upstart
 
2
 *
 
3
 * Copyright © 2010 Canonical Ltd.
 
4
 * Author: Scott James Remnant <scott@netsplit.com>.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License version 2, as
 
8
 * published by the Free Software Foundation.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License along
 
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
18
 */
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
# include <config.h>
 
22
#endif /* HAVE_CONFIG_H */
 
23
 
 
24
 
 
25
#include <sys/epoll.h>
 
26
#include <sys/types.h>
 
27
#include <sys/socket.h>
 
28
#include <sys/un.h>
 
29
 
 
30
#include <netinet/in.h>
 
31
#include <arpa/inet.h>
 
32
 
 
33
#include <errno.h>
 
34
#include <stdlib.h>
 
35
#include <string.h>
 
36
#include <syslog.h>
 
37
#include <unistd.h>
 
38
 
 
39
#include <nih/macros.h>
 
40
#include <nih/alloc.h>
 
41
#include <nih/list.h>
 
42
#include <nih/hash.h>
 
43
#include <nih/string.h>
 
44
#include <nih/io.h>
 
45
#include <nih/option.h>
 
46
#include <nih/main.h>
 
47
#include <nih/logging.h>
 
48
#include <nih/error.h>
 
49
 
 
50
#include <nih-dbus/dbus_connection.h>
 
51
#include <nih-dbus/dbus_proxy.h>
 
52
 
 
53
#include "dbus/upstart.h"
 
54
#include "com.ubuntu.Upstart.h"
 
55
#include "com.ubuntu.Upstart.Job.h"
 
56
 
 
57
 
 
58
/* Structure we use for tracking jobs */
 
59
typedef struct job {
 
60
        NihList entry;
 
61
        char *path;
 
62
        NihList sockets;
 
63
} Job;
 
64
 
 
65
/* Structure we use for tracking listening sockets */
 
66
typedef struct socket {
 
67
        NihList entry;
 
68
 
 
69
        union {
 
70
                struct sockaddr        addr;
 
71
                struct sockaddr_in sin_addr;
 
72
                struct sockaddr_un sun_addr;
 
73
        };
 
74
        socklen_t addrlen;
 
75
 
 
76
        int sock;
 
77
} Socket;
 
78
 
 
79
 
 
80
/* Prototypes for static functions */
 
81
static void epoll_watcher        (void *data, NihIoWatch *watch,
 
82
                                  NihIoEvents events);
 
83
static void upstart_job_added    (void *data, NihDBusMessage *message,
 
84
                                  const char *job);
 
85
static void upstart_job_removed  (void *data, NihDBusMessage *message,
 
86
                                  const char *job);
 
87
static void job_add_socket       (Job *job, char **socket_info);
 
88
static void socket_destroy       (Socket *socket);
 
89
static void upstart_disconnected (DBusConnection *connection);
 
90
static void emit_event_reply     (Socket *sock, NihDBusMessage *message);
 
91
static void emit_event_error     (Socket *sock, NihDBusMessage *message);
 
92
 
 
93
 
 
94
/**
 
95
 * daemonise:
 
96
 *
 
97
 * Set to TRUE if we should become a daemon, rather than just running
 
98
 * in the foreground.
 
99
 **/
 
100
static int daemonise = FALSE;
 
101
 
 
102
/**
 
103
 * epoll_fd:
 
104
 *
 
105
 * Shared epoll file descriptor for listening on.
 
106
 **/
 
107
static int epoll_fd = -1;
 
108
 
 
109
/**
 
110
 * jobs:
 
111
 *
 
112
 * Jobs that we're monitoring.
 
113
 **/
 
114
static NihHash *jobs = NULL;
 
115
 
 
116
/**
 
117
 * upstart:
 
118
 *
 
119
 * Proxy to Upstart daemon.
 
120
 **/
 
121
static NihDBusProxy *upstart = NULL;
 
122
 
 
123
 
 
124
/**
 
125
 * options:
 
126
 *
 
127
 * Command-line options accepted by this program.
 
128
 **/
 
129
static NihOption options[] = {
 
130
        { 0, "daemon", N_("Detach and run in the background"),
 
131
          NULL, NULL, &daemonise, NULL },
 
132
 
 
133
        NIH_OPTION_LAST
 
134
};
 
135
 
 
136
 
 
137
int
 
138
main (int   argc,
 
139
      char *argv[])
 
140
{
 
141
        char **         args;
 
142
        DBusConnection *connection;
 
143
        char **         job_class_paths;
 
144
        int             ret;
 
145
 
 
146
        nih_main_init (argv[0]);
 
147
 
 
148
        nih_option_set_synopsis (_("Bridge socket events into upstart"));
 
149
        nih_option_set_help (
 
150
                _("By default, upstart-socket-bridge does not detach from the "
 
151
                  "console and remains in the foreground.  Use the --daemon "
 
152
                  "option to have it detach."));
 
153
 
 
154
        args = nih_option_parser (NULL, argc, argv, options, FALSE);
 
155
        if (! args)
 
156
                exit (1);
 
157
 
 
158
        /* Create an epoll file descriptor for listening on; use this so
 
159
         * we can do edge triggering rather than level.
 
160
         */
 
161
        epoll_fd = epoll_create1 (0);
 
162
        if (epoll_fd < 0) {
 
163
                nih_fatal ("%s: %s", _("Could not create epoll descriptor"),
 
164
                           strerror (errno));
 
165
                exit (1);
 
166
        }
 
167
 
 
168
        NIH_MUST (nih_io_add_watch (NULL, epoll_fd, NIH_IO_READ,
 
169
                                    epoll_watcher, NULL));
 
170
 
 
171
        /* Allocate jobs hash table */
 
172
        jobs = NIH_MUST (nih_hash_string_new (NULL, 0));
 
173
 
 
174
        /* Initialise the connection to Upstart */
 
175
        connection = NIH_SHOULD (nih_dbus_connect (DBUS_ADDRESS_UPSTART, upstart_disconnected));
 
176
        if (! connection) {
 
177
                NihError *err;
 
178
 
 
179
                err = nih_error_get ();
 
180
                nih_fatal ("%s: %s", _("Could not connect to Upstart"),
 
181
                           err->message);
 
182
                nih_free (err);
 
183
 
 
184
                exit (1);
 
185
        }
 
186
 
 
187
        upstart = NIH_SHOULD (nih_dbus_proxy_new (NULL, connection,
 
188
                                                  NULL, DBUS_PATH_UPSTART,
 
189
                                                  NULL, NULL));
 
190
        if (! upstart) {
 
191
                NihError *err;
 
192
 
 
193
                err = nih_error_get ();
 
194
                nih_fatal ("%s: %s", _("Could not create Upstart proxy"),
 
195
                           err->message);
 
196
                nih_free (err);
 
197
 
 
198
                exit (1);
 
199
        }
 
200
 
 
201
        /* Connect signals to be notified when jobs come and go */
 
202
        if (! nih_dbus_proxy_connect (upstart, &upstart_com_ubuntu_Upstart0_6, "JobAdded",
 
203
                                      (NihDBusSignalHandler)upstart_job_added, NULL)) {
 
204
                NihError *err;
 
205
 
 
206
                err = nih_error_get ();
 
207
                nih_fatal ("%s: %s", _("Could not create JobAdded signal connection"),
 
208
                           err->message);
 
209
                nih_free (err);
 
210
 
 
211
                exit (1);
 
212
        }
 
213
 
 
214
        if (! nih_dbus_proxy_connect (upstart, &upstart_com_ubuntu_Upstart0_6, "JobRemoved",
 
215
                                      (NihDBusSignalHandler)upstart_job_removed, NULL)) {
 
216
                NihError *err;
 
217
 
 
218
                err = nih_error_get ();
 
219
                nih_fatal ("%s: %s", _("Could not create JobRemoved signal connection"),
 
220
                           err->message);
 
221
                nih_free (err);
 
222
 
 
223
                exit (1);
 
224
        }
 
225
 
 
226
        /* Request a list of all current jobs */
 
227
        if (upstart_get_all_jobs_sync (NULL, upstart, &job_class_paths) < 0) {
 
228
                NihError *err;
 
229
 
 
230
                err = nih_error_get ();
 
231
                nih_fatal ("%s: %s", _("Could not obtain job list"),
 
232
                           err->message);
 
233
                nih_free (err);
 
234
 
 
235
                exit (1);
 
236
        }
 
237
 
 
238
        for (char **job_class_path = job_class_paths;
 
239
             job_class_path && *job_class_path; job_class_path++)
 
240
                upstart_job_added (NULL, NULL, *job_class_path);
 
241
 
 
242
        nih_free (job_class_paths);
 
243
 
 
244
        /* Become daemon */
 
245
        if (daemonise) {
 
246
                if (nih_main_daemonise () < 0) {
 
247
                        NihError *err;
 
248
 
 
249
                        err = nih_error_get ();
 
250
                        nih_fatal ("%s: %s", _("Unable to become daemon"),
 
251
                                   err->message);
 
252
                        nih_free (err);
 
253
 
 
254
                        exit (1);
 
255
                }
 
256
 
 
257
                /* Send all logging output to syslog */
 
258
                openlog (program_name, LOG_PID, LOG_DAEMON);
 
259
                nih_log_set_logger (nih_logger_syslog);
 
260
        }
 
261
 
 
262
        /* Handle TERM and INT signals gracefully */
 
263
        nih_signal_set_handler (SIGTERM, nih_signal_handler);
 
264
        NIH_MUST (nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL));
 
265
 
 
266
        if (! daemonise) {
 
267
                nih_signal_set_handler (SIGINT, nih_signal_handler);
 
268
                NIH_MUST (nih_signal_add_handler (NULL, SIGINT, nih_main_term_signal, NULL));
 
269
        }
 
270
 
 
271
        ret = nih_main_loop ();
 
272
 
 
273
        return ret;
 
274
}
 
275
 
 
276
 
 
277
static void
 
278
epoll_watcher (void *      data,
 
279
               NihIoWatch *watch,
 
280
               NihIoEvents events)
 
281
{
 
282
        struct epoll_event event[1024];
 
283
        int                num_events;
 
284
 
 
285
        num_events = epoll_wait (epoll_fd, event, 1024, 0);
 
286
        if (num_events < 0) {
 
287
                nih_error ("%s: %s", _("Error from epoll"), strerror (errno));
 
288
                return;
 
289
        } else if (num_events == 0)
 
290
                return;
 
291
 
 
292
        for (int i = 0; i < num_events; i++) {
 
293
                Socket *sock = (Socket *)event[i].data.ptr;
 
294
                nih_local char **env = NULL;
 
295
                size_t env_len = 0;
 
296
                char *var;
 
297
                DBusPendingCall *pending_call;
 
298
 
 
299
                if (event[i].events & EPOLLIN)
 
300
                        nih_debug ("%p EPOLLIN", sock);
 
301
                if (event[i].events & EPOLLERR)
 
302
                        nih_debug ("%p EPOLLERR", sock);
 
303
                if (event[i].events & EPOLLHUP)
 
304
                        nih_debug ("%p EPOLLHUP", sock);
 
305
 
 
306
                env = NIH_MUST (nih_str_array_new (NULL));
 
307
 
 
308
                switch (sock->addr.sa_family) {
 
309
                case AF_INET:
 
310
                        NIH_MUST (nih_str_array_add (&env, NULL, &env_len,
 
311
                                                     "PROTO=inet"));
 
312
 
 
313
                        var = NIH_MUST (nih_sprintf (NULL, "PORT=%d",
 
314
                                                     ntohs (sock->sin_addr.sin_port)));
 
315
                        NIH_MUST (nih_str_array_addp (&env, NULL, &env_len,
 
316
                                                      var));
 
317
                        nih_discard (var);
 
318
 
 
319
                        var = NIH_MUST (nih_sprintf (NULL, "ADDR=%s",
 
320
                                                     inet_ntoa (sock->sin_addr.sin_addr)));
 
321
                        NIH_MUST (nih_str_array_addp (&env, NULL, &env_len,
 
322
                                                      var));
 
323
                        nih_discard (var);
 
324
                        break;
 
325
                case AF_UNIX:
 
326
                        NIH_MUST (nih_str_array_add (&env, NULL, &env_len,
 
327
                                                     "PROTO=unix"));
 
328
 
 
329
                        var = NIH_MUST (nih_sprintf (NULL, "PATH=%s",
 
330
                                                     sock->sun_addr.sun_path));
 
331
                        NIH_MUST (nih_str_array_addp (&env, NULL, &env_len,
 
332
                                                      var));
 
333
                        nih_discard (var);
 
334
                        break;
 
335
                default:
 
336
                        nih_assert_not_reached ();
 
337
                }
 
338
 
 
339
                pending_call = NIH_SHOULD (upstart_emit_event_with_file (
 
340
                                                   upstart, "socket", env, TRUE,
 
341
                                                   sock->sock,
 
342
                                                   (UpstartEmitEventWithFileReply)emit_event_reply,
 
343
                                                   (NihDBusErrorHandler)emit_event_error,
 
344
                                                   sock,
 
345
                                                   NIH_DBUS_TIMEOUT_NEVER));
 
346
                if (! pending_call) {
 
347
                        NihError *err;
 
348
 
 
349
                        err = nih_error_get ();
 
350
                        nih_warn ("%s: %s", _("Could not send socket event"),
 
351
                                  err->message);
 
352
                        nih_free (err);
 
353
                }
 
354
 
 
355
                dbus_pending_call_unref (pending_call);
 
356
 
 
357
                // might be EPOLLIN
 
358
                // might be EPOLLERR
 
359
                // might be EPOLLHUP
 
360
        }
 
361
}
 
362
 
 
363
 
 
364
static void
 
365
upstart_job_added (void *          data,
 
366
                   NihDBusMessage *message,
 
367
                   const char *    job_class_path)
 
368
{
 
369
        nih_local NihDBusProxy *job_class = NULL;
 
370
        nih_local char ***start_on = NULL;
 
371
        nih_local char ***stop_on = NULL;
 
372
        Job *job;
 
373
 
 
374
        nih_assert (job_class_path != NULL);
 
375
 
 
376
        /* Obtain a proxy to the job */
 
377
        job_class = nih_dbus_proxy_new (NULL, upstart->connection,
 
378
                                        upstart->name, job_class_path,
 
379
                                        NULL, NULL);
 
380
        if (! job_class) {
 
381
                NihError *err;
 
382
 
 
383
                err = nih_error_get ();
 
384
                nih_error ("Could not create proxy for job %s: %s",
 
385
                           job_class_path, err->message);
 
386
                nih_free (err);
 
387
 
 
388
                return;
 
389
        }
 
390
 
 
391
        job_class->auto_start = FALSE;
 
392
 
 
393
        /* Obtain the start_on and stop_on properties of the job */
 
394
        if (job_class_get_start_on_sync (NULL, job_class, &start_on) < 0) {
 
395
                NihError *err;
 
396
 
 
397
                err = nih_error_get ();
 
398
                nih_error ("Could not obtain job start condition %s: %s",
 
399
                           job_class_path, err->message);
 
400
                nih_free (err);
 
401
 
 
402
                return;
 
403
        }
 
404
 
 
405
        if (job_class_get_stop_on_sync (NULL, job_class, &stop_on) < 0) {
 
406
                NihError *err;
 
407
 
 
408
                err = nih_error_get ();
 
409
                nih_error ("Could not obtain job stop condition %s: %s",
 
410
                           job_class_path, err->message);
 
411
                nih_free (err);
 
412
 
 
413
                return;
 
414
        }
 
415
 
 
416
        /* Free any existing record for the job (should never happen,
 
417
         * but worth being safe).
 
418
         */
 
419
        job = (Job *)nih_hash_lookup (jobs, job_class_path);
 
420
        if (job)
 
421
                nih_free (job);
 
422
 
 
423
        /* Create new record for the job */
 
424
        job = NIH_MUST (nih_new (NULL, Job));
 
425
        job->path = NIH_MUST (nih_strdup (job, job_class_path));
 
426
 
 
427
        nih_list_init (&job->entry);
 
428
        nih_list_init (&job->sockets);
 
429
 
 
430
        /* Find out whether this job listens for any socket events */
 
431
        for (char ***event = start_on; event && *event && **event; event++)
 
432
                if (! strcmp (**event, "socket"))
 
433
                        job_add_socket (job, *event);
 
434
        for (char ***event = stop_on; event && *event && **event; event++)
 
435
                if (! strcmp (**event, "socket"))
 
436
                        job_add_socket (job, *event);
 
437
 
 
438
        /* If we didn't end up with any sockets, free the job and move on */
 
439
        if (NIH_LIST_EMPTY (&job->sockets)) {
 
440
                nih_free (job);
 
441
                return;
 
442
        }
 
443
 
 
444
        nih_debug ("Job got added %s", job_class_path);
 
445
 
 
446
        nih_alloc_set_destructor (job, nih_list_destroy);
 
447
        nih_hash_add (jobs, &job->entry);
 
448
}
 
449
 
 
450
static void
 
451
upstart_job_removed (void *          data,
 
452
                     NihDBusMessage *message,
 
453
                     const char *    job_path)
 
454
{
 
455
        Job *job;
 
456
 
 
457
        nih_assert (job_path != NULL);
 
458
 
 
459
        job = (Job *)nih_hash_lookup (jobs, job_path);
 
460
        if (job) {
 
461
                nih_debug ("Job went away %s", job_path);
 
462
                nih_free (job);
 
463
        }
 
464
}
 
465
 
 
466
 
 
467
static void
 
468
job_add_socket (Job *  job,
 
469
                char **socket_info)
 
470
{
 
471
        Socket *sock;
 
472
        nih_local char *error = NULL;
 
473
        int     components = 0;
 
474
        struct epoll_event event;
 
475
 
 
476
        nih_assert (job != NULL);
 
477
        nih_assert (socket_info != NULL);
 
478
        nih_assert (! strcmp(socket_info[0], "socket"));
 
479
 
 
480
        sock = NIH_MUST (nih_new (job, Socket));
 
481
        memset (sock, 0, sizeof (Socket));
 
482
        sock->sock = -1;
 
483
 
 
484
        nih_list_init (&sock->entry);
 
485
 
 
486
        nih_debug ("Found socket");
 
487
        for (char **env = socket_info + 1; env && *env; env++) {
 
488
                char  *val;
 
489
                size_t name_len;
 
490
 
 
491
                val = strchr (*env, '=');
 
492
                if (! val) {
 
493
                        nih_warn ("Ignored socket event without variable name in %s",
 
494
                                  job->path);
 
495
                        goto error;
 
496
                }
 
497
 
 
498
                name_len = val - *env;
 
499
                val++;
 
500
 
 
501
                if (! strncmp (*env, "PROTO", name_len)) {
 
502
                        if (! strcmp (val, "inet")) {
 
503
                                sock->addrlen = sizeof sock->sin_addr;
 
504
                                sock->sin_addr.sin_family = AF_INET;
 
505
                                sock->sin_addr.sin_addr.s_addr = INADDR_ANY;
 
506
                                components = 1;
 
507
                        } else if (! strcmp (val, "unix")) {
 
508
                                sock->addrlen = sizeof sock->sun_addr;
 
509
                                sock->sun_addr.sun_family = AF_UNIX;
 
510
                                components = 1;
 
511
                        } else {
 
512
                                nih_warn ("Ignored socket event with unknown PROTO=%s in %s",
 
513
                                          val, job->path);
 
514
                                goto error;
 
515
                        }
 
516
 
 
517
                } else if (! strncmp (*env, "PORT", name_len)
 
518
                           && (sock->sin_addr.sin_family == AF_INET)) {
 
519
                        sock->sin_addr.sin_port = htons (atoi (val));
 
520
                        components--;
 
521
 
 
522
                } else if (! strncmp (*env, "ADDR", name_len)
 
523
                           && (sock->sin_addr.sin_family == AF_INET)) {
 
524
                        if (inet_aton (val, &(sock->sin_addr.sin_addr)) == 0) {
 
525
                                nih_warn ("Ignored socket event with invalid ADDR=%s in %s",
 
526
                                          val, job->path);
 
527
                                goto error;
 
528
                        }
 
529
 
 
530
                } else if (! strncmp (*env, "PATH", name_len)
 
531
                           && (sock->sun_addr.sun_family == AF_UNIX)) {
 
532
                        strncpy (sock->sun_addr.sun_path, val,
 
533
                                 sizeof sock->sun_addr.sun_path);
 
534
 
 
535
                        if (sock->sun_addr.sun_path[0] == '@')
 
536
                                sock->sun_addr.sun_path[0] = '\0';
 
537
 
 
538
                        components--;
 
539
 
 
540
                } else {
 
541
                        nih_warn ("Ignored socket event with unknown variable %.*s in %s",
 
542
                                  (int)name_len, *env, job->path);
 
543
                        goto error;
 
544
                }
 
545
        }
 
546
 
 
547
        /* Missing any required components? */
 
548
        if (components) {
 
549
                nih_warn ("Ignored incomplete socket event in %s",
 
550
                          job->path);
 
551
                goto error;
 
552
        }
 
553
 
 
554
        /* Let's try and set this baby up */
 
555
        sock->sock = socket (sock->addr.sa_family, SOCK_STREAM, 0);
 
556
        if (sock->sock < 0) {
 
557
                nih_warn ("Failed to create socket in %s: %s",
 
558
                          job->path, strerror (errno));
 
559
                goto error;
 
560
        }
 
561
 
 
562
        int opt = 1;
 
563
        if (setsockopt (sock->sock, SOL_SOCKET, SO_REUSEADDR,
 
564
                        &opt, sizeof opt) < 0) {
 
565
                nih_warn ("Failed to set socket reuse in %s: %s",
 
566
                          job->path, strerror (errno));
 
567
                goto error;
 
568
        }
 
569
 
 
570
        if (bind (sock->sock, &sock->addr, sock->addrlen) < 0) {
 
571
                nih_warn ("Failed to bind socket in %s: %s",
 
572
                          job->path, strerror (errno));
 
573
                goto error;
 
574
        }
 
575
 
 
576
        if (listen (sock->sock, SOMAXCONN) < 0) {
 
577
                nih_warn ("Failed to listen on socket in %s: %s",
 
578
                          job->path, strerror (errno));
 
579
                goto error;
 
580
        }
 
581
 
 
582
        /* We have a listening socket, now we want to be notified when someone
 
583
         * connects; but we just want one notification, we don't want to get
 
584
         * a DDoS of wake-ups while waiting for the service to start.
 
585
         *
 
586
         * The solution is to use epoll in edge-triggered mode, this will
 
587
         * fire only on initial connection until a new one comes in.
 
588
         */
 
589
        event.events = EPOLLIN | EPOLLET;
 
590
        event.data.ptr = sock;
 
591
 
 
592
        if (epoll_ctl (epoll_fd, EPOLL_CTL_ADD, sock->sock, &event) < 0) {
 
593
                nih_warn ("Failed to watch socket in %s: %s",
 
594
                          job->path, strerror (errno));
 
595
                goto error;
 
596
        }
 
597
 
 
598
        /* Okay then, add to the job */
 
599
        nih_alloc_set_destructor (sock, socket_destroy);
 
600
        nih_list_add (&job->sockets, &sock->entry);
 
601
 
 
602
        return;
 
603
 
 
604
error:
 
605
        if (sock->sock != -1)
 
606
                close (sock->sock);
 
607
        nih_free (sock);
 
608
}
 
609
 
 
610
static void
 
611
socket_destroy (Socket *sock)
 
612
{
 
613
        epoll_ctl (epoll_fd, EPOLL_CTL_DEL, sock->sock, NULL);
 
614
        close (sock->sock);
 
615
 
 
616
        nih_list_destroy (&sock->entry);
 
617
}
 
618
 
 
619
 
 
620
static void
 
621
upstart_disconnected (DBusConnection *connection)
 
622
{
 
623
        nih_fatal (_("Disconnected from Upstart"));
 
624
        nih_main_loop_exit (1);
 
625
}
 
626
 
 
627
 
 
628
static void
 
629
emit_event_reply (Socket *        sock,
 
630
                  NihDBusMessage *message)
 
631
{
 
632
        nih_debug ("Event completed");
 
633
}
 
634
 
 
635
static void
 
636
emit_event_error (Socket *        sock,
 
637
                  NihDBusMessage *message)
 
638
{
 
639
        NihError *err;
 
640
 
 
641
        err = nih_error_get ();
 
642
        nih_warn ("%s: %s", _("Error emitting socket event"), err->message);
 
643
        nih_free (err);
 
644
}