~vorlon/ubuntu/raring/upstart/lp.1199778

« back to all changes in this revision

Viewing changes to init/event.c

  • Committer: Scott James Remnant
  • Date: 2008-02-22 14:55:53 UTC
  • Revision ID: scott@netsplit.com-20080222145553-tye32p91r3lz7zyj
* init/event.h (Event): Remove args member.
(EventOperator): Rename args member to env.
Update prototypes to match.
* init/event.c (event_new): Remove args member.
(event_finished): Remove copying of args member to failed event.
(event_operator_new): Rename args member to env.
(event_operator_copy): Rename args copying to env.
(event_operator_match): ??
* init/tests/test_event.c (test_new): Update test to remove args.
(test_operator_new): Update test to rename args to env.
(test_operator_copy): Update test to rename args to env.
(test_operator_match): ???

Show diffs side-by-side

added added

removed removed

Lines of Context:
156
156
 * event_new:
157
157
 * @parent: parent of new event,
158
158
 * @name: name of event to emit,
159
 
 * @args: arguments to event,
160
159
 * @env: environment for event.
161
160
 *
162
161
 * Allocates an Event structure for the event details given and
163
162
 * appends it to the queue of events.
164
163
 *
165
 
 * Both @args and @env are optional, and may be NULL; if they are given,
166
 
 * then the array itself it reparented to belong to the event structure
167
 
 * and should not be modified.
 
164
 * @env is optional, and may be NULL; if given, then the array itself is
 
165
 * reparented to belong to the event structure and should not be modified.
168
166
 *
169
167
 * When the event reaches the top of the queue, it is taken off and placed
170
168
 * into the handling queue.  It is not removed from that queue until there
183
181
Event *
184
182
event_new (const void  *parent,
185
183
           const char  *name,
186
 
           char      **args,
187
184
           char      **env)
188
185
{
189
186
        Event *event;
210
207
        /* Fill in the event details */
211
208
        NIH_MUST (event->name = nih_strdup (event, name));
212
209
 
213
 
        event->args = args;
214
 
        if (event->args)
215
 
                nih_alloc_reparent (event->args, event);
216
 
 
217
210
        event->env = env;
218
211
        if (event->env)
219
212
                nih_alloc_reparent (event->env, event);
456
449
 
457
450
                        NIH_MUST (name = nih_sprintf (NULL, "%s/failed",
458
451
                                                      event->name));
459
 
                        new_event = event_new (NULL, name, NULL, NULL);
 
452
                        new_event = event_new (NULL, name, NULL);
460
453
                        nih_free (name);
461
454
 
462
 
                        if (event->args)
463
 
                                NIH_MUST (new_event->args = nih_str_array_copy (
464
 
                                                  new_event, NULL, event->args));
465
 
 
466
455
                        if (event->env)
467
456
                                NIH_MUST (new_event->env = nih_str_array_copy (
468
457
                                                  new_event, NULL, event->env));
478
467
 * @parent: parent of new operator,
479
468
 * @type: type of operator,
480
469
 * @name: name of event to match.
481
 
 * @args: arguments of event to match.
 
470
 * @env: environment of event to match.
482
471
 *
483
472
 * Allocates and returns a new EventOperator structure with the @type given,
484
473
 * if @type is EVENT_MATCH then the operator will be used to match an event
485
474
 * with the given @name and @arguments using event_match().
486
475
 *
487
 
 * @args is optional, and may be NULL; if given, then the array itself is
 
476
 * @env is optional, and may be NULL; if given, then the array itself is
488
477
 * reparented to belong to the EventOperator structure and should not be
489
478
 * modified.
490
479
 *
499
488
event_operator_new (const void         *parent,
500
489
                    EventOperatorType   type,
501
490
                    const char         *name,
502
 
                    char              **args)
 
491
                    char              **env)
503
492
{
504
493
        EventOperator *oper;
505
494
 
506
495
        nih_assert ((type == EVENT_MATCH) || (name == NULL));
507
 
        nih_assert ((type == EVENT_MATCH) || (args == NULL));
 
496
        nih_assert ((type == EVENT_MATCH) || (env == NULL));
508
497
        nih_assert ((type != EVENT_MATCH) || (name != NULL));
509
498
 
510
499
        oper = nih_new (parent, EventOperator);
523
512
                        return NULL;
524
513
                }
525
514
 
526
 
                oper->args = args;
527
 
                if (oper->args)
528
 
                        nih_alloc_reparent (oper->args, oper);
 
515
                oper->env = env;
 
516
                if (oper->env)
 
517
                        nih_alloc_reparent (oper->env, oper);
529
518
        } else {
530
519
                oper->name = NULL;
531
 
                oper->args = NULL;
 
520
                oper->env = NULL;
532
521
        }
533
522
 
534
523
        oper->event = NULL;
576
565
 
577
566
        oper->value = old_oper->value;
578
567
 
579
 
        if (old_oper->args) {
580
 
                oper->args = nih_str_array_copy (oper, NULL, old_oper->args);
581
 
                if (! oper->args) {
 
568
        if (old_oper->env) {
 
569
                oper->env = nih_str_array_copy (oper, NULL, old_oper->env);
 
570
                if (! oper->env) {
582
571
                        nih_free (oper);
583
572
                        return NULL;
584
573
                }
689
678
 *
690
679
 * Compares @oper against @event to see whether they are identical in name,
691
680
 * and whether @event contains at least the number of arguments given in
692
 
 * @oper, and that each of those arguments matches as a glob.
 
681
 * @oper, and that each of those arguments matches as a glob to environment
 
682
 * in @event.
693
683
 *
694
684
 * This may only be called if the type of @oper is EVENT_MATCH.
695
685
 *
699
689
event_operator_match (EventOperator *oper,
700
690
                      Event         *event)
701
691
{
702
 
        char **arg1, **arg2;
 
692
        char **env1, **env2;
703
693
 
704
694
        nih_assert (oper != NULL);
705
695
        nih_assert (oper->type == EVENT_MATCH);
711
701
        if (strcmp (oper->name, event->name))
712
702
                return FALSE;
713
703
 
714
 
        /* Match arguments using the operator's argument as a glob */
715
 
        for (arg1 = oper->args, arg2 = event->args;
716
 
             arg1 && arg2 && *arg1 && *arg2; arg1++, arg2++)
717
 
                if (fnmatch (*arg1, *arg2, 0))
 
704
        /* Match environment using the operator's environment as globs */
 
705
        for (env1 = oper->env, env2 = event->env;
 
706
             env1 && env2 && *env1 && *env2; env1++, env2++)
 
707
                if (fnmatch (*env1, *env2, 0))
718
708
                        return FALSE;
719
709
 
720
 
        /* Must be at least the same number of arguments in event as
 
710
        /* Must be at least the same number of environment in event as
721
711
         * there are in oper
722
712
         */
723
 
        if (arg1 && *arg1)
 
713
        if (env1 && *env1)
724
714
                return FALSE;
725
715
 
726
716
        return TRUE;