Update date of copyright notices
[src/app-framework-binder.git] / src / afs-supervisor.c
index 71a0036..acad792 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
 #include <errno.h>
 #include <signal.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <pthread.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 
-#include <systemd/sd-event.h>
-#include <systemd/sd-daemon.h>
-
-#include <uuid/uuid.h>
 #include <json-c/json.h>
 #include <afb/afb-binding-v2.h>
 
-#include "afb-systemd.h"
-#include "afb-session.h"
 #include "afb-cred.h"
 #include "afb-stub-ws.h"
 #include "afb-api.h"
 #include "afb-xreq.h"
 #include "afb-api-so-v2.h"
-#include "afb-api-ws.h"
 #include "afb-apiset.h"
 #include "afb-fdev.h"
-#include "jobs.h"
+
+#include "fdev.h"
 #include "verbose.h"
 #include "wrap-json.h"
-#include "process-name.h"
 
 #include "afs-supervision.h"
 #include "afs-supervisor.h"
@@ -76,6 +68,7 @@ static struct afb_apiset *empty_apiset;
 
 /* supervision socket path */
 static const char supervision_socket_path[] = AFS_SURPERVISION_SOCKET;
+static struct fdev *supervision_fdev;
 
 /* global mutex */
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -265,15 +258,14 @@ static void accept_supervision_link(int sock)
 /*
  * handle even on server socket
  */
-static int listening(sd_event_source *src, int fd, uint32_t revents, void *closure)
+static void listening(void *closure, uint32_t revents, struct fdev *fdev)
 {
        if ((revents & EPOLLIN) != 0)
-               accept_supervision_link(fd);
+               accept_supervision_link((int)(intptr_t)closure);
        if ((revents & EPOLLHUP) != 0) {
                ERROR("supervision socket closed");
                exit(1);
        }
-       return 0;
 }
 
 /*
@@ -391,16 +383,19 @@ static void f_session_close(struct afb_req req)
 static void f_exit(struct afb_req req)
 {
        propagate(req, NULL);
+       afb_req_success(req, NULL, NULL);
 }
 
 static void f_debug_wait(struct afb_req req)
 {
        propagate(req, "wait");
+       afb_req_success(req, NULL, NULL);
 }
 
 static void f_debug_break(struct afb_req req)
 {
        propagate(req, "break");
+       afb_req_success(req, NULL, NULL);
 }
 
 /*************************************************************************************/
@@ -432,13 +427,13 @@ static int init_supervisor()
        }
 
        /* integrate the socket to the loop */
-       rc = sd_event_add_io(afb_systemd_get_event_loop(),
-                               NULL, fd, EPOLLIN,
-                               listening, NULL);
+       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;
 }
@@ -459,70 +454,70 @@ static const struct afb_verb_v2 _afb_verbs_v2_supervisor[] = {
         .callback = f_list,
         .auth = &_afb_auths_v2_supervisor[0],
         .info = NULL,
-        .session = AFB_SESSION_NONE_V2
+        .session = AFB_SESSION_CHECK_V2
     },
     {
         .verb = "config",
         .callback = f_config,
         .auth = &_afb_auths_v2_supervisor[0],
         .info = NULL,
-        .session = AFB_SESSION_NONE_V2
+        .session = AFB_SESSION_CHECK_V2
     },
     {
         .verb = "do",
         .callback = f_do,
         .auth = &_afb_auths_v2_supervisor[0],
         .info = NULL,
-        .session = AFB_SESSION_NONE_V2
+        .session = AFB_SESSION_CHECK_V2
     },
     {
         .verb = "trace",
         .callback = f_trace,
         .auth = &_afb_auths_v2_supervisor[0],
         .info = NULL,
-        .session = AFB_SESSION_NONE_V2
+        .session = AFB_SESSION_CHECK_V2
     },
     {
         .verb = "sessions",
         .callback = f_sessions,
         .auth = &_afb_auths_v2_supervisor[0],
         .info = NULL,
-        .session = AFB_SESSION_NONE_V2
+        .session = AFB_SESSION_CHECK_V2
     },
     {
         .verb = "session-close",
         .callback = f_session_close,
         .auth = &_afb_auths_v2_supervisor[0],
         .info = NULL,
-        .session = AFB_SESSION_NONE_V2
+        .session = AFB_SESSION_CHECK_V2
     },
     {
         .verb = "exit",
         .callback = f_exit,
         .auth = &_afb_auths_v2_supervisor[0],
         .info = NULL,
-        .session = AFB_SESSION_NONE_V2
+        .session = AFB_SESSION_CHECK_V2
     },
     {
         .verb = "debug-wait",
         .callback = f_debug_wait,
         .auth = &_afb_auths_v2_supervisor[0],
         .info = NULL,
-        .session = AFB_SESSION_NONE_V2
+        .session = AFB_SESSION_CHECK_V2
     },
     {
         .verb = "debug-break",
         .callback = f_debug_break,
         .auth = &_afb_auths_v2_supervisor[0],
         .info = NULL,
-        .session = AFB_SESSION_NONE_V2
+        .session = AFB_SESSION_CHECK_V2
     },
     {
         .verb = "discover",
         .callback = f_discover,
         .auth = &_afb_auths_v2_supervisor[0],
         .info = NULL,
-        .session = AFB_SESSION_NONE_V2
+        .session = AFB_SESSION_CHECK_V2
     },
     { .verb = NULL }
 };