X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafs-supervisor.c;h=1e92b9f3424dabc964b204f6e77d251d2d5bafea;hb=ca820c65c2b03a24e8936218171c6c1d138fd1f7;hp=8cf21cb589d314c9faf93724a91234fd406313a6;hpb=abbb4599f0b921c6f434b6bd02bcfb277eecf745;p=src%2Fapp-framework-binder.git diff --git a/src/afs-supervisor.c b/src/afs-supervisor.c index 8cf21cb5..1e92b9f3 100644 --- a/src/afs-supervisor.c +++ b/src/afs-supervisor.c @@ -36,7 +36,7 @@ #include #include "afs-supervision.h" -#include "afb-common.h" +#include "afb-systemd.h" #include "afb-session.h" #include "afb-cred.h" #include "afb-stub-ws.h" @@ -45,6 +45,7 @@ #include "afb-api-so-v2.h" #include "afb-api-ws.h" #include "afb-apiset.h" +#include "afb-fdev.h" #include "jobs.h" #include "verbose.h" #include "wrap-json.h" @@ -193,13 +194,20 @@ static void on_supervised_hangup(struct afb_stub_ws *stub) static int make_supervised(int fd, struct afb_cred *cred) { struct supervised *s; + struct fdev *fdev; s = malloc(sizeof *s); if (!s) return -1; + fdev = afb_fdev_create(fd); + if (!fdev) { + free(s); + return -1; + } + s->cred = cred; - s->stub = afb_stub_ws_create_client(fd, supervision_apiname, empty_apiset); + s->stub = afb_stub_ws_create_client(fdev, supervision_apiname, empty_apiset); if (!s->stub) { free(s); return -1; @@ -277,13 +285,17 @@ static void discovered_cb(void *closure, pid_t pid) struct supervised *s; s = supervised_of_pid(pid); - if (!s) + if (!s) { + (*(int*)closure)++; kill(pid, SIGHUP); + } } -static void discover_supervised() +static int discover_supervised() { - afs_discover("afb-daemon", discovered_cb, NULL); + int n = 0; + afs_discover("afb-daemon", discovered_cb, &n); + return n; } /** @@ -335,7 +347,7 @@ static int init(const char *spec) } /* integrate the socket to the loop */ - rc = sd_event_add_io(afb_common_get_event_loop(), + rc = sd_event_add_io(afb_systemd_get_event_loop(), NULL, fd, EPOLLIN, listening, NULL); if (rc < 0) { @@ -411,6 +423,12 @@ static void f_list(struct afb_req req) afb_req_success(req, resu, NULL); } +static void f_discover(struct afb_req req) +{ + discover_supervised(); + afb_req_success(req, NULL, NULL); +} + static void propagate(struct afb_req req, const char *verb) { struct afb_xreq *xreq; @@ -555,6 +573,13 @@ static const struct afb_verb_v2 _afb_verbs_v2_supervision[] = { .info = NULL, .session = AFB_SESSION_NONE_V2 }, + { + .verb = "discover", + .callback = f_discover, + .auth = &_afb_auths_v2_supervision[0], + .info = NULL, + .session = AFB_SESSION_NONE_V2 + }, { .verb = NULL } };