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

« back to all changes in this revision

Viewing changes to init/control.c

  • Committer: Scott James Remnant
  • Date: 2007-03-08 14:22:45 UTC
  • Revision ID: scott@netsplit.com-20070308142245-8brvrno3jf5nspmh
* init/control.c (control_watch_jobs): Rename to control_subscribe_jobs
and update to handle new event name.
(control_unwatch_jobs): Rename to control_unsubscribe_jobs and update
to handle the new event name.
(control_watch_events): Rename to control_subscribe_events and update
to handle the new event name.
(control_unwatch_events): Rename to control_unsubscribe_events and
update to handle the new event name.
* init/tests/test_control.c (test_watch_jobs): Rename to
test_subscribe_jobs and update to new event name.
(test_unwatch_jobs): Rename to test_unsubscribe_jobs and update to 
new event name.
(test_watch_events): Rename to test_subscribe_events and update to
new event name.
(test_unwatch_events): Rename to test_unsubscribe events and update
to new event name.
* upstart/message.h: Rename the watch commands to subscribe/unsubscribe
and regroup with new message numbers.
* upstart/message.c (upstart_message_newv) 
(upstart_message_handle): Marshal the updated subscription messages.
* upstart/tests/test_message.c (test_new, my_handler) 
(test_handle): Update tests to new names and numbers.
* TODO: Update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
 
48
48
 
49
49
/* Prototypes for static functions */
50
 
static void control_error_handler  (void  *data, NihIo *io);
51
 
static int  control_watch_jobs     (void *data, pid_t pid,
52
 
                                    UpstartMessageType type);
53
 
static int  control_unwatch_jobs   (void *data, pid_t pid,
54
 
                                    UpstartMessageType type);
55
 
static int  control_watch_events   (void *data, pid_t pid,
56
 
                                    UpstartMessageType type);
57
 
static int  control_unwatch_events (void *data, pid_t pid,
58
 
                                    UpstartMessageType type);
59
 
static int  control_job_find       (void *data, pid_t pid,
60
 
                                    UpstartMessageType type,
61
 
                                    const char *pattern);
62
 
static int  control_job_query      (void *data, pid_t pid,
63
 
                                    UpstartMessageType type, const char *name,
64
 
                                    uint32_t id);
65
 
static int  control_job_start      (void *data, pid_t pid,
66
 
                                    UpstartMessageType type, const char *name,
67
 
                                    uint32_t id);
68
 
static int  control_job_stop       (void *data, pid_t pid,
69
 
                                    UpstartMessageType type, const char *name,
70
 
                                    uint32_t id);
71
 
static int  control_event_emit     (void *data, pid_t pid,
72
 
                                    UpstartMessageType type, const char *name,
73
 
                                    char **args, char **env);
 
50
static void control_error_handler      (void  *data, NihIo *io);
 
51
static int  control_job_find           (void *data, pid_t pid,
 
52
                                        UpstartMessageType type,
 
53
                                        const char *pattern);
 
54
static int  control_job_query          (void *data, pid_t pid,
 
55
                                        UpstartMessageType type,
 
56
                                        const char *name, uint32_t id);
 
57
static int  control_job_start          (void *data, pid_t pid,
 
58
                                        UpstartMessageType type,
 
59
                                        const char *name, uint32_t id);
 
60
static int  control_job_stop           (void *data, pid_t pid,
 
61
                                        UpstartMessageType type,
 
62
                                        const char *name, uint32_t id);
 
63
static int  control_event_emit         (void *data, pid_t pid,
 
64
                                        UpstartMessageType type,
 
65
                                        const char *name,
 
66
                                        char **args, char **env);
 
67
static int  control_subscribe_jobs     (void *data, pid_t pid,
 
68
                                        UpstartMessageType type);
 
69
static int  control_unsubscribe_jobs   (void *data, pid_t pid,
 
70
                                        UpstartMessageType type);
 
71
static int  control_subscribe_events   (void *data, pid_t pid,
 
72
                                        UpstartMessageType type);
 
73
static int  control_unsubscribe_events (void *data, pid_t pid,
 
74
                                        UpstartMessageType type);
74
75
 
75
76
 
76
77
/**
87
88
 * processes.  Any message types not listed here will be discarded.
88
89
 **/
