diff --git a/common/utils/T/tracer/enb.c b/common/utils/T/tracer/enb.c index f607743d1592f1473ad172ad9684a7ba17730104..a30366faf1eb8e645d5efba1cf664985cc60c255 100644 --- a/common/utils/T/tracer/enb.c +++ b/common/utils/T/tracer/enb.c @@ -12,7 +12,6 @@ #include "gui/gui.h" #include "filter/filter.h" #include "utils.h" -#include "../T_defs.h" #include "event_selector.h" #include "openair_logo.h" #include "config.h" @@ -875,6 +874,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); + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + restart: clear_remote_config(); enb_data.socket = connect_to(ip, port); @@ -884,9 +885,8 @@ restart: /* read messages */ while (1) { - char v[T_BUFFER_MAX]; event e; - e = get_event(enb_data.socket, v, database); + e = get_event(enb_data.socket, &ebuf, database); if (e.type == -1) goto restart; if (pthread_mutex_lock(&enb_data.lock)) abort(); handle_event(h, e); diff --git a/common/utils/T/tracer/event.c b/common/utils/T/tracer/event.c index 0917c010b3852a95a6e0fa6f56e48315c1d19b2b..f5d12e472c0ee09384ff5a1166421dfae4692dca 100644 --- a/common/utils/T/tracer/event.c +++ b/common/utils/T/tracer/event.c @@ -6,7 +6,7 @@ #include <stdlib.h> #include <string.h> -event get_event(int socket, char *event_buffer, void *database) +event get_event(int socket, OBUF *event_buffer, void *database) { #ifdef T_SEND_TIME struct timespec t; @@ -29,17 +29,23 @@ again: #endif if (fullread(socket, &type, sizeof(int)) == -1) goto read_error; length -= sizeof(int); - if (fullread(socket, event_buffer, length) == -1) goto read_error; + if (event_buffer->omaxsize < length) { + event_buffer->omaxsize = (length + 65535) & ~65535; + event_buffer->obuf = realloc(event_buffer->obuf, event_buffer->omaxsize); + if (event_buffer->obuf == NULL) { printf("out of memory\n"); exit(1); } + } + if (fullread(socket, event_buffer->obuf, length) == -1) goto read_error; + event_buffer->osize = length; - if (type == -1) append_received_config_chunk(event_buffer, length); + if (type == -1) append_received_config_chunk(event_buffer->obuf, length); if (type == -2) verify_config(); if (type == -1 || type == -2) goto again; #ifdef T_SEND_TIME - return new_event(t, type, length, event_buffer, database); + return new_event(t, type, length, event_buffer->obuf, database); #else - return new_event(type, length, event_buffer, database); + return new_event(type, length, event_buffer->obuf, database); #endif read_error: diff --git a/common/utils/T/tracer/event.h b/common/utils/T/tracer/event.h index 6272baf1a8f13216959db18951b606690315d46e..0170ab6680c6aac3c4b656ec803177c8e4ee7b6a 100644 --- a/common/utils/T/tracer/event.h +++ b/common/utils/T/tracer/event.h @@ -1,6 +1,7 @@ #ifndef _EVENT_H_ #define _EVENT_H_ +#include "utils.h" #include "../T_defs.h" #ifdef T_SEND_TIME #include <time.h> @@ -37,7 +38,7 @@ typedef struct { int ecount; } event; -event get_event(int s, char *v, void *d); +event get_event(int s, OBUF *v, void *d); #ifdef T_SEND_TIME event new_event(struct timespec sending_time, int type, diff --git a/common/utils/T/tracer/extract.c b/common/utils/T/tracer/extract.c index b9fca959eddf6a8428aee25b5aabf37cd51419b5..2aec38831fe2c528cd12cbaa3814e75813eb3bfe 100644 --- a/common/utils/T/tracer/extract.c +++ b/common/utils/T/tracer/extract.c @@ -99,10 +99,11 @@ int main(int n, char **v) found = 0; + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + while (1) { - char v[T_BUFFER_MAX]; event e; - e = get_event(fd, v, database); + e = get_event(fd, &ebuf, database); if (e.type == -1) break; if (e.type != input_event_id) continue; for (i = 0; i < filter_count; i++) diff --git a/common/utils/T/tracer/extract_config.c b/common/utils/T/tracer/extract_config.c index f35d765cec5b3366b88eca9bd9bc85d2697a18e4..a26c52aeda2a8ec31cf4748a0fc07a825d18a477 100644 --- a/common/utils/T/tracer/extract_config.c +++ b/common/utils/T/tracer/extract_config.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "utils.h" #include "../T_defs.h" void usage(void) @@ -35,14 +36,22 @@ int main(int n, char **v) in = fopen(input_filename, "r"); if (in == NULL) { perror(input_filename); abort(); } + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + while (1) { int type; int32_t length; - char v[T_BUFFER_MAX]; + char *v; int vpos = 0; /* read event from file */ if (fread(&length, 4, 1, in) != 1) break; + if (ebuf.omaxsize < length) { + ebuf.omaxsize = (length + 65535) & ~65535; + ebuf.obuf = realloc(ebuf.obuf, ebuf.omaxsize); + if (ebuf.obuf == NULL) { printf("out of memory\n"); exit(1); } + } + v = ebuf.obuf; memcpy(v+vpos, &length, 4); vpos += 4; #ifdef T_SEND_TIME diff --git a/common/utils/T/tracer/extract_input_subframe.c b/common/utils/T/tracer/extract_input_subframe.c index 02c5f3d56506d2889dc037918c1ec71ca1086d25..d7423182018df7a9f33a8d7c3202a6d810a3ed9f 100644 --- a/common/utils/T/tracer/extract_input_subframe.c +++ b/common/utils/T/tracer/extract_input_subframe.c @@ -104,11 +104,12 @@ err: fd = open(file, O_RDONLY); if (fd == -1) { perror(file); exit(1); } + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + /* get wanted frame/subframe */ while (1) { - char v[T_BUFFER_MAX]; event e; - e = get_event(fd, v, database); + e = get_event(fd, &ebuf, database); if (e.type == -1) break; if (e.type != input_event_id) continue; if (verbose) diff --git a/common/utils/T/tracer/extract_output_subframe.c b/common/utils/T/tracer/extract_output_subframe.c index b82ad0e7665d259358e08b27f7c1816659ca3b3b..d24393553cee537e16f25cc600e74780fc808bba 100644 --- a/common/utils/T/tracer/extract_output_subframe.c +++ b/common/utils/T/tracer/extract_output_subframe.c @@ -100,10 +100,12 @@ err: int last_frame = -1; int last_subframe = -1; int subframe_written = 0; + + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + while (1) { - char v[T_BUFFER_MAX]; event e; - e = get_event(fd, v, database); + e = get_event(fd, &ebuf, database); if (e.type == -1) break; if (e.type != output_event_id) continue; if (verbose) diff --git a/common/utils/T/tracer/hacks/dump_nack_signal.c b/common/utils/T/tracer/hacks/dump_nack_signal.c index 1627bdd14e925ad68797d16614be9e57bc23447e..bb8f1a9477bda7894ba8465a068b2825db5e6737 100644 --- a/common/utils/T/tracer/hacks/dump_nack_signal.c +++ b/common/utils/T/tracer/hacks/dump_nack_signal.c @@ -73,17 +73,22 @@ int main(int n, char **v) socket_send(socket, is_on, number_of_events * sizeof(int)) == -1) abort(); + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + char dump[10][T_BUFFER_MAX]; event dump_ev[10]; FILE *z = fopen("/tmp/dd", "w"); if (z == NULL) abort(); while (1) { - char v[T_BUFFER_MAX]; + char *v; event e; - e = get_event(socket, v, database); + e = get_event(socket, &ebuf, database); + v = ebuf.obuf; if (e.type == -1) break; if (e.type == ev_input) { int sf = e.e[2].i; - memcpy(dump[sf], v, T_BUFFER_MAX); + if (ebuf.osize > T_BUFFER_MAX) + { printf("event size too big\n"); exit(1); } + memcpy(dump[sf], ebuf.obuf, ebuf.osize); dump_ev[sf] = e; printf("input %d/%d\n", e.e[1].i, sf); if (fwrite(dump_ev[sf].e[4].b, dump_ev[sf].e[4].bsize, 1, z) != 1) abort(); diff --git a/common/utils/T/tracer/hacks/time_meas.c b/common/utils/T/tracer/hacks/time_meas.c index 04d4fa5acfcd026816c0345bc7513aa5759e0064..6bd29503011fb92e306dd10a7dd6539ebd0ee0f9 100644 --- a/common/utils/T/tracer/hacks/time_meas.c +++ b/common/utils/T/tracer/hacks/time_meas.c @@ -84,11 +84,12 @@ int main(int n, char **v) socket_send(socket, is_on, number_of_events * sizeof(int)) == -1) abort(); + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + while (1) { - char v[T_BUFFER_MAX]; event e; int on_off; - e = get_event(socket, v, database); + e = get_event(socket, &ebuf, database); if (e.type == -1) break; if (e.type != ev_fun) { printf("unhandled event %d\n", e.type); continue; } diff --git a/common/utils/T/tracer/macpdu2wireshark.c b/common/utils/T/tracer/macpdu2wireshark.c index be0bbd382142bf82f171401bac34f91a7e4d4f67..954f668aa420c0cd0070f58757df721727199e2a 100644 --- a/common/utils/T/tracer/macpdu2wireshark.c +++ b/common/utils/T/tracer/macpdu2wireshark.c @@ -246,11 +246,12 @@ int main(int n, char **v) new_thread(receiver, &d); + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + /* read messages */ while (1) { - char v[T_BUFFER_MAX]; event e; - e = get_event(in, v, database); + e = get_event(in, &ebuf, database); if (e.type == -1) break; if (!(e.type == ul_id || e.type == dl_id)) continue; handle_event(h, e); diff --git a/common/utils/T/tracer/record.c b/common/utils/T/tracer/record.c index b1a1bc60de8cb8bdd0b69604f414f7d5aa7b0802..a565884e52b071ff9da15974b04fa81427cfa943 100644 --- a/common/utils/T/tracer/record.c +++ b/common/utils/T/tracer/record.c @@ -123,14 +123,22 @@ int main(int n, char **v) if (signal(SIGINT, force_stop) == SIG_ERR) abort(); if (signal(SIGTSTP, force_stop) == SIG_ERR) abort(); + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + /* read messages */ while (run) { int type; int32_t length; - char v[T_BUFFER_MAX]; + char *v; int vpos = 0; if (fullread(socket, &length, 4) == -1) goto read_error; + if (ebuf.omaxsize < length) { + ebuf.omaxsize = (length + 65535) & ~65535; + ebuf.obuf = realloc(ebuf.obuf, ebuf.omaxsize); + if (ebuf.obuf == NULL) { printf("out of memory\n"); exit(1); } + } + v = ebuf.obuf; memcpy(v+vpos, &length, 4); vpos += 4; #ifdef T_SEND_TIME diff --git a/common/utils/T/tracer/replay.c b/common/utils/T/tracer/replay.c index be7e8d60c69fefcdd562ec79c5dea01c384b92c0..c199a668d58f7dfde3fc07378aaf112267d7afea 100644 --- a/common/utils/T/tracer/replay.c +++ b/common/utils/T/tracer/replay.c @@ -136,14 +136,22 @@ int main(int n, char **v) new_thread(get_message_thread, &socket); + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + while (1) { int type; int32_t length; - char v[T_BUFFER_MAX]; + char *v; int vpos = 0; /* read event from file */ if (fread(&length, 4, 1, in) != 1) break; + if (ebuf.omaxsize < length) { + ebuf.omaxsize = (length + 65535) & ~65535; + ebuf.obuf = realloc(ebuf.obuf, ebuf.omaxsize); + if (ebuf.obuf == NULL) { printf("out of memory\n"); exit(1); } + } + v = ebuf.obuf; memcpy(v+vpos, &length, 4); vpos += 4; #ifdef T_SEND_TIME diff --git a/common/utils/T/tracer/textlog.c b/common/utils/T/tracer/textlog.c index 32bf1ed791ce10060fb48b62d7f4b69c94b23ba9..bb773b42150b9fcc15b7378405818a4b14db0e42 100644 --- a/common/utils/T/tracer/textlog.c +++ b/common/utils/T/tracer/textlog.c @@ -10,7 +10,6 @@ #include "view/view.h" #include "gui/gui.h" #include "utils.h" -#include "../T_defs.h" #include "event_selector.h" #include "config.h" @@ -182,11 +181,12 @@ int main(int n, char **v) /* send the first message - activate selected traces */ is_on_changed(&textlog_data); + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + /* read messages */ while (1) { - char v[T_BUFFER_MAX]; event e; - e = get_event(textlog_data.socket, v, database); + e = get_event(textlog_data.socket, &ebuf, database); if (e.type == -1) abort(); handle_event(h, e); } diff --git a/common/utils/T/tracer/to_vcd.c b/common/utils/T/tracer/to_vcd.c index 82cd3393d7e9e26e59305cb3928a209d879bfdc4..097fdce93217af2d6b6bc48a204bc120c421775f 100644 --- a/common/utils/T/tracer/to_vcd.c +++ b/common/utils/T/tracer/to_vcd.c @@ -287,11 +287,12 @@ int main(int n, char **v) if (signal(SIGINT, force_stop) == SIG_ERR) abort(); if (signal(SIGTSTP, force_stop) == SIG_ERR) abort(); + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + /* read messages */ while (run) { - char v[T_BUFFER_MAX]; event e; - e = get_event(socket, v, database); + e = get_event(socket, &ebuf, database); if (e.type == -1) { printf("disconnected? let's quit gently\n"); break; } handle_event(h, e); } diff --git a/common/utils/T/tracer/ue.c b/common/utils/T/tracer/ue.c index 5709a4e79e06c82f2baa3a90b8cea683c768471c..6a7d03c897357c5e0d2cbbe07239fcb2bf2ebcfc 100644 --- a/common/utils/T/tracer/ue.c +++ b/common/utils/T/tracer/ue.c @@ -12,7 +12,6 @@ #include "gui/gui.h" #include "filter/filter.h" #include "utils.h" -#include "../T_defs.h" #include "event_selector.h" #include "openair_logo.h" #include "config.h" @@ -854,6 +853,8 @@ int main(int n, char **v) if (pthread_mutex_init(&ue_data.lock, NULL)) abort(); setup_event_selector(g, database, is_on, is_on_changed, &ue_data); + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + restart: clear_remote_config(); ue_data.socket = connect_to(ip, port); @@ -863,9 +864,8 @@ restart: /* read messages */ while (1) { - char v[T_BUFFER_MAX]; event e; - e = get_event(ue_data.socket, v, database); + e = get_event(ue_data.socket, &ebuf, database); if (e.type == -1) goto restart; if (pthread_mutex_lock(&ue_data.lock)) abort(); handle_event(h, e); diff --git a/common/utils/T/tracer/vcd.c b/common/utils/T/tracer/vcd.c index 0ad2756c2a49d218314aa4b586ba6a7bac0765ab..d4faa5fd8477d4698fd59721b910fca1dd6d26b6 100644 --- a/common/utils/T/tracer/vcd.c +++ b/common/utils/T/tracer/vcd.c @@ -10,7 +10,6 @@ #include "view/view.h" #include "gui/gui.h" #include "utils.h" -#include "../T_defs.h" #include "event_selector.h" #include "config.h" @@ -188,11 +187,12 @@ int main(int n, char **v) /* send the first message - activate selected traces */ is_on_changed(&vcd_data); + OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + /* read messages */ while (1) { - char v[T_BUFFER_MAX]; event e; - e = get_event(vcd_data.socket, v, database); + e = get_event(vcd_data.socket, &ebuf, database); if (e.type == -1) abort(); handle_event(h, e); }