~xnox/upstart/upstart-async-run-dead-code

« back to all changes in this revision

Viewing changes to init/event_operator.c

  • Committer: James Hunt
  • Date: 2011-06-06 17:05:11 UTC
  • mfrom: (1245.3.13 upstart-bridges)
  • Revision ID: james.hunt@ubuntu.com-20110606170511-h7cm82b47vsv2y0o
Merge of lp:~jamesodhunt/upstart/upstream-udev+socket-bridges.

* Makefile.am: Added extra directory.
* New files:
  - extra/Makefile.am
  - extra/conf/upstart-socket-bridge.conf
  - extra/conf/upstart-udev-bridge.conf
  - extra/man/socket-event.7
  - extra/man/upstart-socket-bridge.8
  - extra/man/upstart-udev-bridge.8
  - extra/upstart-socket-bridge.c
  - extra/upstart-udev-bridge.c
* configure.ac:
  - Check for udev (for upstart-udev-bridge).
  - Add extra/Makefile to AC_CONFIG_FILES.
* dbus/com.ubuntu.Upstart.xml: Add EmitEventWithFile method.
* init/control.c:
  - control_emit_event(): Now a wrapper for control_emit_event_with_file.
  - control_emit_event_with_file(): New function that operates on an fd.
* init/control.h: Prototype for control_emit_event_with_file().
* init/event.c:
  - event_new(): Initialize event fd.
  - event_pending_handle_jobs(): Now calls event_operator_fds().
* init/event.c: Add fd to Event struct.
* init/event_operator.c: event_operator_fds(): New function.
* init/event_operator.h: Prototype for event_operator_fds().
* init/job.c: job_new(): Initialize fd members.
* init/job.h: Add fds and num_fds to Job struct.

Show diffs side-by-side

added added

removed removed

Lines of Context:
552
552
        return *env;
553
553
}
554
554
 
 
555
int *
 
556
event_operator_fds (EventOperator *root,
 
557
                    const void *parent,
 
558
                    int **fds,
 
559
                    size_t *num_fds,
 
560
                    char          ***env,
 
561
                    size_t          *len,
 
562
                    const char      *key)
 
563
{
 
564
        nih_local char *evlist = NULL;
 
565
 
 
566
        nih_assert (root != NULL);
 
567
        nih_assert (fds != NULL);
 
568
        nih_assert (num_fds != NULL);
 
569
        nih_assert (env != NULL);
 
570
        nih_assert (len != NULL);
 
571
        nih_assert (key != NULL);
 
572
 
 
573
        /* Initialise the event list variable with the name given. */
 
574
        evlist = nih_sprintf (NULL, "%s=", key);
 
575
        if (! evlist)
 
576
                return NULL;
 
577
 
 
578
        *num_fds = 0;
 
579
        NIH_TREE_FOREACH_FULL (&root->node, iter,
 
580
                               (NihTreeFilter)event_operator_filter, NULL) {
 
581
                EventOperator *oper = (EventOperator *)iter;
 
582
 
 
583
                if (oper->type != EVENT_MATCH)
 
584
                        continue;
 
585
 
 
586
                nih_assert (oper->event != NULL);
 
587
 
 
588
                if (oper->event->fd >= 0) {
 
589
                        *fds = nih_realloc (*fds, parent, sizeof (int) * (*num_fds + 1));
 
590
                        if (! *fds)
 
591
                                return NULL;
 
592
 
 
593
                        (*fds)[(*num_fds)++] = oper->event->fd;
 
594
 
 
595
                        if (evlist[strlen (evlist) - 1] != '=') {
 
596
                                if (! nih_strcat_sprintf (&evlist, NULL, " %d",
 
597
                                                          oper->event->fd))
 
598
                                        return NULL;
 
599
                        } else {
 
600
                                if (! nih_strcat_sprintf (&evlist, NULL, "%d",
 
601
                                                          oper->event->fd))
 
602
                                        return NULL;
 
603
                        }
 
604
                }
 
605
        }
 
606
 
 
607
        if (*num_fds)
 
608
                if (! environ_add (env, parent, len, TRUE, evlist))
 
609
                        return NULL;
 
610
 
 
611
        return (void *)1;
 
612
}
 
613
 
555
614
/**
556
615
 * event_operator_events:
557
616
 * @root: operator tree to collect from,