aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-supervision.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2018-02-14 15:12:30 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2018-02-14 15:12:30 +0100
commitabbb4599f0b921c6f434b6bd02bcfb277eecf745 (patch)
treefd8a7449742fbb4c445286529349ab12cca9540a /src/afb-supervision.c
parent4788fcd7becaef5a665dea0f9c0345401c80f757 (diff)
afs-supervisor: Add discovery mechanic
Change-Id: Icfcdcc16d0433454c9bb0785d0690f7f173980ae Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-supervision.c')
-rw-r--r--src/afb-supervision.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/afb-supervision.c b/src/afb-supervision.c
index ecdcbf20..f41ca18b 100644
--- a/src/afb-supervision.c
+++ b/src/afb-supervision.c
@@ -45,6 +45,7 @@
#include "afb-debug.h"
#include "verbose.h"
#include "wrap-json.h"
+#include "jobs.h"
extern struct afb_config *main_config;
@@ -111,20 +112,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 */
@@ -195,6 +200,7 @@ static void try_connect_supervisor()
ERROR("Creation of supervisor failed: %m");
goto end2;
}
+ afb_stub_ws_on_hangup(supervisor, on_supervisor_hangup);
/* successful termination */
goto end;
@@ -205,11 +211,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
*/