89
90
static UpstartMessage message_handlers[] = {
90
 
        { -1, UPSTART_WATCH_JOBS,
91
 
          (UpstartMessageHandler)control_watch_jobs },
92
 
        { -1, UPSTART_UNWATCH_JOBS,
93
 
          (UpstartMessageHandler)control_unwatch_jobs },
94
 
        { -1, UPSTART_WATCH_EVENTS,
95
 
          (UpstartMessageHandler)control_watch_events },
96
 
        { -1, UPSTART_UNWATCH_EVENTS,
97
 
          (UpstartMessageHandler)control_unwatch_events },
98
91
        { -1, UPSTART_JOB_FIND,
99
92
          (UpstartMessageHandler)control_job_find },
100
93
        { -1, UPSTART_JOB_QUERY,
105
98
          (UpstartMessageHandler)control_job_stop },
106
99
        { -1, UPSTART_EVENT_EMIT,
107
100
          (UpstartMessageHandler)control_event_emit },
 
101
        { -1, UPSTART_SUBSCRIBE_JOBS,
 
102
          (UpstartMessageHandler)control_subscribe_jobs },
 
103
        { -1, UPSTART_UNSUBSCRIBE_JOBS,
 
104
          (UpstartMessageHandler)control_unsubscribe_jobs },
 
105
        { -1, UPSTART_SUBSCRIBE_EVENTS,
 
106
          (UpstartMessageHandler)control_subscribe_events },
 
107
        { -1, UPSTART_UNSUBSCRIBE_EVENTS,
 
108
          (UpstartMessageHandler)control_unsubscribe_events },
108
109
 
109
110
        UPSTART_MESSAGE_LAST
110
111
};
299
300
 
300
301
 
301
302
/**
302
 
 * control_watch_jobs:
303
 
 * @data: data pointer,
304
 
 * @pid: origin process id,
305
 
 * @type: message type received.
306
 
 *
307
 
 * This function is called when another process on the system requests
308
 
 * status updates for all jobs to be sent to it.  It receives no reply.
309
 
 *
310
 
 * Returns: zero on success, negative value on raised error.
311
 
 **/
312
 
static int
313
 
control_watch_jobs (void               *data,
314
 
                    pid_t               pid,
315
 
                    UpstartMessageType  type)
316
 
{
317
 
        nih_assert (pid > 0);
318
 
        nih_assert (type == UPSTART_WATCH_JOBS);
319
 
 
320
 
        nih_info (_("Control request to subscribe %d to jobs"), pid);
321
 
 
322
 
        notify_subscribe_job (NULL, pid, NULL);
323
 
 
324
 
        return 0;
325
 
}
326
 
 
327
 
/**
328
 
 * control_unwatch_jobs:
329
 
 * @data: data pointer,
330
 
 * @pid: origin process id,
331
 
 * @type: message type received.
332
 
 *
333
 
 * This function is called when another process on the system requests
334
 
 * status updates for all jobs no longer be sent to it.  It receives no reply.
335
 
 *
336
 
 * Returns: zero on success, negative value on raised error.
337
 
 **/
338
 
static int
339
 
control_unwatch_jobs (void               *data,
340
 
                      pid_t               pid,
341
 
                      UpstartMessageType  type)
342
 
{
343
 
        NotifySubscription *sub;
344
 
 
345
 
        nih_assert (pid > 0);
346
 
        nih_assert (type == UPSTART_UNWATCH_JOBS);
347
 
 
348
 
        nih_info (_("Control request to unsubscribe %d from jobs"), pid);
349
 
 
350
 
        sub = notify_subscription_find (pid, NOTIFY_JOB, NULL);
351
 
        if (sub)
352
 
                nih_list_free (&sub->entry);
353
 
 
354
 
        return 0;
355
 
}
356
 
 
357
 
/**
358
 
 * control_watch_events:
359
 
 * @data: data pointer,
360
 
 * @pid: origin process id,
361
 
 * @type: message type received.
362
 
 *
363
 
 * This function is called when another process on the system requests
364
 
 * notification of all events be sent to it.  It receives no reply.
365
 
 *
366
 
 * Returns: zero on success, negative value on raised error.
367
 
 **/
368
 
static int
369
 
control_watch_events (void               *data,
370
 
                      pid_t               pid,
371
 
                      UpstartMessageType  type)
372
 
{
373
 
        nih_assert (pid > 0);
374
 
        nih_assert (type == UPSTART_WATCH_EVENTS);
375
 
 
376
 
        nih_info (_("Control request to subscribe %d to events"), pid);
377
 
 
378
 
        notify_subscribe_event (NULL, pid, NULL);
379
 
 
380
 
        return 0;
381
 
}
382
 
 
383
 
/**
384
 
 * control_unwatch_events:
385
 
 * @data: data pointer,
386
 
 * @pid: origin process id,
387
 
 * @type: message type received.
388
 
 *
389
 
 * This function is called when another process on the system requests
390
 
 * notification of all events no longer be sent to it.  It receives no reply.
391
 
 *
392
 
 * Returns: zero on success, negative value on raised error.
393
 
 **/
394
 
static int
395
 
control_unwatch_events (void               *data,
396
 
                        pid_t               pid,
397
 
                        UpstartMessageType  type)
398
 
{
399
 
        NotifySubscription *sub;
400
 
 
401
 
        nih_assert (pid > 0);
402
 
        nih_assert (type == UPSTART_UNWATCH_EVENTS);
403
 
 
404
 
        nih_info (_("Control request to unsubscribe %d from events"), pid);
405
 
 
406
 
        sub = notify_subscription_find (pid, NOTIFY_EVENT, NULL);
407
 
        if (sub)
408
 
                nih_list_free (&sub->entry);
409
 
 
410
 
        return 0;
411
 
}
412
 
 
413
 
 
414
 
