Commit d171e18c authored by frtabu's avatar frtabu

fix some cppcheck errors and warnings in config module and T Tracer

parent 974167b5
......@@ -171,7 +171,7 @@ int config_check_unknown_cmdlineopt(char *prefix) {
if (strcmp(prefix,CONFIG_CHECKALLSECTIONS) == 0)
finalcheck = 1;
else if (strlen(prefix) > 0) {
sprintf(testprefix,"--%s.",prefix);
sprintf(testprefix,"--%.*s.",CONFIG_MAXOPTLENGTH-1,prefix);
}
}
......
......@@ -345,7 +345,7 @@ void free_configmodule(void) {
if( cfgptr->cfgmode != NULL) free(cfgptr->cfgmode);
printf ("[CONFIG] free %u config parameter pointers\n",cfgptr->num_cfgP);
printf ("[CONFIG] free %i config parameter pointers\n",cfgptr->num_cfgP);
for (int i=0; i<cfgptr->num_cfgP; i++) {
if ( cfgptr->cfgP[i] != NULL) free(cfgptr->cfgP[i]);
......
......@@ -202,9 +202,9 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork) {
}
void T_Config_Init(void) {
int T_port; /* by default we wait for the tracer */
int T_nowait; /* default port to listen to to wait for the tracer */
int T_dont_fork; /* default is to fork, see 'T_init' to understand */
int T_port=TTRACER_DEFAULT_PORTNUM; /* by default we wait for the tracer */
int T_nowait=0; /* default port to listen to to wait for the tracer */
int T_dont_fork=0; /* default is to fork, see 'T_init' to understand */
paramdef_t ttraceparams[] = CMDLINE_TTRACEPARAMS_DESC;
/* for a cleaner config file, TTracer params should be defined in a
* specific section...
......
......@@ -8,7 +8,7 @@
#include "T_defs.h"
#ifdef T_SEND_TIME
#include <time.h>
#include <time.h>
#endif
/* T message IDs */
......@@ -598,20 +598,21 @@ extern int *T_active;
#define TTRACER_CONFIG_PREFIX "TTracer"
/*------------------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
/* configuration parameters for TTRACE utility */
/* optname helpstr paramflags XXXptr defXXXval type numelt */
/*------------------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
#define TTRACER_DEFAULT_PORTNUM 2021
#define CMDLINE_TTRACEPARAMS_DESC { \
{"T_port", CONFIG_HLP_TPORT, 0, iptr:&T_port, defintval:2021, TYPE_INT, 0}, \
{"T_nowait", CONFIG_HLP_NOTWAIT, PARAMFLAG_BOOL, iptr:&T_nowait, defintval:0, TYPE_INT, 0}, \
{"T_dont_fork", CONFIG_HLP_TNOFORK, PARAMFLAG_BOOL, iptr:&T_dont_fork, defintval:0, TYPE_INT, 0}, \
{"T_stdout", CONFIG_HLP_STDOUT, PARAMFLAG_BOOL, iptr:&T_stdout, defintval:1, TYPE_INT, 0}, \
}
{"T_port", CONFIG_HLP_TPORT, 0, iptr:&T_port, defintval:TTRACER_DEFAULT_PORTNUM, TYPE_INT, 0},\
{"T_nowait", CONFIG_HLP_NOTWAIT, PARAMFLAG_BOOL, iptr:&T_nowait, defintval:0, TYPE_INT, 0},\
{"T_dont_fork", CONFIG_HLP_TNOFORK, PARAMFLAG_BOOL, iptr:&T_dont_fork, defintval:0, TYPE_INT, 0},\
{"T_stdout", CONFIG_HLP_STDOUT, PARAMFLAG_BOOL, iptr:&T_stdout, defintval:1, TYPE_INT, 0},\
}
/* log on stdout */
/* log on stdout */
void T_init(int remote_port, int wait_for_tracer, int dont_fork);
void T_Config_Init(void);
#else /* T_TRACER */
......
......@@ -49,7 +49,7 @@
//-------------------------------
FILE* g_msc_fd;
FILE *g_msc_fd;
char g_msc_proto2str[MAX_MSC_PROTOS][MSC_MAX_PROTO_NAME_LENGTH];
......@@ -70,15 +70,11 @@ void *msc_task(void *args_p)
//------------------------------------------------------------------------------
{
MessageDef *received_message_p = NULL;
// const char *msg_name = NULL;
// instance_t instance = 0;
// const char *msg_name = NULL;
// instance_t instance = 0;
long timer_id;
itti_mark_task_ready(TASK_MSC);
msc_start_use();
timer_setup(0, // seconds
50000, // usec
TASK_MSC,
......@@ -91,11 +87,9 @@ void *msc_task(void *args_p)
itti_receive_msg(TASK_MSC, &received_message_p);
if (received_message_p != NULL) {
// msg_name = ITTI_MSG_NAME (received_message_p);
// instance = ITTI_MSG_INSTANCE (received_message_p);
// msg_name = ITTI_MSG_NAME (received_message_p);
// instance = ITTI_MSG_INSTANCE (received_message_p);
switch (ITTI_MSG_ID(received_message_p)) {
case TIMER_HAS_EXPIRED: {
msc_flush_messages();
}
......@@ -119,6 +113,7 @@ void *msc_task(void *args_p)
}
}
}
fprintf(stderr, "Task MSC exiting\n");
return NULL;
}
......@@ -132,15 +127,16 @@ int msc_init(const msc_env_t envP, const int max_threadsP)
void *pointer_p;
char msc_filename[256];
fprintf(stderr, "Initializing MSC logs\n");
rv = snprintf(msc_filename, 256, "/tmp/openair.msc.%i.log", envP); // TODO NAME
rv = snprintf(msc_filename, 256, "/tmp/openair.msc.%u.log", envP); // TODO NAME
if ((0 >= rv) || (256 < rv)){
if ((0 >= rv) || (256 < rv)) {
fprintf(stderr, "Error in MSC log file name");
}
g_msc_fd = fopen(msc_filename,"w");
AssertFatal(g_msc_fd != NULL, "Could not open MSC log file %s : %s", msc_filename, strerror(errno));
rv = lfds611_stack_new(&g_msc_memory_stack_p, (lfds611_atom_t)max_threadsP + 2);
if (0 >= rv) {
AssertFatal (0, "lfds611_stack_new failed!\n");
}
......@@ -161,182 +157,335 @@ int msc_init(const msc_env_t envP, const int max_threadsP)
switch (i) {
case MSC_IP_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "IP_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_IP_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "IP_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if (envP == MSC_E_UTRAN_LIPA) {
msc_log_declare_proto(i);
}
break;
case MSC_NAS_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_RRC_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RRC_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_PDCP_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PDCP_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_RLC_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_MAC_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MAC_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_PHY_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PHY_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_PHY_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PHY_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_MAC_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MAC_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_RLC_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_PDCP_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PDCP_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_RRC_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RRC_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_S1AP_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S1AP_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
case MSC_GTPU_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "GTPU_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_GTPU_SGW:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "GTPU_SGW");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_MME_GW) || (envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_S1AP_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S1AP_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_MME_GW) || (envP == MSC_MME) || (envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_MMEAPP_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MME_APP");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
case MSC_NAS_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
msc_log_declare_proto(i);
break;
case MSC_NAS_EMM_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_EMM");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
case MSC_NAS_ESM_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_ESM");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
case MSC_SP_GWAPP_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "SP_GW_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if (envP == MSC_MME_GW) {
msc_log_declare_proto(i);
}
break;
case MSC_S11_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S11_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if (envP == MSC_MME) {
msc_log_declare_proto(i);
}
break;
case MSC_S6A_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S6A");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
case MSC_HSS:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "HSS");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
default:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "UNKNOWN");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
}
}
}
rv = itti_create_task (TASK_MSC, msc_task, NULL);
AssertFatal (rv == 0, "Create task for MSC failed!\n");
fprintf(stderr, "Initializing MSC logs Done\n");
......@@ -359,15 +508,17 @@ void msc_flush_messages(void)
int rv;
msc_queue_item_t *item_p = NULL;
while ((rv = lfds611_queue_dequeue( g_msc_message_queue_p, (void**)&item_p )) == 1) {
while ((rv = lfds611_queue_dequeue( g_msc_message_queue_p, (void **)&item_p )) == 1) {
if (NULL != item_p->message_str) {
fputs(item_p->message_str, g_msc_fd);
// TODO BIN DATA
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, item_p->message_str );
}
// TODO FREE BIN DATA
free(item_p);
}
fflush(g_msc_fd);
}
......@@ -377,13 +528,17 @@ void msc_end(void)
//------------------------------------------------------------------------------
{
int rv;
if (NULL != g_msc_fd ) {
msc_flush_messages();
rv = fflush(g_msc_fd);
if (rv != 0) {
fprintf(stderr, "Error while flushing stream of MSC log file: %s", strerror(errno));
}
rv = fclose(g_msc_fd);
if (rv != 0) {
fprintf(stderr, "Error while closing MSC log file: %s", strerror(errno));
}
......@@ -393,7 +548,7 @@ void msc_end(void)
//------------------------------------------------------------------------------
void msc_log_declare_proto(
const msc_proto_t protoP
)
)
//------------------------------------------------------------------------------
{
int rv = 0;
......@@ -403,35 +558,43 @@ void msc_log_declare_proto(
if ((MIN_MSC_PROTOS <= protoP) && (MAX_MSC_PROTOS > protoP)) {
// may be build a memory pool for that also ?
new_item_p = malloc(sizeof(msc_queue_item_t));
if (NULL != new_item_p) {
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
if (0 == rv) {
msc_flush_messages();
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
}
if (1 == rv) {
rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [PROTO] %d %s\n", __sync_fetch_and_add (&g_message_number, 1), protoP, &g_msc_proto2str[protoP][0]);
if (0 > rv) {
fprintf(stderr, "Error while declaring new protocol in MSC: %s", strerror(errno));
}
new_item_p->message_str = char_message_p;
new_item_p->message_str_size = rv;
new_item_p->message_bin = NULL;
new_item_p->message_bin_size = 0;
rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
if (0 == rv) {
rv = lfds611_queue_guaranteed_enqueue(g_msc_message_queue_p, new_item_p );
if (0 == rv) {
fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
free(new_item_p);
}
}
return;
} else {
fprintf(stderr, "Error while lfds611_stack_pop()\n");
}
free(new_item_p);
} else {
fprintf(stderr, "Error while malloc in MSC");
......@@ -450,43 +613,52 @@ void msc_log_event(
msc_queue_item_t *new_item_p = NULL;
char *char_message_p = NULL;
if ((MIN_MSC_PROTOS > protoP) || (MAX_MSC_PROTOS <= protoP)) {
return;
}
new_item_p = malloc(sizeof(msc_queue_item_t));
if (NULL != new_item_p) {
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
if (0 == rv) {
msc_flush_messages();
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
}
if (1 == rv) {
rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [EVENT] %d ", __sync_fetch_and_add (&g_message_number, 1), protoP);
if ((0 > rv) || (MSC_MAX_MESSAGE_LENGTH < rv)) {
fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
goto error_event;
}
va_start(args, format);
rv2 = vsnprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, format, args);
va_end(args);
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
goto error_event;
}
rv += rv2;
rv2 = snprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, "\n");
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
goto error_event;
}
rv += rv2;
new_item_p->message_str = char_message_p;
new_item_p->message_str_size = rv;
new_item_p->message_bin = NULL;
new_item_p->message_bin_size = 0;
rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
if (0 == rv) {
fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
......@@ -496,6 +668,7 @@ void msc_log_event(
fprintf(stderr, "Error while lfds611_stack_pop()\n");
}
}
return;
error_event:
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
......@@ -503,10 +676,10 @@ error_event:
}
//------------------------------------------------------------------------------
void msc_log_message(
const char * const message_operationP,
const char *const message_operationP,
const msc_proto_t proto1P,
const msc_proto_t proto2P,
const uint8_t * const bytesP,
const uint8_t *const bytesP,
const unsigned int num_bytes,
char *format, ...)
//------------------------------------------------------------------------------
......@@ -518,46 +691,54 @@ void msc_log_message(
msc_queue_item_t *new_item_p = NULL;
char *char_message_p = NULL;
if ((MIN_MSC_PROTOS > proto1P) || (MAX_MSC_PROTOS <= proto1P) ||
(MIN_MSC_PROTOS > proto2P) || (MAX_MSC_PROTOS <= proto2P) ) {
return;
}
new_item_p = malloc(sizeof(msc_queue_item_t));
if (NULL != new_item_p) {
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
if (0 == rv) {
msc_flush_messages();
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
}
if (1 == rv) {
rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [MESSAGE] %d %s %d %"PRIu64" ",
__sync_fetch_and_add (&g_message_number, 1), proto1P, message_operationP, proto2P, mac);
if ((0 > rv) || (MSC_MAX_MESSAGE_LENGTH < rv)) {
fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
goto error_event;
}
va_start(args, format);
rv2 = vsnprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, format, args);
va_end(args);
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
goto error_event;
}
rv += rv2;
rv2 = snprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, "\n");
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
goto error_event;
}
rv += rv2;
new_item_p->message_str = char_message_p;
new_item_p->message_str_size = rv;
new_item_p->message_bin = NULL; // TO DO
new_item_p->message_bin_size = 0; // TO DO
rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
if (0 == rv) {
fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
......@@ -568,6 +749,7 @@ void msc_log_message(
msc_flush_messages();
}
}
return;
error_event:
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
......@@ -578,8 +760,7 @@ error_event:
// function called when oai loader loads the msc shared lib
int msc_autoinit(msc_interface_t *msc_interface)
//------------------------------------------------------------------------------
{
{
msc_interface->msc_init = msc_init;
msc_interface->msc_start_use = msc_start_use;
msc_interface->msc_end = msc_end;
......@@ -587,4 +768,4 @@ int msc_autoinit(msc_interface_t *msc_interface)
msc_interface->msc_log_message = msc_log_message;
msc_interface->msc_loaded = 1;
return 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