diff options
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | include/dlt/dlt_client.h | 24 | ||||
-rw-r--r-- | src/console/dlt-control-common.c | 6 | ||||
-rw-r--r-- | src/console/dlt-control.c | 14 | ||||
-rw-r--r-- | src/console/dlt-receive.c | 14 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_client.c | 4 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_connection.c | 15 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_connection_types.h | 3 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_event_handler.c | 35 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_event_handler.h | 2 | ||||
-rw-r--r-- | src/gateway/dlt_gateway.c | 9 | ||||
-rw-r--r-- | src/lib/dlt_client.c | 32 | ||||
-rw-r--r-- | src/lib/dlt_user.c | 14 | ||||
-rw-r--r-- | src/tests/dlt-test-client.c | 12 | ||||
-rw-r--r-- | src/tests/dlt-test-multi-process-client.c | 12 | ||||
-rw-r--r-- | src/tests/dlt-test-stress-client.c | 12 |
16 files changed, 195 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f97e491..f05d566 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,8 @@ option(WITH_DLT_LOGSTORAGE_CTRL_UDEV "PROTOTYPE! Set to ON to build logstorage c option(WITH_DLT_LOGSTORAGE_CTRL_PROP "PROTOTYPE! Set to ON to build logstorage control application with proprietary support" OFF) option(WITH_DLT_USE_IPv6 "Set to ON for IPv6 support" ON) option(WITH_DLT_KPI "Set to ON to build src/kpi binaries" ON) +option(WITH_DLT_FATAL_LOG_TRAP "Set to ON to enable DLT_LOG_FATAL trap (trigger segv inside dlt-user library)" OFF) + # RPM settings set( GENIVI_RPM_RELEASE "1")#${DLT_REVISION}") set( LICENSE "Mozilla Public License Version 2.0" ) @@ -194,6 +196,10 @@ if(WITH_DLT_LOGSTORAGE_CTRL_PROP) add_definitions( -DDLT_LOGSTORAGE_CTRL_PROP) endif(WITH_DLT_LOGSTORAGE_CTRL_PROP) +if (WITH_DLT_FATAL_LOG_TRAP) + add_definitions( -DDLT_FATAL_LOG_RESET_ENABLE) +endif(WITH_DLT_FATAL_LOG_TRAP) + add_subdirectory( doc ) add_subdirectory( src ) add_subdirectory( include ) diff --git a/include/dlt/dlt_client.h b/include/dlt/dlt_client.h index 9af7421..587c6ca 100644 --- a/include/dlt/dlt_client.h +++ b/include/dlt/dlt_client.h @@ -249,6 +249,30 @@ DltReturnValue dlt_client_send_reset_to_factory_default(DltClient *client); */ DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate); +/** + * Set server ip + * @param client pointer to dlt client structure + * @param pointer to command line argument + * @return negative value if there was an error + */ +int dlt_client_set_server_ip(DltClient *client, char *ipaddr); + +/** + * Set serial device + * @client pointer to dlt client structure + * @param param pointer to command line argument + * @return negative value if there was an error + */ +int dlt_client_set_serial_device(DltClient *client, char *serial_device); + +/** + * Set socket path + * @client pointer to dlt client structure + * @param param pointer to socket path string + * @return negative value if there was an error + */ +int dlt_client_set_socket_path(DltClient *client, char *socket_path); + #ifdef __cplusplus } #endif diff --git a/src/console/dlt-control-common.c b/src/console/dlt-control-common.c index 3973059..56a1795 100644 --- a/src/console/dlt-control-common.c +++ b/src/console/dlt-control-common.c @@ -479,7 +479,11 @@ static int dlt_control_init_connection(DltClient *client, void *cb) if (dlt_parse_config_param("ControlSocketPath", &client->socketPath) != 0) { /* Failed to read from conf, copy default */ - client->socketPath = strdup(DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH); + if(dlt_client_set_socket_path(client, DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH) == -1) + { + pr_error("set socket path didn't succeed\n"); + return -1; + } } client->mode = DLT_CLIENT_MODE_UNIX; diff --git a/src/console/dlt-control.c b/src/console/dlt-control.c index 8a66d0a..832343b 100644 --- a/src/console/dlt-control.c +++ b/src/console/dlt-control.c @@ -473,9 +473,12 @@ int main(int argc, char* argv[]) { for (index = optind; index < argc; index++) { - g_dltclient.servIP = argv[index]; + if(dlt_client_set_server_ip(&g_dltclient, argv[index]) == -1) + { + pr_error("set server ip didn't succeed\n"); + return -1; + } } - if (g_dltclient.servIP == 0) { /* no hostname selected, show usage and terminate */ @@ -489,9 +492,12 @@ int main(int argc, char* argv[]) { for (index = optind; index < argc; index++) { - g_dltclient.serialDevice = argv[index]; + if(dlt_client_set_serial_device(&g_dltclient, argv[index]) == -1) + { + pr_error("set serial device didn't succeed\n"); + return -1; + } } - if (g_dltclient.serialDevice == 0) { /* no serial device name selected, show usage and terminate */ diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c index c10fab0..a4aef2e 100644 --- a/src/console/dlt-receive.c +++ b/src/console/dlt-receive.c @@ -442,7 +442,11 @@ int main(int argc, char* argv[]) { for (index = optind; index < argc; index++) { - dltclient.servIP = argv[index]; + if(dlt_client_set_server_ip(&dltclient, argv[index]) == -1) + { + fprintf(stderr,"set server ip didn't succeed\n"); + return -1; + } } if (dltclient.servIP == 0) @@ -458,7 +462,11 @@ int main(int argc, char* argv[]) { for (index = optind; index < argc; index++) { - dltclient.serialDevice = argv[index]; + if(dlt_client_set_serial_device(&dltclient, argv[index]) == -1) + { + fprintf(stderr,"set serial device didn't succeed\n"); + return -1; + } } if (dltclient.serialDevice == 0) @@ -469,7 +477,7 @@ int main(int argc, char* argv[]) return -1; } - dlt_client_setbaudrate(&dltclient,dltdata.bvalue); + dlt_client_setbaudrate(&dltclient,dltdata.bvalue); } /* initialise structure to use DLT file */ diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index e605bd5..84ffd5d 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -133,6 +133,8 @@ static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon, { int ret = 0; DLT_DAEMON_SEM_LOCK(); + DltConnection *next = dlt_connection_get_next(temp->next, type_mask); + ret = dlt_connection_send_multiple(temp, data1, size1, @@ -166,7 +168,7 @@ static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon, sent = 1; } - temp = dlt_connection_get_next(temp->next, type_mask); + temp = next; } /* for */ return sent; diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c index 51f975d..8d2aa67 100644 --- a/src/daemon/dlt_daemon_connection.c +++ b/src/daemon/dlt_daemon_connection.c @@ -47,6 +47,8 @@ #include "dlt_common.h" #include "dlt_gateway.h" +static DltConnectionId connectionId; + /** @brief Generic sending function. * * We manage different type of connection which have similar send/write @@ -171,6 +173,7 @@ STATIC void dlt_connection_destroy_receiver(DltConnection *con) default: (void) dlt_receiver_free(con->receiver); free(con->receiver); + con->receiver = NULL; break; } } @@ -318,8 +321,12 @@ void *dlt_connection_get_callback(DltConnection *con) */ void dlt_connection_destroy(DltConnection *to_destroy) { + to_destroy->id = 0; close(to_destroy->receiver->fd); dlt_connection_destroy_receiver(to_destroy); + /* connection pointer might be in epoll queue and used even after destroying + * it. To make sure it is not used anymore, connection type is invalidated */ + to_destroy->type = DLT_CONNECTION_TYPE_MAX; free(to_destroy); } @@ -384,6 +391,14 @@ int dlt_connection_create(DltDaemonLocal *daemon_local, return -1; } + /* We are single threaded no need for protection. */ + temp->id = connectionId++; + if (!temp->id) + { + /* Skipping 0 */ + temp->id = connectionId++; + } + temp->type = type; temp->status = ACTIVE; diff --git a/src/daemon/dlt_daemon_connection_types.h b/src/daemon/dlt_daemon_connection_types.h index 1e1186b..8774378 100644 --- a/src/daemon/dlt_daemon_connection_types.h +++ b/src/daemon/dlt_daemon_connection_types.h @@ -67,10 +67,13 @@ typedef enum { #define DLT_CON_MASK_GATEWAY_TIMER (1 << DLT_CONNECTION_GATEWAY_TIMER) #define DLT_CON_MASK_ALL (0xffff) +typedef unsigned int DltConnectionId; + /* TODO: squash the DltReceiver structure in there * and remove any other duplicates of FDs */ typedef struct DltConnection { + DltConnectionId id; DltReceiver *receiver; /**< Receiver structure for this connection */ DltConnectionType type; /**< Represents what type of handle is this (like FIFO, serial, client, server) */ DltConnectionStatus status; /**< Status of connection */ diff --git a/src/daemon/dlt_daemon_event_handler.c b/src/daemon/dlt_daemon_event_handler.c index 9ee3bc1..9051f07 100644 --- a/src/daemon/dlt_daemon_event_handler.c +++ b/src/daemon/dlt_daemon_event_handler.c @@ -128,7 +128,9 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent, for (i = 0 ; i < nfds ; i++) { struct epoll_event *ev = &pEvent->events[i]; - DltConnection *con = (DltConnection *)ev->data.ptr; + DltConnectionId id = (DltConnectionId)ev->data.ptr; + DltConnection *con = dlt_event_handler_find_connection_by_id(pEvent, + id); int fd = 0; DltConnectionType type = DLT_CONNECTION_TYPE_MAX; @@ -137,6 +139,10 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent, type = con->type; fd = con->receiver->fd; } + else /* connection might have been destroyed in the meanwhile */ + { + continue; + } /* First of all handle epoll error events * We only expect EPOLLIN or EPOLLOUT @@ -206,6 +212,31 @@ DltConnection *dlt_event_handler_find_connection(DltEventHandler *ev, return temp; } +/** @brief Find connection with a specific \a id in the connection list. + * + * There can be only one event per \a fd. We can then find a specific connection + * based on this \a fd. That allows to check if a specific \a fd has already been + * registered. + * + * @param ev The event handler structure where the list of connection is. + * @param id The identifier of the connection to be found. + * + * @return The found connection pointer, NULL otherwise. + */ +DltConnection *dlt_event_handler_find_connection_by_id(DltEventHandler *ev, + DltConnectionId id) +{ + + DltConnection *temp = ev->connections; + + while ((temp != NULL) && (temp->id != id)) + { + temp = temp->next; + } + + return temp; +} + /** @brief Remove a connection from the list and destroy it. * * This function will first look for the connection in the event handler list, @@ -347,7 +378,7 @@ int dlt_connection_check_activate(DltEventHandler *evhdl, { struct epoll_event ev; /* Content will be copied by the kernel */ ev.events = con->ev_mask; - ev.data.ptr = (void *)con; + ev.data.ptr = (void *)con->id; snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, diff --git a/src/daemon/dlt_daemon_event_handler.h b/src/daemon/dlt_daemon_event_handler.h index ea88da9..dc91b89 100644 --- a/src/daemon/dlt_daemon_event_handler.h +++ b/src/daemon/dlt_daemon_event_handler.h @@ -39,6 +39,8 @@ int dlt_daemon_prepare_event_handling(DltEventHandler *); int dlt_daemon_handle_event(DltEventHandler *, DltDaemon *, DltDaemonLocal *); +DltConnection *dlt_event_handler_find_connection_by_id(DltEventHandler *, + DltConnectionId); DltConnection *dlt_event_handler_find_connection(DltEventHandler *, int); diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c index 902822a..04237c2 100644 --- a/src/gateway/dlt_gateway.c +++ b/src/gateway/dlt_gateway.c @@ -425,8 +425,13 @@ int dlt_gateway_store_connection(DltGateway *gateway, gateway->connections[i].client.sock, DLT_DAEMON_RCVBUFSIZESOCK); /* setup DltClient Structure */ - gateway->connections[i].client.servIP = - strdup(gateway->connections[i].ip_address); + if(dlt_client_set_server_ip(&gateway->connections[i].client, + gateway->connections[i].ip_address) == -1) + { + dlt_log(LOG_ERR, + "dlt_client_set_server_ip() failed for gateway connection \n"); + return -1; + } if (ret != 0) { diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c index f3fbbf0..fadd789 100644 --- a/src/lib/dlt_client.c +++ b/src/lib/dlt_client.c @@ -836,3 +836,35 @@ DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate) return DLT_RETURN_OK; } +int dlt_client_set_server_ip(DltClient *client, char *ipaddr) +{ + client->servIP = strdup(ipaddr); + if (client->servIP == NULL) + { + dlt_log(LOG_ERR, "ERROR: failed to duplicate server IP\n"); + return DLT_RETURN_ERROR; + } + return DLT_RETURN_OK; +} + +int dlt_client_set_serial_device(DltClient *client, char *serial_device) +{ + client->serialDevice = strdup(serial_device); + if (client->serialDevice == NULL) + { + dlt_log(LOG_ERR, "ERROR: failed to duplicate serial device\n"); + return DLT_RETURN_ERROR; + } + return DLT_RETURN_OK; +} + +int dlt_client_set_socket_path(DltClient *client, char *socket_path) +{ + client->socketPath = strdup(socket_path); + if (client->socketPath == NULL) + { + dlt_log(LOG_ERR, "ERROR: failed to duplicate socket path\n"); + return DLT_RETURN_ERROR; + } + return DLT_RETURN_OK; +} diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 0b00070..713bea3 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -63,6 +63,18 @@ #include "dlt_user_shared_cfg.h" #include "dlt_user_cfg.h" +#ifdef DLT_FATAL_LOG_RESET_ENABLE +#define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) \ + do { \ + if (LOGLEVEL == DLT_LOG_FATAL) { \ + int *p = NULL; \ + *p = 0; \ + } \ + } while(0) +#else /* DLT_FATAL_LOG_RESET_ENABLE */ +#define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) +#endif /* DLT_FATAL_LOG_RESET_ENABLE */ + static DltUser dlt_user; static bool dlt_user_initialised = false; static int dlt_user_freeing = 0; @@ -1420,6 +1432,8 @@ inline DltReturnValue dlt_user_log_write_start(DltContext *handle, DltContextDat DltReturnValue dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t messageid) { + DLT_LOG_FATAL_RESET_TRAP(loglevel); + // check nullpointer if (handle == NULL || log == NULL) return DLT_RETURN_WRONG_PARAMETER; diff --git a/src/tests/dlt-test-client.c b/src/tests/dlt-test-client.c index 9df7e3e..d7b02fe 100644 --- a/src/tests/dlt-test-client.c +++ b/src/tests/dlt-test-client.c @@ -283,7 +283,11 @@ int main(int argc, char* argv[]) { for (index = optind; index < argc; index++) { - dltclient.servIP = argv[index]; + if(dlt_client_set_server_ip(&dltclient, argv[index]) == -1) + { + fprintf(stderr,"set server ip didn't succeed\n"); + return -1; + } } if (dltclient.servIP == 0) @@ -299,7 +303,11 @@ int main(int argc, char* argv[]) { for (index = optind; index < argc; index++) { - dltclient.serialDevice = argv[index]; + if(dlt_client_set_serial_device(&dltclient, argv[index]) == -1) + { + fprintf(stderr,"set serial device didn't succeed\n"); + return -1; + } } if (dltclient.serialDevice == 0) diff --git a/src/tests/dlt-test-multi-process-client.c b/src/tests/dlt-test-multi-process-client.c index bdefaaa..72a9ea4 100644 --- a/src/tests/dlt-test-multi-process-client.c +++ b/src/tests/dlt-test-multi-process-client.c @@ -167,12 +167,20 @@ int init_dlt_connect(DltClient *client, const s_parameters *params, int argc, ch if(params->serial > 0) { client->mode = 1; - client->serialDevice = argv[argc - 1]; + if(dlt_client_set_serial_device(client, argv[argc - 1]) == -1) + { + fprintf(stderr,"set serial device didn't succeed\n"); + return -1; + } dlt_client_setbaudrate(client, params->baudrate); } else { - client->servIP = argv[argc - 1]; + if(dlt_client_set_server_ip(client, argv[argc - 1]) == -1) + { + fprintf(stderr,"set serial ip didn't succeed\n"); + return -1; + } } dlt_set_id(id, ECUID); return 0; diff --git a/src/tests/dlt-test-stress-client.c b/src/tests/dlt-test-stress-client.c index e0ca808..d97099b 100644 --- a/src/tests/dlt-test-stress-client.c +++ b/src/tests/dlt-test-stress-client.c @@ -304,7 +304,11 @@ int main(int argc, char* argv[]) { for (index = optind; index < argc; index++) { - dltclient.servIP = argv[index]; + if(dlt_client_set_server_ip(&dltclient, argv[index]) == -1) + { + fprintf(stderr,"set server ip didn't succeed\n"); + return -1; + } } if (dltclient.servIP == 0) @@ -320,7 +324,11 @@ int main(int argc, char* argv[]) { for (index = optind; index < argc; index++) { - dltclient.serialDevice = argv[index]; + if(dlt_client_set_serial_device(&dltclient, argv[index]) == -1) + { + fprintf(stderr,"set serial device didn't succeed\n"); + return -1; + } } if (dltclient.serialDevice == 0) |