/**
415
303
 * control_job_find:
416
304
 * @data: data pointer,
417
305
 * @pid: origin process id,
790
678
 
791
679
        return 0;
792
680
}
 
681
 
 
682
 
 
683
/**
 
684
 * control_subscribe_jobs:
 
685
 * @data: data pointer,
 
686
 * @pid: origin process id,
 
687
 * @type: message type received.
 
688
 *
 
689
 * This function is called when another process on the system requests that
 
690
 * it be subscribed to job status updates.
 
691
 *
 
692
 * We add the subscription, no reply is sent.
 
693
 *
 
694
 * Returns: zero on success, negative value on raised error.
 
695
 **/
 
696
static int
 
697
control_subscribe_jobs (void               *data,
 
698
                        pid_t               pid,
 
699
                        UpstartMessageType  type)
 
700
{
 
701
        nih_assert (pid > 0);
 
702
        nih_assert (type == UPSTART_SUBSCRIBE_JOBS);
 
703
 
 
704
        nih_info (_("Control request to subscribe %d to jobs"), pid);
 
705
 
 
706
        notify_subscribe_job (NULL, pid, NULL);
 
707
 
 
708
        return 0;
 
709
}
 
710
 
 
711
/**
 
712
 * control_unsubscribe_jobs:
 
713
 * @data: data pointer,
 
714
 * @pid: origin process id,
 
715
 * @type: message type received.
 
716
 *
 
717
 * This function is called when another process on the system requests that
 
718
 * it be unsubscribed from job status updates.
 
719
 *
 
720
 * We lookup their current subscription, and remove it if it exists.  No
 
721
 * reply is sent, and a non-existant subscription is ignored.
 
722
 *
 
723
 * Returns: zero on success, negative value on raised error.
 
724
 **/
 
725
static int
 
726
control_unsubscribe_jobs (void               *data,
 
727
                          pid_t               pid,
 
728
                          UpstartMessageType  type)
 
729
{
 
730
        NotifySubscription *sub;
 
731
 
 
732
        nih_assert (pid > 0);
 
733
        nih_assert (type == UPSTART_UNSUBSCRIBE_JOBS);
 
734
 
 
735
        nih_info (_("Control request to unsubscribe %d from jobs"), pid);
 
736
 
 
737
        sub = notify_subscription_find (pid, NOTIFY_JOB, NULL);
 
738
        if (sub)
 
739
                nih_list_free (&sub->entry);
 
740
 
 
741
        return 0;
 
742
}
 
743
 
 
744
/**
 
745
 * control_subscribe_events:
 
746
 * @data: data pointer,
 
747
 * @pid: origin process id,
 
748
 * @type: message type received.
 
749
 *
 
750
 * This function is called when another process on the system requests that
 
751
 * it be subscribed to event emissions.
 
752
 *
 
753
 * We add the subscription, no reply is sent.
 
754
 *
 
755
 * Returns: zero on success, negative value on raised error.
 
756
 **/
 
757
static int
 
758
control_subscribe_events (void               *data,
 
759
                          pid_t               pid,
 
760
                          UpstartMessageType  type)
 
761
{
 
762
        nih_assert (pid > 0);
 
763
        nih_assert (type == UPSTART_SUBSCRIBE_EVENTS);
 
764
 
 
765
        nih_info (_("Control request to subscribe %d to events"), pid);
 
766
 
 
767
        notify_subscribe_event (NULL, pid, NULL);
 
768
 
 
769
        return 0;
 
770
}
 
771
 
 
772
/**
 
773
 * control_unsubscribe_events:
 
774
 * @data: data pointer,
 
775
 * @pid: origin process id,
 
776
 * @type: message type received.
 
777
 *
 
778
 * This function is called when another process on the system requests that
 
779
 * it be unsubscribed from event emissions.
 
780
 *
 
781
 * We lookup their current subscription, and remove it if it exists.  No
 
782
 * reply is sent, and a non-existant subscription is ignored.
 
783
 *
 
784
 * Returns: zero on success, negative value on raised error.
 
785
 **/
 
786
static int
 
787
control_unsubscribe_events (void               *data,
 
788
                            pid_t               pid,
 
789
                            UpstartMessageType  type)
 
790
{
 
791
        NotifySubscription *sub;
 
792
 
 
793
        nih_assert (pid > 0);
 
794
        nih_assert (type == UPSTART_UNSUBSCRIBE_EVENTS);
 
795
 
 
796
        nih_info (_("Control request to unsubscribe %d from events"), pid);
 
797
 
 
798
        sub = notify_subscription_find (pid, NOTIFY_EVENT, NULL);
 
799
        if (sub)
 
800
                nih_list_free (&sub->entry);
 
801
 
 
802
        return 0;
 
803
}