X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafs-supervisor.c;h=9746a0f342e781c3930131aab7bb70174bafed50;hb=99ad30bf29c683da833efeac42d8f178b6d2ca8c;hp=6bd1fc6290035764ad58ff29f5930363765d1dd7;hpb=4521c1e7ae5371ab9d639adc617d17fb4e8ded0c;p=src%2Fapp-framework-binder.git diff --git a/src/afs-supervisor.c b/src/afs-supervisor.c index 6bd1fc62..9746a0f3 100644 --- a/src/afs-supervisor.c +++ b/src/afs-supervisor.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017, 2018 "IoT.bzh" + * Copyright (C) 2016-2019 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -173,14 +173,22 @@ static int should_accept(struct afb_cred *cred) static void on_supervised_hangup(struct afb_stub_ws *stub) { struct supervised *s, **ps; + + /* Search the supervised of the ws-stub */ pthread_mutex_lock(&mutex); ps = &superviseds; while ((s = *ps) && s->stub != stub) ps = &s->next; + + /* unlink the supervised if found */ if (s) *ps = s->next; pthread_mutex_unlock(&mutex); + + /* forgive the ws-stub */ afb_stub_ws_unref(stub); + + /* forgive the supervised */ if (s) { afb_event_push(event_del_pid, json_object_new_int((int)s->cred->pid)); afb_cred_unref(s->cred); @@ -217,7 +225,7 @@ static int make_supervised(int fd, struct afb_cred *cred) s->next = superviseds; superviseds = s; pthread_mutex_unlock(&mutex); - afb_stub_ws_on_hangup(s->stub, on_supervised_hangup); + afb_stub_ws_set_on_hangup(s->stub, on_supervised_hangup); return 0; } @@ -272,12 +280,12 @@ static void accept_supervision_link(int sock) */ static void listening(void *closure, uint32_t revents, struct fdev *fdev) { - if ((revents & EPOLLIN) != 0) - accept_supervision_link((int)(intptr_t)closure); if ((revents & EPOLLHUP) != 0) { ERROR("supervision socket closed"); exit(1); } + if ((revents & EPOLLIN) != 0) + accept_supervision_link((int)(intptr_t)closure); } /* @@ -363,6 +371,8 @@ static void propagate(afb_req_t req, const char *verb) xreq = xreq_from_req_x2(req); args = afb_xreq_json(xreq); + + /* extract the pid */ if (!json_object_object_get_ex(args, "pid", &item)) { afb_xreq_reply(xreq, NULL, "no-pid", NULL); return; @@ -373,14 +383,20 @@ static void propagate(afb_req_t req, const char *verb) afb_xreq_reply(xreq, NULL, "bad-pid", NULL); return; } + + /* get supervised of pid */ s = supervised_of_pid((pid_t)p); if (!s) { afb_req_reply(req, NULL, "unknown-pid", NULL); return; } json_object_object_del(args, "pid"); + + /* replace the verb to call if needed */ if (verb) xreq->request.called_verb = verb; + + /* call it now */ api = afb_stub_ws_client_api(s->stub); api.itf->call(api.closure, xreq); }