Commit 0b7d2420 authored by Cedric Roux's avatar Cedric Roux

enb.c stays alive if tracee dies

enb.c will then try to reconnect.
parent 88c44ef9
...@@ -17,6 +17,13 @@ static char *PUT(char *to, int tosize, char c) ...@@ -17,6 +17,13 @@ static char *PUT(char *to, int tosize, char c)
return to; return to;
} }
void clear_remote_config(void)
{
free(remote);
remote = NULL;
remote_size = 0;
}
void append_received_config_chunk(char *buf, int length) void append_received_config_chunk(char *buf, int length)
{ {
int buflen = *(int *)buf; int buflen = *(int *)buf;
......
#ifndef _CONFIG_H_ #ifndef _CONFIG_H_
#define _CONFIG_H_ #define _CONFIG_H_
void clear_remote_config(void);
void append_received_config_chunk(char *buf, int length); void append_received_config_chunk(char *buf, int length);
void load_config_file(char *filename); void load_config_file(char *filename);
void verify_config(void); void verify_config(void);
......
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <pthread.h> #include <pthread.h>
#include <signal.h> #include <signal.h>
#include "database.h" #include "database.h"
...@@ -43,10 +44,16 @@ void is_on_changed(void *_d) ...@@ -43,10 +44,16 @@ void is_on_changed(void *_d)
if (socket_send(d->socket, &t, 1) == -1 || if (socket_send(d->socket, &t, 1) == -1 ||
socket_send(d->socket, &d->nevents, sizeof(int)) == -1 || socket_send(d->socket, &d->nevents, sizeof(int)) == -1 ||
socket_send(d->socket, d->is_on, d->nevents * sizeof(int)) == -1) socket_send(d->socket, d->is_on, d->nevents * sizeof(int)) == -1)
abort(); goto connection_dies;
no_connection: no_connection:
if (pthread_mutex_unlock(&d->lock)) abort(); 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) void usage(void)
...@@ -380,6 +387,8 @@ int main(int n, char **v) ...@@ -380,6 +387,8 @@ int main(int n, char **v)
if (pthread_mutex_init(&enb_data.lock, NULL)) abort(); if (pthread_mutex_init(&enb_data.lock, NULL)) abort();
setup_event_selector(g, database, is_on, is_on_changed, &enb_data); setup_event_selector(g, database, is_on, is_on_changed, &enb_data);
restart:
clear_remote_config();
enb_data.socket = connect_to(ip, port); enb_data.socket = connect_to(ip, port);
/* send the first message - activate selected traces */ /* send the first message - activate selected traces */
...@@ -390,7 +399,7 @@ int main(int n, char **v) ...@@ -390,7 +399,7 @@ int main(int n, char **v)
char v[T_BUFFER_MAX]; char v[T_BUFFER_MAX];
event e; event e;
e = get_event(enb_data.socket, v, database); e = get_event(enb_data.socket, v, database);
if (e.type == -1) abort(); if (e.type == -1) goto restart;
handle_event(h, e); handle_event(h, e);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment