From 0b7d24208375cf529f5ab80dab5e6e2762034d79 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Sun, 5 Jun 2016 17:57:57 +0200
Subject: [PATCH] enb.c stays alive if tracee dies

enb.c will then try to reconnect.
---
 common/utils/T/tracer/config.c |  7 +++++++
 common/utils/T/tracer/config.h |  1 +
 common/utils/T/tracer/enb.c    | 13 +++++++++++--
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/common/utils/T/tracer/config.c b/common/utils/T/tracer/config.c
index 98085956a2..f88966ed79 100644
--- a/common/utils/T/tracer/config.c
+++ b/common/utils/T/tracer/config.c
@@ -17,6 +17,13 @@ static char *PUT(char *to, int tosize, char c)
   return to;
 }
 
+void  clear_remote_config(void)
+{
+  free(remote);
+  remote = NULL;
+  remote_size = 0;
+}
+
 void append_received_config_chunk(char *buf, int length)
 {
   int buflen = *(int *)buf;
diff --git a/common/utils/T/tracer/config.h b/common/utils/T/tracer/config.h
index 5234b0f537..f90869eb66 100644
--- a/common/utils/T/tracer/config.h
+++ b/common/utils/T/tracer/config.h
@@ -1,6 +1,7 @@
 #ifndef _CONFIG_H_
 #define _CONFIG_H_
 
+void clear_remote_config(void);
 void append_received_config_chunk(char *buf, int length);
 void load_config_file(char *filename);
 void verify_config(void);
diff --git a/common/utils/T/tracer/enb.c b/common/utils/T/tracer/enb.c
index 3f1e864763..a8c4232892 100644
--- a/common/utils/T/tracer/enb.c
+++ b/common/utils/T/tracer/enb.c
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <pthread.h>
 #include <signal.h>
 #include "database.h"
@@ -43,10 +44,16 @@ void is_on_changed(void *_d)
   if (socket_send(d->socket, &t, 1) == -1 ||
       socket_send(d->socket, &d->nevents, sizeof(int)) == -1 ||
       socket_send(d->socket, d->is_on, d->nevents * sizeof(int)) == -1)
-    abort();
+    goto connection_dies;
 
 no_connection:
   if (pthread_mutex_unlock(&d->lock)) abort();
+  return;
+
+connection_dies:
+  close(d->socket);
+  d->socket = -1;
+  if (pthread_mutex_unlock(&d->lock)) abort();
 }
 
 void usage(void)
@@ -380,6 +387,8 @@ int main(int n, char **v)
   if (pthread_mutex_init(&enb_data.lock, NULL)) abort();
   setup_event_selector(g, database, is_on, is_on_changed, &enb_data);
 
+restart:
+  clear_remote_config();
   enb_data.socket = connect_to(ip, port);
 
   /* send the first message - activate selected traces */
@@ -390,7 +399,7 @@ int main(int n, char **v)
     char v[T_BUFFER_MAX];
     event e;
     e = get_event(enb_data.socket, v, database);
-    if (e.type == -1) abort();
+    if (e.type == -1) goto restart;
     handle_event(h, e);
   }
 
-- 
GitLab