+/*************************************************************************************/
+
+/**
+ * initialize the supervisor
+ */
+static int init_supervisor(afb_api_t api)
+{
+ int rc, fd;
+
+ event_add_pid = afb_api_make_event(api, "add-pid");
+ if (!afb_event_is_valid(event_add_pid)) {
+ ERROR("Can't create added event");
+ return -1;
+ }
+
+ event_del_pid = afb_api_make_event(api, "del-pid");
+ if (!afb_event_is_valid(event_del_pid)) {
+ ERROR("Can't create deleted event");
+ return -1;
+ }
+
+ /* create an empty set for superviseds */
+ empty_apiset = afb_apiset_create(supervision_apiname, 0);
+ if (!empty_apiset) {
+ ERROR("Can't create supervision apiset");
+ return -1;
+ }
+
+ /* create the supervision socket */
+ fd = create_supervision_socket(supervision_socket_path);
+ if (fd < 0)
+ return fd;
+
+ /* listen the socket */
+ rc = listen(fd, 5);
+ if (rc < 0) {
+ ERROR("refused to listen on socket");
+ return rc;
+ }
+
+ /* integrate the socket to the loop */
+ supervision_fdev = afb_fdev_create(fd);
+ if (rc < 0) {
+ ERROR("handling socket event isn't possible");
+ return rc;
+ }
+ fdev_set_events(supervision_fdev, EPOLLIN);
+ fdev_set_callback(supervision_fdev, listening, (void*)(intptr_t)fd);
+
+ return 0;
+}
+
+/*************************************************************************************/
+
+static const struct afb_auth _afb_auths_v2_supervisor[] = {