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,
62
static int control_job_query (void *data, pid_t pid,
63
UpstartMessageType type, const char *name,
65
static int control_job_start (void *data, pid_t pid,
66
UpstartMessageType type, const char *name,
68
static int control_job_stop (void *data, pid_t pid,
69
UpstartMessageType type, const char *name,
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,
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,
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);
87
88
* processes. Any message types not listed here will be discarded.
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 },
109
110
UPSTART_MESSAGE_LAST
302
* control_watch_jobs:
303
* @data: data pointer,
304
* @pid: origin process id,
305
* @type: message type received.
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.
310
* Returns: zero on success, negative value on raised error.
313
control_watch_jobs (void *data,
315
UpstartMessageType type)
317
nih_assert (pid > 0);
318
nih_assert (type == UPSTART_WATCH_JOBS);
320
nih_info (_("Control request to subscribe %d to jobs"), pid);
322
notify_subscribe_job (NULL, pid, NULL);
328
* control_unwatch_jobs:
329
* @data: data pointer,
330
* @pid: origin process id,
331
* @type: message type received.
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.
336
* Returns: zero on success, negative value on raised error.
339
control_unwatch_jobs (void *data,
341
UpstartMessageType type)
343
NotifySubscription *sub;
345
nih_assert (pid > 0);
346
nih_assert (type == UPSTART_UNWATCH_JOBS);
348
nih_info (_("Control request to unsubscribe %d from jobs"), pid);
350
sub = notify_subscription_find (pid, NOTIFY_JOB, NULL);
352
nih_list_free (&sub->entry);
358
* control_watch_events:
359
* @data: data pointer,
360
* @pid: origin process id,
361
* @type: message type received.
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.
366
* Returns: zero on success, negative value on raised error.
369
control_watch_events (void *data,
371
UpstartMessageType type)
373
nih_assert (pid > 0);
374
nih_assert (type == UPSTART_WATCH_EVENTS);
376
nih_info (_("Control request to subscribe %d to events"), pid);
378
notify_subscribe_event (NULL, pid, NULL);
384
* control_unwatch_events:
385
* @data: data pointer,
386
* @pid: origin process id,
387
* @type: message type received.
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.
392
* Returns: zero on success, negative value on raised error.
395
control_unwatch_events (void *data,
397
UpstartMessageType type)
399
NotifySubscription *sub;
401
nih_assert (pid > 0);
402
nih_assert (type == UPSTART_UNWATCH_EVENTS);
404
nih_info (_("Control request to unsubscribe %d from events"), pid);
406
sub = notify_subscription_find (pid, NOTIFY_EVENT, NULL);
408
nih_list_free (&sub->entry);
415
303
* control_job_find:
416
304
* @data: data pointer,
417
305
* @pid: origin process id,
684
* control_subscribe_jobs:
685
* @data: data pointer,
686
* @pid: origin process id,
687
* @type: message type received.
689
* This function is called when another process on the system requests that
690
* it be subscribed to job status updates.
692
* We add the subscription, no reply is sent.
694
* Returns: zero on success, negative value on raised error.
697
control_subscribe_jobs (void *data,
699
UpstartMessageType type)
701
nih_assert (pid > 0);
702
nih_assert (type == UPSTART_SUBSCRIBE_JOBS);
704
nih_info (_("Control request to subscribe %d to jobs"), pid);
706
notify_subscribe_job (NULL, pid, NULL);
712
* control_unsubscribe_jobs:
713
* @data: data pointer,
714
* @pid: origin process id,
715
* @type: message type received.
717
* This function is called when another process on the system requests that
718
* it be unsubscribed from job status updates.
720
* We lookup their current subscription, and remove it if it exists. No
721
* reply is sent, and a non-existant subscription is ignored.
723
* Returns: zero on success, negative value on raised error.
726
control_unsubscribe_jobs (void *data,
728
UpstartMessageType type)
730
NotifySubscription *sub;
732
nih_assert (pid > 0);
733
nih_assert (type == UPSTART_UNSUBSCRIBE_JOBS);
735
nih_info (_("Control request to unsubscribe %d from jobs"), pid);
737
sub = notify_subscription_find (pid, NOTIFY_JOB, NULL);
739
nih_list_free (&sub->entry);
745
* control_subscribe_events:
746
* @data: data pointer,
747
* @pid: origin process id,
748
* @type: message type received.
750
* This function is called when another process on the system requests that
751
* it be subscribed to event emissions.
753
* We add the subscription, no reply is sent.
755
* Returns: zero on success, negative value on raised error.
758
control_subscribe_events (void *data,
760
UpstartMessageType type)
762
nih_assert (pid > 0);
763
nih_assert (type == UPSTART_SUBSCRIBE_EVENTS);
765
nih_info (_("Control request to subscribe %d to events"), pid);
767
notify_subscribe_event (NULL, pid, NULL);
773
* control_unsubscribe_events:
774
* @data: data pointer,
775
* @pid: origin process id,
776
* @type: message type received.
778
* This function is called when another process on the system requests that
779
* it be unsubscribed from event emissions.
781
* We lookup their current subscription, and remove it if it exists. No
782
* reply is sent, and a non-existant subscription is ignored.
784
* Returns: zero on success, negative value on raised error.
787
control_unsubscribe_events (void *data,
789
UpstartMessageType type)
791
NotifySubscription *sub;
793
nih_assert (pid > 0);
794
nih_assert (type == UPSTART_UNSUBSCRIBE_EVENTS);
796
nih_info (_("Control request to unsubscribe %d from events"), pid);
798
sub = notify_subscription_find (pid, NOTIFY_EVENT, NULL);
800
nih_list_free (&sub->entry);