X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-supervision.c;h=1ff8f8b56b0337ec5a0baf35a09ff0b71cbed90c;hb=9e8fda2954d951ea819dbddfe5afe466b2306074;hp=6812e00acd6cccf89561d2da747b8e30e6cde77c;hpb=775144f839df8e3d37ec1cf52d0f7d3849ac7d46;p=src%2Fapp-framework-binder.git diff --git a/src/afb-supervision.c b/src/afb-supervision.c index 6812e00a..1ff8f8b5 100644 --- a/src/afb-supervision.c +++ b/src/afb-supervision.c @@ -43,13 +43,15 @@ #include "afs-supervision.h" #include "afb-stub-ws.h" #include "afb-debug.h" +#include "afb-fdev.h" #include "verbose.h" #include "wrap-json.h" +#include "jobs.h" extern struct afb_config *main_config; /* api and apiset name */ -static const char supervision_apiname[] = AFS_SURPERVISION_APINAME; +static const char supervision_apiname[] = AFS_SURPERVISION_APINAME_INTERNAL; /* path of the supervision socket */ static const char supervisor_socket_path[] = AFS_SURPERVISION_SOCKET; @@ -111,20 +113,24 @@ static int open_supervisor_socket(const char *path) return fd; } -static void cleanup_supervisor(void *nada) +static void disconnect_supervisor() { - struct afb_trace *t = __atomic_exchange_n(&trace, NULL, __ATOMIC_RELAXED); + struct afb_stub_ws *s; + struct afb_trace *t; + + INFO("Disconnecting supervision"); + s = __atomic_exchange_n(&supervisor, NULL, __ATOMIC_RELAXED); + t = __atomic_exchange_n(&trace, NULL, __ATOMIC_RELAXED); + if (s) + afb_stub_ws_unref(s); if (t) afb_trace_unref(t); - supervisor = NULL; } -static void disconnect_supervisor() +static void on_supervisor_hangup(struct afb_stub_ws *s) { - struct afb_stub_ws *s = __atomic_exchange_n(&supervisor, NULL, __ATOMIC_RELAXED); - - if (s) - afb_stub_ws_unref(s); + if (s && s == supervisor) + disconnect_supervisor(); } /* try to connect to supervisor */ @@ -133,6 +139,7 @@ static void try_connect_supervisor() int fd; ssize_t srd; struct afs_supervision_initiator initiator; + struct fdev *fdev; /* get the mutex */ pthread_mutex_lock(&mutex); @@ -190,11 +197,17 @@ static void try_connect_supervisor() } /* make the supervisor link */ - supervisor = afb_stub_ws_create_server(fd, supervision_apiname, supervision_apiset); + fdev = afb_fdev_create(fd); + if (!fdev) { + ERROR("Creation of fdev failed: %m"); + goto end2; + } + supervisor = afb_stub_ws_create_server(fdev, supervision_apiname, supervision_apiset); if (!supervisor) { ERROR("Creation of supervisor failed: %m"); - goto end2; + goto end; } + afb_stub_ws_on_hangup(supervisor, on_supervisor_hangup); /* successful termination */ goto end; @@ -205,11 +218,18 @@ end: pthread_mutex_unlock(&mutex); } -static void on_sighup(int signum) +static void try_connect_supervisor_job(int signum, void *args) { + INFO("Try to connect supervisor after SIGHUP"); try_connect_supervisor(); } +static void on_sighup(int signum) +{ + INFO("Supervision received a SIGHUP"); + jobs_queue(NULL, 0, try_connect_supervisor_job, NULL); +} + /** * initalize the supervision */ @@ -271,7 +291,6 @@ static const char *verbs[] = { "break", "config", "do", "exit", "sclose", "slist", "trace", "wait" }; enum { Break , Config , Do , Exit , Sclose , Slist , Trace , Wait }; - static void on_supervision_call(void *closure, struct afb_xreq *xreq) { int i, rc; @@ -329,7 +348,8 @@ static void on_supervision_call(void *closure, struct afb_xreq *xreq) if (!trace) trace = afb_trace_create(supervision_apiname, NULL /* not bound to any session */); - req = afb_xreq_unstore((struct afb_stored_req*)xreq); + req = xreq_to_req(xreq); + add = drop = NULL; wrap_json_unpack(args, "{s?o s?o}", "add", &add, "drop", &drop); if (add) { rc = afb_trace_add(req, add, trace);