Commit b3889a44 authored by Cedric Roux's avatar Cedric Roux

integration of local tracer into tracee - step 2

The local tracer now waits for the remote tracer to connect,
that's no more the other way around.

All the remote tracers (textlog, enb, vcd) have also been converted.
parent b6854b15
...@@ -16,7 +16,7 @@ void iq_plot_set_sized(void *_plot, short *data, int len, int pp); ...@@ -16,7 +16,7 @@ void iq_plot_set_sized(void *_plot, short *data, int len, int pp);
void iq_plot_add_iq_point_loop(void *_plot, short i, short q, int pp); void iq_plot_add_iq_point_loop(void *_plot, short i, short q, int pp);
void iq_plot_add_energy_point_loop(void *_plot, int e, int pp); void iq_plot_add_energy_point_loop(void *_plot, int e, int pp);
void *forwarder(char *ip, int port); void *forwarder(int port);
void forward(void *forwarder, char *buf, int size); void forward(void *forwarder, char *buf, int size);
void forward_start_client(void *forwarder, int socket); void forward_start_client(void *forwarder, int socket);
......
...@@ -19,6 +19,7 @@ typedef struct { ...@@ -19,6 +19,7 @@ typedef struct {
view *legacy; view *legacy;
} enb_gui; } enb_gui;
#define DEFAULT_REMOTE_IP "127.0.0.1"
#define DEFAULT_REMOTE_PORT 2021 #define DEFAULT_REMOTE_PORT 2021
void usage(void) void usage(void)
...@@ -33,8 +34,10 @@ void usage(void) ...@@ -33,8 +34,10 @@ void usage(void)
" note: you may pass several -on/-off/-ON/-OFF,\n" " note: you may pass several -on/-off/-ON/-OFF,\n"
" they will be processed in order\n" " they will be processed in order\n"
" by default, all is off\n" " by default, all is off\n"
" -p <port> use given port (default %d)\n" " -ip <host> connect to given IP address (default %s)\n"
" -p <port> connect to given port (default %d)\n"
" -debug-gui activate GUI debug logs\n", " -debug-gui activate GUI debug logs\n",
DEFAULT_REMOTE_IP,
DEFAULT_REMOTE_PORT DEFAULT_REMOTE_PORT
); );
exit(1); exit(1);
...@@ -204,6 +207,7 @@ int main(int n, char **v) ...@@ -204,6 +207,7 @@ int main(int n, char **v)
extern int volatile gui_logd; extern int volatile gui_logd;
char *database_filename = NULL; char *database_filename = NULL;
void *database; void *database;
char *ip = DEFAULT_REMOTE_IP;
int port = DEFAULT_REMOTE_PORT; int port = DEFAULT_REMOTE_PORT;
char **on_off_name; char **on_off_name;
int *on_off_action; int *on_off_action;
...@@ -225,6 +229,7 @@ int main(int n, char **v) ...@@ -225,6 +229,7 @@ int main(int n, char **v)
if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
if (!strcmp(v[i], "-d")) if (!strcmp(v[i], "-d"))
{ if (i > n-2) usage(); database_filename = v[++i]; continue; } { if (i > n-2) usage(); database_filename = v[++i]; continue; }
if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
if (!strcmp(v[i], "-p")) if (!strcmp(v[i], "-p"))
{ if (i > n-2) usage(); port = atoi(v[++i]); continue; } { if (i > n-2) usage(); port = atoi(v[++i]); continue; }
if (!strcmp(v[i], "-on")) { if (i > n-2) usage(); if (!strcmp(v[i], "-on")) { if (i > n-2) usage();
...@@ -341,7 +346,7 @@ int main(int n, char **v) ...@@ -341,7 +346,7 @@ int main(int n, char **v)
for (i = 0; i < on_off_n; i++) for (i = 0; i < on_off_n; i++)
on_off(database, on_off_name[i], is_on, on_off_action[i]); on_off(database, on_off_name[i], is_on, on_off_action[i]);
s = get_connection("0.0.0.0", port); s = connect_to(ip, port);
/* send the first message - activate selected traces */ /* send the first message - activate selected traces */
t = 0; t = 0;
......
...@@ -102,10 +102,11 @@ void forward_start_client(void *_f, int s) ...@@ -102,10 +102,11 @@ void forward_start_client(void *_f, int s)
new_thread(forward_s_to_sc, f); new_thread(forward_s_to_sc, f);
} }
void *forwarder(char *ip, int port) int get_connection(char *addr, int port);
void *forwarder(int port)
{ {
forward_data *f; forward_data *f;
struct sockaddr_in a;
f = malloc(sizeof(*f)); if (f == NULL) abort(); f = malloc(sizeof(*f)); if (f == NULL) abort();
...@@ -119,23 +120,9 @@ void *forwarder(char *ip, int port) ...@@ -119,23 +120,9 @@ void *forwarder(char *ip, int port)
f->memusage = 0; f->memusage = 0;
f->last_warning_memusage = 0; f->last_warning_memusage = 0;
printf("connecting to remote tracer %s:%d\n", ip, port); printf("waiting for remote tracer on port %d\n", port);
again:
f->s = socket(AF_INET, SOCK_STREAM, 0);
if (f->s == -1) { perror("socket"); exit(1); }
a.sin_family = AF_INET; f->s = get_connection("127.0.0.1", port);
a.sin_port = htons(port);
a.sin_addr.s_addr = inet_addr(ip);
if (connect(f->s, (struct sockaddr *)&a, sizeof(a)) == -1) {
perror("connect");
close(f->s);
printf("trying again in 1s\n");
sleep(1);
goto again;
}
printf("connected\n"); printf("connected\n");
......
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
#define DEFAULT_REMOTE_IP "127.0.0.1" #define DEFAULT_PORT 2021
#define DEFAULT_REMOTE_PORT 2021
#include "defs.h" #include "defs.h"
...@@ -97,11 +96,9 @@ void usage(void) ...@@ -97,11 +96,9 @@ void usage(void)
printf( printf(
"tracer - local side\n" "tracer - local side\n"
"options:\n" "options:\n"
" -r <IP address> <port> forwards packets to remote IP:port\n" " -p <port> wait for remote tracer on port <port> (default %d)\n"
" (default %s:%d)\n" " -nowait don't wait for remote tracer, start tracee immediately\n",
" -nowait don't wait for remote tracer,\n" DEFAULT_PORT
" start tracee immediately\n",
DEFAULT_REMOTE_IP, DEFAULT_REMOTE_PORT
); );
exit(1); exit(1);
} }
...@@ -110,30 +107,29 @@ int main(int n, char **v) ...@@ -110,30 +107,29 @@ int main(int n, char **v)
{ {
int s; int s;
int i; int i;
char *remote_ip = DEFAULT_REMOTE_IP; int port = DEFAULT_PORT;
int remote_port = DEFAULT_REMOTE_PORT; int local_port = 2020;
int port = 2020;
int dont_wait = 0; int dont_wait = 0;
void *f; void *f;
for (i = 1; i < n; i++) { for (i = 1; i < n; i++) {
if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
if (!strcmp(v[i], "-r")) { if (i > n-3) usage(); if (!strcmp(v[i], "-p")) { if (i > n-2) usage();
remote_ip = v[++i]; remote_port = atoi(v[++i]); continue; } port = atoi(v[++i]); continue; }
if (!strcmp(v[i], "-nowait")) { dont_wait = 1; continue; } if (!strcmp(v[i], "-nowait")) { dont_wait = 1; continue; }
printf("ERROR: unknown option %s\n", v[i]); printf("ERROR: unknown option %s\n", v[i]);
usage(); usage();
} }
init_shm(); init_shm();
s = get_connection("127.0.0.1", port); s = get_connection("127.0.0.1", local_port);
if (dont_wait) { if (dont_wait) {
char t = 2; char t = 2;
if (write(s, &t, 1) != 1) abort(); if (write(s, &t, 1) != 1) abort();
} }
f = forwarder(remote_ip, remote_port); f = forwarder(port);
forward_start_client(f, s); forward_start_client(f, s);
/* read messages */ /* read messages */
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "event_selector.h" #include "event_selector.h"
#include "config.h" #include "config.h"
#define DEFAULT_REMOTE_IP "127.0.0.1"
#define DEFAULT_REMOTE_PORT 2021 #define DEFAULT_REMOTE_PORT 2021
void usage(void) void usage(void)
...@@ -27,10 +28,12 @@ void usage(void) ...@@ -27,10 +28,12 @@ void usage(void)
" note: you may pass several -on/-off/-ON/-OFF,\n" " note: you may pass several -on/-off/-ON/-OFF,\n"
" they will be processed in order\n" " they will be processed in order\n"
" by default, all is off\n" " by default, all is off\n"
" -p <port> use given port (default %d)\n" " -ip <host> connect to given IP address (default %s)\n"
" -p <port> connect to given port (default %d)\n"
" -x GUI output\n" " -x GUI output\n"
" -debug-gui activate GUI debug logs\n" " -debug-gui activate GUI debug logs\n"
" -no-gui disable GUI entirely\n", " -no-gui disable GUI entirely\n",
DEFAULT_REMOTE_IP,
DEFAULT_REMOTE_PORT DEFAULT_REMOTE_PORT
); );
exit(1); exit(1);
...@@ -48,6 +51,7 @@ int main(int n, char **v) ...@@ -48,6 +51,7 @@ int main(int n, char **v)
extern int volatile gui_logd; extern int volatile gui_logd;
char *database_filename = NULL; char *database_filename = NULL;
void *database; void *database;
char *ip = DEFAULT_REMOTE_IP;
int port = DEFAULT_REMOTE_PORT; int port = DEFAULT_REMOTE_PORT;
char **on_off_name; char **on_off_name;
int *on_off_action; int *on_off_action;
...@@ -72,6 +76,7 @@ int main(int n, char **v) ...@@ -72,6 +76,7 @@ int main(int n, char **v)
if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
if (!strcmp(v[i], "-d")) if (!strcmp(v[i], "-d"))
{ if (i > n-2) usage(); database_filename = v[++i]; continue; } { if (i > n-2) usage(); database_filename = v[++i]; continue; }
if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
if (!strcmp(v[i], "-p")) if (!strcmp(v[i], "-p"))
{ if (i > n-2) usage(); port = atoi(v[++i]); continue; } { if (i > n-2) usage(); port = atoi(v[++i]); continue; }
if (!strcmp(v[i], "-on")) { if (i > n-2) usage(); if (!strcmp(v[i], "-on")) { if (i > n-2) usage();
...@@ -136,7 +141,7 @@ int main(int n, char **v) ...@@ -136,7 +141,7 @@ int main(int n, char **v)
for (i = 0; i < on_off_n; i++) for (i = 0; i < on_off_n; i++)
on_off(database, on_off_name[i], is_on, on_off_action[i]); on_off(database, on_off_name[i], is_on, on_off_action[i]);
s = get_connection("0.0.0.0", port); s = connect_to(ip, port);
/* send the first message - activate selected traces */ /* send the first message - activate selected traces */
t = 0; t = 0;
......
...@@ -125,6 +125,32 @@ int fullread(int fd, void *_buf, int count) ...@@ -125,6 +125,32 @@ int fullread(int fd, void *_buf, int count)
return ret; return ret;
} }
int connect_to(char *addr, int port)
{
int s;
struct sockaddr_in a;
printf("connecting to %s:%d\n", addr, port);
again:
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == -1) { perror("socket"); exit(1); }
a.sin_family = AF_INET;
a.sin_port = htons(port);
a.sin_addr.s_addr = inet_addr(addr);
if (connect(s, (struct sockaddr *)&a, sizeof(a)) == -1) {
perror("connect");
close(s);
printf("trying again in 1s\n");
sleep(1);
goto again;
}
return s;
}
/****************************************************************************/ /****************************************************************************/
/* buffer */ /* buffer */
/****************************************************************************/ /****************************************************************************/
......
...@@ -23,6 +23,7 @@ list *list_append(list *l, void *data); ...@@ -23,6 +23,7 @@ list *list_append(list *l, void *data);
void socket_send(int socket, void *buffer, int size); void socket_send(int socket, void *buffer, int size);
int get_connection(char *addr, int port); int get_connection(char *addr, int port);
int fullread(int fd, void *_buf, int count); int fullread(int fd, void *_buf, int count);
int connect_to(char *addr, int port);
/****************************************************************************/ /****************************************************************************/
/* buffer */ /* buffer */
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "event_selector.h" #include "event_selector.h"
#include "config.h" #include "config.h"
#define DEFAULT_REMOTE_IP "127.0.0.1"
#define DEFAULT_REMOTE_PORT 2021 #define DEFAULT_REMOTE_PORT 2021
void usage(void) void usage(void)
...@@ -27,8 +28,10 @@ void usage(void) ...@@ -27,8 +28,10 @@ void usage(void)
" note: you may pass several -on/-off/-ON/-OFF,\n" " note: you may pass several -on/-off/-ON/-OFF,\n"
" they will be processed in order\n" " they will be processed in order\n"
" by default, all is off\n" " by default, all is off\n"
" -p <port> use given port (default %d)\n" " -ip <host> connect to given IP address (default %s)\n"
" -p <port> connect to given port (default %d)\n"
" -debug-gui activate GUI debug logs\n", " -debug-gui activate GUI debug logs\n",
DEFAULT_REMOTE_IP,
DEFAULT_REMOTE_PORT DEFAULT_REMOTE_PORT
); );
exit(1); exit(1);
...@@ -88,6 +91,7 @@ int main(int n, char **v) ...@@ -88,6 +91,7 @@ int main(int n, char **v)
extern int volatile gui_logd; extern int volatile gui_logd;
char *database_filename = NULL; char *database_filename = NULL;
void *database; void *database;
char *ip = DEFAULT_REMOTE_IP;
int port = DEFAULT_REMOTE_PORT; int port = DEFAULT_REMOTE_PORT;
char **on_off_name; char **on_off_name;
int *on_off_action; int *on_off_action;
...@@ -108,6 +112,7 @@ int main(int n, char **v) ...@@ -108,6 +112,7 @@ int main(int n, char **v)
if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
if (!strcmp(v[i], "-d")) if (!strcmp(v[i], "-d"))
{ if (i > n-2) usage(); database_filename = v[++i]; continue; } { if (i > n-2) usage(); database_filename = v[++i]; continue; }
if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
if (!strcmp(v[i], "-p")) if (!strcmp(v[i], "-p"))
{ if (i > n-2) usage(); port = atoi(v[++i]); continue; } { if (i > n-2) usage(); port = atoi(v[++i]); continue; }
if (!strcmp(v[i], "-on")) { if (i > n-2) usage(); if (!strcmp(v[i], "-on")) { if (i > n-2) usage();
...@@ -147,7 +152,7 @@ int main(int n, char **v) ...@@ -147,7 +152,7 @@ int main(int n, char **v)
for (i = 0; i < on_off_n; i++) for (i = 0; i < on_off_n; i++)
on_off(database, on_off_name[i], is_on, on_off_action[i]); on_off(database, on_off_name[i], is_on, on_off_action[i]);
s = get_connection("0.0.0.0", port); s = connect_to(ip, port);
/* send the first message - activate selected traces */ /* send the first message - activate selected traces */
t = 0; t = 0;
......
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