From dca8ab254aa0a687c32009079d85e4d8f960b213 Mon Sep 17 00:00:00 2001 From: Christoph Lipka Date: Thu, 20 Dec 2018 14:58:19 +0100 Subject: Code beautification using uncrustify Signed-off-by: Christoph Lipka --- src/console/dlt-control-common.c | 159 +++---- src/console/dlt-control.c | 583 +++++++++++-------------- src/console/dlt-convert.c | 312 ++++++------- src/console/dlt-passive-node-ctrl.c | 111 ++--- src/console/dlt-receive.c | 487 ++++++++++----------- src/console/dlt-sortbytimestamp.c | 244 +++++------ src/console/logstorage/dlt-logstorage-common.c | 54 +-- src/console/logstorage/dlt-logstorage-ctrl.c | 132 ++---- src/console/logstorage/dlt-logstorage-list.c | 43 +- src/console/logstorage/dlt-logstorage-prop.h | 9 +- src/console/logstorage/dlt-logstorage-udev.c | 93 ++-- 11 files changed, 928 insertions(+), 1299 deletions(-) (limited to 'src/console') diff --git a/src/console/dlt-control-common.c b/src/console/dlt-control-common.c index 37c5a62..964dbe8 100644 --- a/src/console/dlt-control-common.c +++ b/src/console/dlt-control-common.c @@ -111,24 +111,19 @@ void set_ecuid(char *ecuid) { char *ecuid_conf = NULL; - if (local_ecuid != ecuid) - { + if (local_ecuid != ecuid) { /* If user pass NULL, read ECUId from dlt.conf */ - if (ecuid == NULL) - { - if (dlt_parse_config_param("ECUId", &ecuid_conf) == 0) - { + if (ecuid == NULL) { + if (dlt_parse_config_param("ECUId", &ecuid_conf) == 0) { memset(local_ecuid, 0, DLT_CTRL_ECUID_LEN); strncpy(local_ecuid, ecuid_conf, DLT_CTRL_ECUID_LEN); local_ecuid[DLT_CTRL_ECUID_LEN - 1] = '\0'; } - else - { + else { pr_error("Cannot read ECUid from dlt.conf\n"); } } - else - { + else { /* Set user passed ECUID */ memset(local_ecuid, 0, DLT_CTRL_ECUID_LEN); strncpy(local_ecuid, ecuid, DLT_CTRL_ECUID_LEN); @@ -147,23 +142,19 @@ void set_timeout(long t) local_timeout = DLT_CTRL_TIMEOUT; if (t > 1) - { local_timeout = t; - } else - { pr_error("Timeout to small. Set to default: %d", DLT_CTRL_TIMEOUT); - } } int dlt_parse_config_param(char *config_id, char **config_data) { - FILE * pFile = NULL; + FILE *pFile = NULL; int value_length = DLT_LINE_LEN; - char line[DLT_LINE_LEN-1] = {0}; - char token[DLT_LINE_LEN] = {0}; - char value[DLT_LINE_LEN] = {0}; + char line[DLT_LINE_LEN - 1] = { 0 }; + char token[DLT_LINE_LEN] = { 0 }; + char value[DLT_LINE_LEN] = { 0 }; char *pch = NULL; const char *filename = NULL; @@ -174,58 +165,48 @@ int dlt_parse_config_param(char *config_id, char **config_data) filename = CONFIGURATION_FILES_DIR "/dlt.conf"; pFile = fopen(filename, "r"); - if (pFile != NULL) - { - while (1) - { + if (pFile != NULL) { + while (1) { /* fetch line from configuration file */ - if (fgets(line, value_length - 1, pFile) != NULL) - { - if (strncmp(line, config_id, strlen(config_id)) == 0) - { + if (fgets(line, value_length - 1, pFile) != NULL) { + if (strncmp(line, config_id, strlen(config_id)) == 0) { pch = strtok(line, " =\r\n"); token[0] = 0; value[0] = 0; - while (pch != NULL) - { - if (token[0] == 0) - { + while (pch != NULL) { + if (token[0] == 0) { strncpy(token, pch, sizeof(token) - 1); token[sizeof(token) - 1] = 0; } - else - { + else { strncpy(value, pch, sizeof(value) - 1); value[sizeof(value) - 1] = 0; break; } + pch = strtok(NULL, " =\r\n"); } - if (token[0] && value[0]) - { - if (strcmp(token, config_id) == 0) - { - *(config_data) = (char*) - calloc(DLT_DAEMON_FLAG_MAX, sizeof(char)); + if (token[0] && value[0]) { + if (strcmp(token, config_id) == 0) { + *(config_data) = (char *) + calloc(DLT_DAEMON_FLAG_MAX, sizeof(char)); memcpy(*config_data, - value, - DLT_DAEMON_FLAG_MAX-1); + value, + DLT_DAEMON_FLAG_MAX - 1); } } - } } - else - { + else { break; } } + fclose (pFile); } - else - { + else { fprintf(stderr, "Cannot open configuration file: %s\n", filename); } @@ -248,14 +229,12 @@ static int dlt_control_send_message_to_socket(int sock, DltMessage *msg) { if (send(sock, (const char *)(msg->headerbuffer + sizeof(DltStorageHeader)), - msg->headersize - sizeof(DltStorageHeader), 0) == -1) - { + msg->headersize - sizeof(DltStorageHeader), 0) == -1) { pr_error("Sending message header failed: %s\n", strerror(errno)); return -1; } - if (send(sock, (const char *) msg->databuffer, msg->datasize, 0) == -1) - { + if (send(sock, (const char *)msg->databuffer, msg->datasize, 0) == -1) { pr_error("Sending message failed: %s\n", strerror(errno)); return -1; } @@ -279,9 +258,7 @@ static int prepare_extra_headers(DltMessage *msg, uint8_t *header) pr_verbose("Preparing extra headers.\n"); if (!msg || !header) - { return -1; - } shift = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + @@ -293,8 +270,7 @@ static int prepare_extra_headers(DltMessage *msg, uint8_t *header) msg->headerextra.tmsp = dlt_uptime(); /* Copy header extra parameters to header buffer */ - if (dlt_message_set_extraparameters(msg, get_verbosity()) == -1) - { + if (dlt_message_set_extraparameters(msg, get_verbosity()) == -1) { pr_error("Cannot copy header extra parameter\n"); return -1; } @@ -329,21 +305,18 @@ static int prepare_headers(DltMessage *msg, uint8_t *header) pr_verbose("Preparing headers.\n"); if (!msg || !header) - { return -1; - } - msg->storageheader = (DltStorageHeader *) header; + msg->storageheader = (DltStorageHeader *)header; - if (dlt_set_storageheader(msg->storageheader, "") == -1) - { + if (dlt_set_storageheader(msg->storageheader, "") == -1) { pr_error("Storage header initialization failed.\n"); return -1; } /* prepare standard header */ msg->standardheader = - (DltStandardHeader *) (header + sizeof(DltStorageHeader)); + (DltStandardHeader *)(header + sizeof(DltStorageHeader)); msg->standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1; @@ -362,8 +335,7 @@ static int prepare_headers(DltMessage *msg, uint8_t *header) len = msg->headersize - sizeof(DltStorageHeader) + msg->datasize; - if (len > UINT16_MAX) - { + if (len > UINT16_MAX) { pr_error("Message header is too long.\n"); return -1; } @@ -388,22 +360,19 @@ static DltMessage *dlt_control_prepare_message(DltControlMsgBody *data) pr_verbose("Preparing message.\n"); - if (data == NULL) - { + if (data == NULL) { pr_error("Data for message body is NULL\n"); return NULL; } msg = calloc(1, sizeof(DltMessage)); - if (msg == NULL) - { + if (msg == NULL) { pr_error("Cannot allocate memory for Dlt Message\n"); return NULL; } - if (dlt_message_init(msg, get_verbosity()) == -1) - { + if (dlt_message_init(msg, get_verbosity()) == -1) { pr_error("Cannot initialize Dlt Message\n"); free(msg); return NULL; @@ -415,8 +384,7 @@ static DltMessage *dlt_control_prepare_message(DltControlMsgBody *data) /* Allocate memory for Dlt Message's buffer */ msg->databuffer = (uint8_t *)calloc(1, data->size); - if (msg->databuffer == NULL) - { + if (msg->databuffer == NULL) { pr_error("Cannot allocate memory for data buffer\n"); free(msg); return NULL; @@ -426,16 +394,14 @@ static DltMessage *dlt_control_prepare_message(DltControlMsgBody *data) memcpy(msg->databuffer, data->data, data->size); /* prepare storage header */ - if (prepare_headers(msg, msg->headerbuffer)) - { + if (prepare_headers(msg, msg->headerbuffer)) { dlt_message_free(msg, get_verbosity()); free(msg); return NULL; } /* prepare extra headers */ - if (prepare_extra_headers(msg, msg->headerbuffer)) - { + if (prepare_extra_headers(msg, msg->headerbuffer)) { dlt_message_free(msg, get_verbosity()); free(msg); return NULL; @@ -459,15 +425,14 @@ static int dlt_control_init_connection(DltClient *client, void *cb) { int (*callback)(DltMessage *message, void *data) = cb; - if (!cb || !client) - { + if (!cb || !client) { pr_error("%s Invalid parameters (%p, %p)\n", __func__, client, cb); return -1; } pr_verbose("Initializing the connection.\n"); - if (dlt_client_init(client, get_verbosity()) != 0) - { + + if (dlt_client_init(client, get_verbosity()) != 0) { pr_error("Failed to register callback (NULL)\n"); return -1; } @@ -475,15 +440,15 @@ static int dlt_control_init_connection(DltClient *client, void *cb) dlt_client_register_message_callback(callback); client->socketPath = NULL; - if (dlt_parse_config_param("ControlSocketPath", &client->socketPath) != 0) - { + + if (dlt_parse_config_param("ControlSocketPath", &client->socketPath) != 0) { /* Failed to read from conf, copy default */ - if(dlt_client_set_socket_path(client, DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH) == -1) - { + 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; return dlt_client_connect(client, get_verbosity()); @@ -525,23 +490,18 @@ static void *dlt_control_listen_to_daemon(void *data) static int dlt_control_callback(DltMessage *message, void *data) { char text[DLT_RECEIVE_BUFSIZE] = { 0 }; - (void) data; + (void)data; - if (message == NULL) - { + if (message == NULL) { pr_error("Received message is null\n"); return -1; } /* prepare storage header */ if (DLT_IS_HTYP_WEID(message->standardheader->htyp)) - { dlt_set_storageheader(message->storageheader, message->headerextra.ecu); - } else - { dlt_set_storageheader(message->storageheader, "LCTL"); - } dlt_message_header(message, text, DLT_RECEIVE_BUFSIZE, get_verbosity()); @@ -582,14 +542,12 @@ int dlt_control_send_message(DltControlMsgBody *body, int timeout) struct timespec t; DltMessage *msg = NULL; - if (!body) - { + if (!body) { pr_error("Invalid input (%p).\n", body); return -1; } - if (clock_gettime(CLOCK_REALTIME, &t) == -1) - { + if (clock_gettime(CLOCK_REALTIME, &t) == -1) { pr_error("Cannot read system time.\n"); return -1; } @@ -599,8 +557,7 @@ int dlt_control_send_message(DltControlMsgBody *body, int timeout) /* send command to daemon here */ msg = dlt_control_prepare_message(body); - if (msg == NULL) - { + if (msg == NULL) { pr_error("Control message preparation failed\n"); return -1; } @@ -610,8 +567,7 @@ int dlt_control_send_message(DltControlMsgBody *body, int timeout) /* Re-init the return value */ callback_return = -1; - if (dlt_control_send_message_to_socket(client.sock, msg) != 0) - { + if (dlt_control_send_message_to_socket(client.sock, msg) != 0) { pr_error("Sending message to daemon failed\n"); free(msg); return -1; @@ -619,9 +575,7 @@ int dlt_control_send_message(DltControlMsgBody *body, int timeout) /* If we timeout the lock is not taken back */ if (!pthread_cond_timedwait(&answer_cond, &answer_lock, &t)) - { pthread_mutex_unlock(&answer_lock); - } /* Destroying the message */ dlt_message_free(msg, get_verbosity()); @@ -648,8 +602,7 @@ int dlt_control_init(int (*response_analyzer)(char *, void *, int), char *ecuid, int verbosity) { - if (!response_analyzer || !ecuid) - { + if (!response_analyzer || !ecuid) { pr_error("Invalid input (%p %p).\n", response_analyzer, ecuid); return -1; } @@ -658,8 +611,7 @@ int dlt_control_init(int (*response_analyzer)(char *, void *, int), set_ecuid(ecuid); set_verbosity(verbosity); - if (dlt_control_init_connection(&client, dlt_control_callback) != 0) - { + if (dlt_control_init_connection(&client, dlt_control_callback) != 0) { pr_error("Connection initialization failed\n"); dlt_client_cleanup(&client, get_verbosity()); return -1; @@ -669,8 +621,7 @@ int dlt_control_init(int (*response_analyzer)(char *, void *, int), if (pthread_create(&daemon_connect_thread, NULL, dlt_control_listen_to_daemon, - NULL) != 0) - { + NULL) != 0) { pr_error("Cannot create thread to communicate with DLT daemon.\n"); return -1; } diff --git a/src/console/dlt-control.c b/src/console/dlt-control.c index f291afa..a1eb408 100644 --- a/src/console/dlt-control.c +++ b/src/console/dlt-control.c @@ -22,7 +22,7 @@ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt-control.cpp -*/ + */ /******************************************************************************* @@ -80,7 +80,7 @@ typedef struct uint32_t service_id; /**< service ID */ } PACKED DltServiceGetDefaultLogLevel; -DltClient g_dltclient; +DltClient g_dltclient; DltServiceGetLogInfoResponse *g_resp = NULL; /* Function prototypes */ @@ -119,7 +119,7 @@ void usage() { char version[255]; - dlt_get_version(version,255); + dlt_get_version(version, 255); printf("Usage: dlt-control [options] hostname/serial_device_name\n"); printf("Send control message to DLT daemon.\n"); @@ -166,73 +166,59 @@ void usage() */ void dlt_process_get_log_info(void) { - char apid[DLT_ID_SIZE+1] = {0}; - char ctid[DLT_ID_SIZE+1] = {0}; + char apid[DLT_ID_SIZE + 1] = { 0 }; + char ctid[DLT_ID_SIZE + 1] = { 0 }; AppIDsType app; ContextIDsInfoType con; int i = 0; int j = 0; - g_resp = (DltServiceGetLogInfoResponse*) calloc(1, sizeof(DltServiceGetLogInfoResponse)); + g_resp = (DltServiceGetLogInfoResponse *)calloc(1, sizeof(DltServiceGetLogInfoResponse)); - if (g_resp == NULL) - { + if (g_resp == NULL) { fprintf(stderr, "%s: Calloc failed for resp..\n", __func__); return; } /* send control message*/ - if (0 != dlt_client_get_log_info(&g_dltclient)) - { + if (0 != dlt_client_get_log_info(&g_dltclient)) { fprintf(stderr, "ERROR: Could not get log info\n"); dlt_client_cleanup_get_log_info(g_resp); return; } if (dlt_client_main_loop(&g_dltclient, NULL, 0) == DLT_RETURN_TRUE) - { fprintf(stdout, "DLT-daemon's response is invalid.\n"); - } - for (i = 0; i < g_resp->log_info_type.count_app_ids; i++) - { + for (i = 0; i < g_resp->log_info_type.count_app_ids; i++) { app = g_resp->log_info_type.app_ids[i]; dlt_print_id(apid, app.app_id); if (app.app_description != 0) - { printf("APID:%4s %s\n", apid, app.app_description); - } else - { printf("APID:%4s \n", apid); - } - for (j = 0; j < app.count_context_ids; j++) - { + for (j = 0; j < app.count_context_ids; j++) { con = app.context_id_info[j]; dlt_print_id(ctid, con.context_id); if (con.context_description != 0) - { - printf("CTID:%4s %2d %2d %s\n", - ctid, - con.log_level, - con.trace_status, - con.context_description); - } + printf("CTID:%4s %2d %2d %s\n", + ctid, + con.log_level, + con.trace_status, + con.context_description); else - { printf("CTID:%4s %2d %2d\n", ctid, con.log_level, con.trace_status); - } - } - } + } + } dlt_client_cleanup_get_log_info(g_resp); } @@ -240,7 +226,7 @@ void dlt_process_get_log_info(void) /** * Main function of tool. */ -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { DltReceiveData dltdata; int c; @@ -271,152 +257,150 @@ int main(int argc, char* argv[]) opterr = 0; while ((c = getopt (argc, argv, "vhye:b:a:c:s:m:x:t:l:r:d:f:i:ogju")) != -1) - switch (c) - { + switch (c) { case 'v': - { - dltdata.vflag = 1; - break; - } + { + dltdata.vflag = 1; + break; + } case 'h': - { - usage(); - return -1; - } + { + usage(); + return -1; + } case 'y': - { - dltdata.yflag = DLT_CLIENT_MODE_SERIAL; - break; - } + { + dltdata.yflag = DLT_CLIENT_MODE_SERIAL; + break; + } case 'e': - { - dltdata.evalue = optarg; - break; - } + { + dltdata.evalue = optarg; + break; + } case 'b': - { - dltdata.bvalue = atoi(optarg); - break; - } + { + dltdata.bvalue = atoi(optarg); + break; + } case 'a': - { - dltdata.avalue = optarg; - if (strlen(dltdata.avalue) > DLT_ID_SIZE) - { - fprintf (stderr, "Invalid appid\n"); - return -1; - } - break; + { + dltdata.avalue = optarg; + + if (strlen(dltdata.avalue) > DLT_ID_SIZE) { + fprintf (stderr, "Invalid appid\n"); + return -1; } + + break; + } case 'c': - { - dltdata.cvalue = optarg; - if (strlen(dltdata.cvalue) > DLT_ID_SIZE) - { - fprintf (stderr, "Invalid context id\n"); - return -1; - } - break; + { + dltdata.cvalue = optarg; + + if (strlen(dltdata.cvalue) > DLT_ID_SIZE) { + fprintf (stderr, "Invalid context id\n"); + return -1; } + + break; + } case 's': - { - dltdata.svalue = atoi(optarg); - break; - } + { + dltdata.svalue = atoi(optarg); + break; + } case 'm': - { - dltdata.mvalue = optarg; - break; - } + { + dltdata.mvalue = optarg; + break; + } case 'x': - { - dltdata.xvalue = optarg; - break; - } + { + dltdata.xvalue = optarg; + break; + } case 't': - { - dltdata.tvalue = atoi(optarg);; - break; - } + { + dltdata.tvalue = atoi(optarg); + break; + } case 'l': - { - dltdata.lvalue = strtol(optarg, &endptr, 10); - if ((dltdata.lvalue < DLT_LOG_DEFAULT) || (dltdata.lvalue > DLT_LOG_VERBOSE)) - { - fprintf (stderr, "invalid log level, supported log level 0-6\n"); - return -1; - } - break; + { + dltdata.lvalue = strtol(optarg, &endptr, 10); + + if ((dltdata.lvalue < DLT_LOG_DEFAULT) || (dltdata.lvalue > DLT_LOG_VERBOSE)) { + fprintf (stderr, "invalid log level, supported log level 0-6\n"); + return -1; } + + break; + } case 'r': - { - dltdata.rvalue = strtol(optarg, &endptr, 10); - if ((dltdata.rvalue < DLT_TRACE_STATUS_DEFAULT) || (dltdata.rvalue > DLT_TRACE_STATUS_ON)) - { - fprintf (stderr, "invalid trace status, supported trace status -1, 0, 1\n"); - return -1; - } - break; - } + { + dltdata.rvalue = strtol(optarg, &endptr, 10); + + if ((dltdata.rvalue < DLT_TRACE_STATUS_DEFAULT) || (dltdata.rvalue > DLT_TRACE_STATUS_ON)) { + fprintf (stderr, "invalid trace status, supported trace status -1, 0, 1\n"); + return -1; + } + + break; + } case 'd': - { - dltdata.dvalue = atoi(optarg);; - break; - } + { + dltdata.dvalue = atoi(optarg); + break; + } case 'f': - { - dltdata.fvalue = atoi(optarg);; - break; - } + { + dltdata.fvalue = atoi(optarg); + break; + } case 'i': - { - dltdata.ivalue = atoi(optarg);; - break; - } + { + dltdata.ivalue = atoi(optarg); + break; + } case 'o': - { - dltdata.oflag = 1; - break; - } + { + dltdata.oflag = 1; + break; + } case 'g': - { - dltdata.gflag = 1; - break; - } + { + dltdata.gflag = 1; + break; + } case 'j': - { - dltdata.jvalue = 1; - break; - } + { + dltdata.jvalue = 1; + break; + } case 'u': - { - dltdata.yflag = DLT_CLIENT_MODE_UNIX; - break; - } + { + dltdata.yflag = DLT_CLIENT_MODE_UNIX; + break; + } case '?': - { - if ((optopt == 'o') || (optopt == 'f')) - { - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - } - else if (isprint (optopt)) - { - fprintf (stderr, "Unknown option `-%c'.\n", optopt); - } - else - { - fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt); - } - /* unknown or wrong option used, show usage information and terminate */ - usage(); - return -1; - } + { + if ((optopt == 'o') || (optopt == 'f')) + fprintf (stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint (optopt)) + fprintf (stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + + /* unknown or wrong option used, show usage information and terminate */ + usage(); + return -1; + } default: - { - abort (); - return -1;//for parasoft - } + { + abort (); + return -1; /*for parasoft */ + } } /* Initialize DLT Client */ @@ -426,8 +410,7 @@ int main(int argc, char* argv[]) dlt_client_register_message_callback(dlt_receive_message_callback); /* Setup DLT Client structure */ - if (dltdata.yflag == DLT_CLIENT_MODE_SERIAL) - { + if (dltdata.yflag == DLT_CLIENT_MODE_SERIAL) { g_dltclient.mode = DLT_CLIENT_MODE_SERIAL; } else if (dltdata.yflag == DLT_CLIENT_MODE_UNIX) @@ -436,267 +419,240 @@ int main(int argc, char* argv[]) g_dltclient.socketPath = NULL; dlt_parse_config_param("ControlSocketPath", &g_dltclient.socketPath); } - else - { + else { g_dltclient.mode = DLT_CLIENT_MODE_TCP; } - if (g_dltclient.mode==DLT_CLIENT_MODE_TCP) - { + if (g_dltclient.mode == DLT_CLIENT_MODE_TCP) { for (index = optind; index < argc; index++) - { - if(dlt_client_set_server_ip(&g_dltclient, argv[index]) == -1) - { + 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) - { + + + + if (g_dltclient.servIP == 0) { /* no hostname selected, show usage and terminate */ - fprintf(stderr,"ERROR: No hostname selected\n"); + fprintf(stderr, "ERROR: No hostname selected\n"); usage(); - dlt_client_cleanup(&g_dltclient,dltdata.vflag); + dlt_client_cleanup(&g_dltclient, dltdata.vflag); return -1; } } else if (g_dltclient.mode == DLT_CLIENT_MODE_SERIAL) { for (index = optind; index < argc; index++) - { - if(dlt_client_set_serial_device(&g_dltclient, argv[index]) == -1) - { + 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) - { + + + + if (g_dltclient.serialDevice == 0) { /* no serial device name selected, show usage and terminate */ - fprintf(stderr,"ERROR: No serial device name specified\n"); + fprintf(stderr, "ERROR: No serial device name specified\n"); usage(); return -1; } - dlt_client_setbaudrate(&g_dltclient,dltdata.bvalue); + dlt_client_setbaudrate(&g_dltclient, dltdata.bvalue); } /* initialise structure to use DLT file */ - dlt_file_init(&(dltdata.file),dltdata.vflag); + dlt_file_init(&(dltdata.file), dltdata.vflag); /* first parse filter file if filter parameter is used */ - dlt_filter_init(&(dltdata.filter),dltdata.vflag); + dlt_filter_init(&(dltdata.filter), dltdata.vflag); - if (dltdata.evalue) - { - dlt_set_id(dltdata.ecuid,dltdata.evalue); - dlt_set_id(g_dltclient.ecuid,dltdata.evalue); + if (dltdata.evalue) { + dlt_set_id(dltdata.ecuid, dltdata.evalue); + dlt_set_id(g_dltclient.ecuid, dltdata.evalue); } - else - { + else { dltdata.evalue = NULL; - if (dlt_parse_config_param("ECUId", &dltdata.evalue) == 0) - { - dlt_set_id(dltdata.ecuid,dltdata.evalue); - dlt_set_id(g_dltclient.ecuid,dltdata.evalue); + + if (dlt_parse_config_param("ECUId", &dltdata.evalue) == 0) { + dlt_set_id(dltdata.ecuid, dltdata.evalue); + dlt_set_id(g_dltclient.ecuid, dltdata.evalue); free (dltdata.evalue); } - else - { + else { fprintf(stderr, "ERROR: Failed to read ECUId from dlt.conf \n"); } } /* Connect to TCP socket or open serial device */ - if (dlt_client_connect(&g_dltclient, dltdata.vflag) != DLT_RETURN_ERROR) - { - /* send injection message */ - if(dltdata.mvalue && dltdata.avalue && dltdata.cvalue) - { - /* ASCII */ - printf("Send injection message:\n"); - printf("AppId: %s\n",dltdata.avalue); - printf("ConId: %s\n",dltdata.cvalue); - printf("ServiceId: %d\n",dltdata.svalue); - printf("Message: %s\n",dltdata.mvalue); - /* send control message in ascii */ + if (dlt_client_connect(&g_dltclient, dltdata.vflag) != DLT_RETURN_ERROR) { + /* send injection message */ + if (dltdata.mvalue && dltdata.avalue && dltdata.cvalue) { + /* ASCII */ + printf("Send injection message:\n"); + printf("AppId: %s\n", dltdata.avalue); + printf("ConId: %s\n", dltdata.cvalue); + printf("ServiceId: %d\n", dltdata.svalue); + printf("Message: %s\n", dltdata.mvalue); + + /* send control message in ascii */ if (dlt_client_send_inject_msg(&g_dltclient, - dltdata.avalue, - dltdata.cvalue, - dltdata.svalue, - (uint8_t*)dltdata.mvalue, - strlen(dltdata.mvalue)) != DLT_RETURN_OK) - { + dltdata.avalue, + dltdata.cvalue, + dltdata.svalue, + (uint8_t *)dltdata.mvalue, + strlen(dltdata.mvalue)) != DLT_RETURN_OK) fprintf(stderr, "ERROR: Could not send inject message\n"); - } - } - else if(dltdata.xvalue && dltdata.avalue && dltdata.cvalue) - { - /* Hex */ - uint8_t buffer[1024]; - int size = 1024; - printf("Send injection message:\n"); - printf("AppId: %s\n",dltdata.avalue); - printf("ConId: %s\n",dltdata.cvalue); - printf("ServiceId: %d\n",dltdata.svalue); - printf("Message: %s\n",dltdata.xvalue); - dlt_hex_ascii_to_binary(dltdata.xvalue,buffer,&size); - printf("Size: %d\n",size); + } + else if (dltdata.xvalue && dltdata.avalue && dltdata.cvalue) + { + /* Hex */ + uint8_t buffer[1024]; + int size = 1024; + printf("Send injection message:\n"); + printf("AppId: %s\n", dltdata.avalue); + printf("ConId: %s\n", dltdata.cvalue); + printf("ServiceId: %d\n", dltdata.svalue); + printf("Message: %s\n", dltdata.xvalue); + dlt_hex_ascii_to_binary(dltdata.xvalue, buffer, &size); + printf("Size: %d\n", size); + /* send control message in hex */ if (dlt_client_send_inject_msg(&g_dltclient, - dltdata.avalue, - dltdata.cvalue, - dltdata.svalue, - buffer,size) != DLT_RETURN_OK) - { + dltdata.avalue, + dltdata.cvalue, + dltdata.svalue, + buffer, size) != DLT_RETURN_OK) fprintf(stderr, "ERROR: Could not send inject message\n"); - } - } - else if (dltdata.lvalue != DLT_INVALID_LOG_LEVEL) /*&& dltdata.avalue && dltdata.cvalue)*/ + } + else if (dltdata.lvalue != DLT_INVALID_LOG_LEVEL) /*&& dltdata.avalue && dltdata.cvalue)*/ { - if ((dltdata.avalue == 0) && (dltdata.cvalue == 0)) - { - if (dltdata.vflag) - { + if ((dltdata.avalue == 0) && (dltdata.cvalue == 0)) { + if (dltdata.vflag) { printf("Set all log level:\n"); printf("Loglevel: %d\n", dltdata.lvalue); } + if (0 != dlt_client_send_all_log_level(&g_dltclient, dltdata.lvalue)) - { fprintf(stderr, "ERROR: Could not send log level\n"); - } } - else - { + else { /* log level */ - if (dltdata.vflag) - { + if (dltdata.vflag) { printf("Set log level:\n"); printf("AppId: %s\n", dltdata.avalue); printf("ConId: %s\n", dltdata.cvalue); printf("Loglevel: %d\n", dltdata.lvalue); } + /* send control message*/ if (0 != dlt_client_send_log_level(&g_dltclient, dltdata.avalue, dltdata.cvalue, dltdata.lvalue)) - { fprintf(stderr, "ERROR: Could not send log level\n"); - } } } else if (dltdata.rvalue != DLT_INVALID_TRACE_STATUS) { - if ((dltdata.avalue == 0) && (dltdata.cvalue == 0)) - { - if (dltdata.vflag) - { + if ((dltdata.avalue == 0) && (dltdata.cvalue == 0)) { + if (dltdata.vflag) { printf("Set all trace status:\n"); printf("Tracestatus: %d\n", dltdata.rvalue); } + if (0 != dlt_client_send_all_trace_status(&g_dltclient, dltdata.rvalue)) - { fprintf(stderr, "ERROR: Could not send trace status\n"); - } } - else - { + else { /* trace status */ - if (dltdata.vflag) - { + if (dltdata.vflag) { printf("Set trace status:\n"); printf("AppId: %s\n", dltdata.avalue); printf("ConId: %s\n", dltdata.cvalue); printf("Tracestatus: %d\n", dltdata.rvalue); } + /* send control message*/ if (0 != dlt_client_send_trace_status(&g_dltclient, dltdata.avalue, dltdata.cvalue, dltdata.rvalue)) - { fprintf(stderr, "ERROR: Could not send trace status\n"); - } } } - else if(dltdata.dvalue!=-1) - { - /* default log level */ - printf("Set default log level:\n"); - printf("Loglevel: %d\n",dltdata.dvalue); - /* send control message in*/ + else if (dltdata.dvalue != -1) + { + /* default log level */ + printf("Set default log level:\n"); + printf("Loglevel: %d\n", dltdata.dvalue); + + /* send control message in*/ if (dlt_client_send_default_log_level(&g_dltclient, dltdata.dvalue) != DLT_RETURN_OK) - { fprintf (stderr, "ERROR: Could not send default log level\n"); - } - } - else if(dltdata.fvalue!=-1) - { - /* default trace status */ - printf("Set default trace status:\n"); - printf("TraceStatus: %d\n",dltdata.fvalue); - /* send control message in*/ + } + else if (dltdata.fvalue != -1) + { + /* default trace status */ + printf("Set default trace status:\n"); + printf("TraceStatus: %d\n", dltdata.fvalue); + + /* send control message in*/ if (dlt_client_send_default_trace_status(&g_dltclient, dltdata.fvalue) != DLT_RETURN_OK) - { fprintf (stderr, "ERROR: Could not send default trace status\n"); - } - } - else if(dltdata.ivalue!=-1) - { - /* timing pakets */ - printf("Set timing pakets:\n"); - printf("Timing packets: %d\n",dltdata.ivalue); - /* send control message in*/ + } + else if (dltdata.ivalue != -1) + { + /* timing pakets */ + printf("Set timing pakets:\n"); + printf("Timing packets: %d\n", dltdata.ivalue); + + /* send control message in*/ if (dlt_client_send_timing_pakets(&g_dltclient, dltdata.ivalue) != DLT_RETURN_OK) - { fprintf (stderr, "ERROR: Could not send timing packets\n"); - } - } - else if(dltdata.oflag!=-1) - { - /* default trace status */ - printf("Store config\n"); - /* send control message in*/ + } + else if (dltdata.oflag != -1) + { + /* default trace status */ + printf("Store config\n"); + + /* send control message in*/ if (dlt_client_send_store_config(&g_dltclient) != DLT_RETURN_OK) - { fprintf (stderr, "ERROR: Could not send store config\n"); - } - } - else if(dltdata.gflag!=-1) - { - /* reset to factory default */ - printf("Reset to factory default\n"); - /* send control message in*/ + } + else if (dltdata.gflag != -1) + { + /* reset to factory default */ + printf("Reset to factory default\n"); + + /* send control message in*/ if (dlt_client_send_reset_to_factory_default(&g_dltclient) != DLT_RETURN_OK) - { fprintf (stderr, "ERROR: Could send reset to factory default\n"); - } - } + } else if (dltdata.jvalue == 1) { /* get log info */ printf("Get log info:\n"); dlt_process_get_log_info(); } + /* Dlt Client Main Loop */ - //dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag); + /*dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag); */ - /* Wait timeout */ - usleep(dltdata.tvalue*1000); + /* Wait timeout */ + usleep(dltdata.tvalue * 1000); } /* Dlt Client Cleanup */ - dlt_client_cleanup(&g_dltclient,dltdata.vflag); + dlt_client_cleanup(&g_dltclient, dltdata.vflag); if (g_dltclient.socketPath != NULL) free(g_dltclient.socketPath); - dlt_file_free(&(dltdata.file),dltdata.vflag); + dlt_file_free(&(dltdata.file), dltdata.vflag); - dlt_filter_free(&(dltdata.filter),dltdata.vflag); + dlt_filter_free(&(dltdata.filter), dltdata.vflag); return 0; } @@ -708,56 +664,49 @@ int dlt_receive_message_callback(DltMessage *message, void *data) /* parameter check */ if (message == NULL) - { return -1; - } + /* to avoid warning */ data = data; /* prepare storage header */ if (DLT_IS_HTYP_WEID(message->standardheader->htyp)) - { dlt_set_storageheader(message->storageheader, message->headerextra.ecu); - } else - { dlt_set_storageheader(message->storageheader, "LCTL"); - } /* get response data */ ret = dlt_message_header(message, resp_text, DLT_RECEIVE_BUFSIZE, 0); - if (ret < 0) - { + + if (ret < 0) { fprintf(stderr, "GET_LOG_INFO message_header result failed..\n"); dlt_client_cleanup(&g_dltclient, 0); return -1; } ret = dlt_message_payload(message, resp_text, DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, 0); - if (ret < 0) - { + + if (ret < 0) { fprintf(stderr, "GET_LOG_INFO message_payload result failed..\n"); dlt_client_cleanup(&g_dltclient, 0); return -1; } /* check service id */ - if (g_resp == NULL) - { + if (g_resp == NULL) { fprintf(stderr, "%s: g_resp isn't allocated.\n", __func__); dlt_client_cleanup(&g_dltclient, 0); return -1; } ret = dlt_set_loginfo_parse_service_id(resp_text, &g_resp->service_id, &g_resp->status); - if ((ret == 0) && (g_resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO)) - { + + if ((ret == 0) && (g_resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO)) { ret = dlt_client_parse_get_log_info_resp_text(g_resp, resp_text); if (ret != 0) - { fprintf(stderr, "GET_LOG_INFO result failed..\n"); - } + dlt_client_cleanup(&g_dltclient, 0); } diff --git a/src/console/dlt-convert.c b/src/console/dlt-convert.c index 8c5c901..8c71684 100644 --- a/src/console/dlt-convert.c +++ b/src/console/dlt-convert.c @@ -22,7 +22,7 @@ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt-convert.cpp -*/ + */ /******************************************************************************* ** ** @@ -72,8 +72,8 @@ * $LastChangedRevision: 1670 $ * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $ * $LastChangedBy$ - Initials Date Comment - aw 13.01.2010 initial + * Initials Date Comment + * aw 13.01.2010 initial */ #include #include @@ -97,7 +97,7 @@ void usage() { char version[DLT_CONVERT_TEXTBUFSIZE]; - dlt_get_version(version,255); + dlt_get_version(version, 255); printf("Usage: dlt-convert [options] [commands] file1 [file2]\n"); printf("Read DLT files, print DLT messages as ASCII and store the messages again.\n"); @@ -124,7 +124,7 @@ void usage() /** * Main function of tool. */ -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int vflag = 0; int cflag = 0; @@ -141,271 +141,239 @@ int main(int argc, char* argv[]) int index; int c; - DltFile file; - DltFilter filter; + DltFile file; + DltFilter filter; - int ohandle=-1; + int ohandle = -1; - int num, begin, end; + int num, begin, end; - char text[DLT_CONVERT_TEXTBUFSIZE]; + char text[DLT_CONVERT_TEXTBUFSIZE]; - struct iovec iov[2]; + struct iovec iov[2]; int bytes_written; opterr = 0; while ((c = getopt (argc, argv, "vcashxmwf:b:e:o:")) != -1) - switch (c) - { + switch (c) { case 'v': - { - vflag = 1; - break; - } + { + vflag = 1; + break; + } case 'c': - { - cflag = 1; - break; - } + { + cflag = 1; + break; + } case 'a': - { - aflag = 1; - break; - } + { + aflag = 1; + break; + } case 's': - { - sflag = 1; - break; - } + { + sflag = 1; + break; + } case 'x': - { - xflag = 1; - break; - } + { + xflag = 1; + break; + } case 'm': - { - mflag = 1; - break; - } + { + mflag = 1; + break; + } case 'w': - { - wflag = 1; - break; - } + { + wflag = 1; + break; + } case 'h': - { - usage(); - return -1; - } + { + usage(); + return -1; + } case 'f': - { - fvalue = optarg; - break; - } + { + fvalue = optarg; + break; + } case 'b': - { - bvalue = optarg; - break; - } + { + bvalue = optarg; + break; + } case 'e': - { - evalue = optarg; - break; - } + { + evalue = optarg; + break; + } case 'o': - { - ovalue = optarg; - break; - } + { + ovalue = optarg; + break; + } case '?': - { - if (optopt == 'f' || optopt == 'b' || optopt == 'e' || optopt == 'o') - { - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - } - else if (isprint (optopt)) - { - fprintf (stderr, "Unknown option `-%c'.\n", optopt); - } - else - { - fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt); - } - /* unknown or wrong option used, show usage information and terminate */ - usage(); - return -1; - } + { + if ((optopt == 'f') || (optopt == 'b') || (optopt == 'e') || (optopt == 'o')) + fprintf (stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint (optopt)) + fprintf (stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + + /* unknown or wrong option used, show usage information and terminate */ + usage(); + return -1; + } default: - { - abort(); - return -1;//for parasoft - } + { + abort(); + return -1; /*for parasoft */ + } } /* initialise structure to use DLT file */ - dlt_file_init(&file,vflag); + dlt_file_init(&file, vflag); /* first parse filter file if filter parameter is used */ - if (fvalue) - { - if (dlt_filter_load(&filter,fvalue,vflag) < DLT_RETURN_OK) - { - dlt_file_free(&file,vflag); + if (fvalue) { + if (dlt_filter_load(&filter, fvalue, vflag) < DLT_RETURN_OK) { + dlt_file_free(&file, vflag); return -1; } - dlt_file_set_filter(&file,&filter,vflag); + dlt_file_set_filter(&file, &filter, vflag); } - if (ovalue) - { - ohandle = open(ovalue,O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ - if (ohandle == -1) - { - dlt_file_free(&file,vflag); - fprintf(stderr,"ERROR: Output file %s cannot be opened!\n",ovalue); + if (ovalue) { + ohandle = open(ovalue, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ + + if (ohandle == -1) { + dlt_file_free(&file, vflag); + fprintf(stderr, "ERROR: Output file %s cannot be opened!\n", ovalue); return -1; } - } - for (index = optind; index < argc; index++) - { + for (index = optind; index < argc; index++) { /* load, analyse data file and create index list */ - if (dlt_file_open(&file,argv[index],vflag) >= DLT_RETURN_OK) - { - while (dlt_file_read(&file,vflag) >= DLT_RETURN_OK) - { - } + if (dlt_file_open(&file, argv[index], vflag) >= DLT_RETURN_OK) { + while (dlt_file_read(&file, vflag) >= DLT_RETURN_OK) {} } - if (aflag || sflag || xflag || mflag || ovalue) - { + if (aflag || sflag || xflag || mflag || ovalue) { if (bvalue) - { begin = atoi(bvalue); - } - else - { + else begin = 0; - } - if (evalue && (wflag==0)) - { + if (evalue && (wflag == 0)) end = atoi(evalue); - } - else - { - end = file.counter-1; - } - - if (begin<0 || begin>=file.counter) - { - fprintf(stderr,"ERROR: Selected first message %d is out of range!\n",begin); + else + end = file.counter - 1; + + if ((begin < 0) || (begin >= file.counter)) { + fprintf(stderr, "ERROR: Selected first message %d is out of range!\n", begin); return -1; } - if (end<0 || end>=file.counter || end= file.counter) || (end < begin)) { + fprintf(stderr, "ERROR: Selected end message %d is out of range!\n", end); return -1; } - for (num = begin; num <= end ;num++) - { - dlt_file_message(&file,num,vflag); - if (xflag) - { - printf("%d ",num); - dlt_message_print_hex(&(file.msg),text,DLT_CONVERT_TEXTBUFSIZE,vflag); + for (num = begin; num <= end; num++) { + dlt_file_message(&file, num, vflag); + + if (xflag) { + printf("%d ", num); + dlt_message_print_hex(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag); } else if (aflag) { - printf("%d ",num); + printf("%d ", num); - dlt_message_header(&(file.msg),text,DLT_CONVERT_TEXTBUFSIZE,vflag); + dlt_message_header(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag); - printf("%s ",text); + printf("%s ", text); - dlt_message_payload(&file.msg,text,DLT_CONVERT_TEXTBUFSIZE,DLT_OUTPUT_ASCII,vflag); + dlt_message_payload(&file.msg, text, DLT_CONVERT_TEXTBUFSIZE, DLT_OUTPUT_ASCII, vflag); - printf("[%s]\n",text); + printf("[%s]\n", text); } else if (mflag) { - printf("%d ",num); - dlt_message_print_mixed_plain(&(file.msg),text,DLT_CONVERT_TEXTBUFSIZE,vflag); + printf("%d ", num); + dlt_message_print_mixed_plain(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag); } else if (sflag) { - printf("%d ",num); + printf("%d ", num); - dlt_message_header(&(file.msg),text,DLT_CONVERT_TEXTBUFSIZE,vflag); + dlt_message_header(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag); - printf("%s \n",text); + printf("%s \n", text); } /* if file output enabled write message */ - if (ovalue) - { + if (ovalue) { iov[0].iov_base = file.msg.headerbuffer; iov[0].iov_len = file.msg.headersize; iov[1].iov_base = file.msg.databuffer; iov[1].iov_len = file.msg.datasize; bytes_written = writev(ohandle, iov, 2); - if (0 > bytes_written){ - printf("in main: writev(ohandle, iov, 2); returned an error!" ); - dlt_file_free(&file,vflag); - return -1; + + if (0 > bytes_written) { + printf("in main: writev(ohandle, iov, 2); returned an error!"); + dlt_file_free(&file, vflag); + return -1; } } /* check for new messages if follow flag set */ - if (wflag && num==end) - { - while (1) - { - while (dlt_file_read(&file,0)>=0) - { - } - if (end == (file.counter-1)) - { + if (wflag && (num == end)) { + while (1) { + while (dlt_file_read(&file, 0) >= 0) {} + + if (end == (file.counter - 1)) { /* Sleep if no new message was received */ sleep(1); } - else - { + else { /* set new end of log file and continue reading */ - end = file.counter-1; + end = file.counter - 1; break; } } } } } - if (cflag) - { - printf("Total number of messages: %d\n",file.counter_total); + + if (cflag) { + printf("Total number of messages: %d\n", file.counter_total); + if (file.filter) - { - printf("Filtered number of messages: %d\n",file.counter); - } + printf("Filtered number of messages: %d\n", file.counter); } } + if (ovalue) - { close(ohandle); - } - if (index == optind) - { + + if (index == optind) { /* no file selected, show usage and terminate */ - fprintf(stderr,"ERROR: No file selected\n"); + fprintf(stderr, "ERROR: No file selected\n"); usage(); return -1; } - dlt_file_free(&file,vflag); + dlt_file_free(&file, vflag); return 0; } diff --git a/src/console/dlt-passive-node-ctrl.c b/src/console/dlt-passive-node-ctrl.c index 88a03a8..76ff789 100644 --- a/src/console/dlt-passive-node-ctrl.c +++ b/src/console/dlt-passive-node-ctrl.c @@ -78,7 +78,7 @@ static struct PassiveNodeOptions { } g_options = { .command = UNDEFINED, .connection_state = UNDEFINED, - .node_id = {'\0'}, + .node_id = { '\0' }, }; unsigned int get_command(void) @@ -98,13 +98,11 @@ unsigned int get_connection_state(void) void set_connection_state(unsigned int s) { - if ((s == DLT_NODE_CONNECT) || (s == DLT_NODE_DISCONNECT)) - { + if ((s == DLT_NODE_CONNECT) || (s == DLT_NODE_DISCONNECT)) { g_options.connection_state = s; set_command(DLT_SERVICE_ID_PASSIVE_NODE_CONNECT); } - else - { + else { pr_error("Connection status %u invalid\n", s); exit(-1); } @@ -112,13 +110,11 @@ void set_connection_state(unsigned int s) void set_node_id(char *id) { - if (id == 0) - { + if (id == 0) { pr_error("node identifier is NULL\n"); exit(-1); } - else - { + else { strncpy(g_options.node_id, id, DLT_ID_SIZE); } } @@ -134,28 +130,22 @@ char *get_node_id() * @param info DltServicePassiveNodeConnectionInfo */ static void dlt_print_passive_node_status( - DltServicePassiveNodeConnectionInfo *info) + DltServicePassiveNodeConnectionInfo *info) { unsigned int i = 0; char *status; if (info == NULL) - { return; - } printf("\nPassive Node connection status:\n" "---------------------------------\n"); - for(i = 0; i < info->num_connections; i++) - { + + for (i = 0; i < info->num_connections; i++) { if (info->connection_status[i] == DLT_GATEWAY_CONNECTED) - { status = DLT_NODE_CONNECTED_STR; - } else - { status = DLT_NODE_DISCONNECTED_STR; - } printf("%.4s: %s\n", &info->node_id[i * DLT_ID_SIZE], status); } @@ -181,10 +171,8 @@ static int dlt_passive_node_analyze_response(char *answer, int ret = -1; char resp_ok[MAX_RESPONSE_LENGTH] = { 0 }; - if (answer == NULL || payload == NULL) - { + if ((answer == NULL) || (payload == NULL)) return -1; - } snprintf(resp_ok, MAX_RESPONSE_LENGTH, @@ -194,26 +182,22 @@ static int dlt_passive_node_analyze_response(char *answer, pr_verbose("Response received: '%s'\n", answer); pr_verbose("Response expected: '%s'\n", resp_ok); - if (strncmp(answer, resp_ok, strlen(resp_ok)) == 0) - { + if (strncmp(answer, resp_ok, strlen(resp_ok)) == 0) { ret = 0; - if (get_command() == DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS) - { - if ((int)sizeof(DltServicePassiveNodeConnectionInfo) > len) - { + if (get_command() == DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS) { + if ((int)sizeof(DltServicePassiveNodeConnectionInfo) > len) { pr_error("Received payload is smaller than expected\n"); pr_verbose("Expected: %lu,\nreceived: %d", sizeof(DltServicePassiveNodeConnectionInfo), len); ret = -1; } - else - { + else { DltServicePassiveNodeConnectionInfo *info = - (DltServicePassiveNodeConnectionInfo *) (payload); - if (info == NULL) - { + (DltServicePassiveNodeConnectionInfo *)(payload); + + if (info == NULL) { fprintf(stderr, "Received response is NULL\n"); return -1; } @@ -235,19 +219,18 @@ DltControlMsgBody *dlt_passive_node_prepare_message_body() { DltControlMsgBody *mb = calloc(1, sizeof(DltControlMsgBody)); char *ecuid = get_node_id(); + if (mb == NULL) - { return NULL; - } - if (get_command() == DLT_SERVICE_ID_PASSIVE_NODE_CONNECT) - { + if (get_command() == DLT_SERVICE_ID_PASSIVE_NODE_CONNECT) { mb->data = calloc(1, sizeof(DltServicePassiveNodeConnect)); - if (mb->data == NULL) - { + + if (mb->data == NULL) { free(mb); return NULL; } + mb->size = sizeof(DltServicePassiveNodeConnect); DltServicePassiveNodeConnect *serv = (DltServicePassiveNodeConnect *) mb->data; @@ -256,18 +239,17 @@ DltControlMsgBody *dlt_passive_node_prepare_message_body() memcpy(serv->node_id, ecuid, DLT_ID_SIZE); } - else /* DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS */ - { + else { /* DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS */ mb->data = calloc(1, sizeof(DltServicePassiveNodeConnectionInfo)); - if (mb->data == NULL) - { + + if (mb->data == NULL) { free(mb); return NULL; } mb->size = sizeof(DltServicePassiveNodeConnectionInfo); DltServicePassiveNodeConnectionInfo *serv = - (DltServicePassiveNodeConnectionInfo *) mb->data; + (DltServicePassiveNodeConnectionInfo *)mb->data; serv->service_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS; } @@ -280,14 +262,11 @@ DltControlMsgBody *dlt_passive_node_prepare_message_body() void dlt_passive_node_destroy_message_body(DltControlMsgBody *msg_body) { if (msg_body == NULL) - { return; - } if (msg_body->data != NULL) - { free(msg_body->data); - } + free(msg_body); } @@ -303,8 +282,7 @@ static int dlt_passive_node_ctrl_single_request() /* Initializing the communication with the daemon */ if (dlt_control_init(dlt_passive_node_analyze_response, get_ecuid(), - get_verbosity()) != 0) - { + get_verbosity()) != 0) { pr_error("Failed to initialize connection with the daemon.\n"); return ret; } @@ -313,8 +291,7 @@ static int dlt_passive_node_ctrl_single_request() DltControlMsgBody *msg_body = NULL; msg_body = dlt_passive_node_prepare_message_body(); - if (msg_body == NULL) - { + if (msg_body == NULL) { pr_error("Data for Dlt Message body is NULL\n"); return ret; } @@ -362,21 +339,19 @@ static int parse_args(int argc, char *argv[]) opterr = 0; while ((c = getopt(argc, argv, "c:hn:stv")) != -1) - { - switch(c) - { + switch (c) { case 'c': - state = (int)strtol(optarg,NULL, 10); - if (state == DLT_NODE_CONNECT || state == DLT_NODE_DISCONNECT) - { + state = (int)strtol(optarg, NULL, 10); + + if ((state == DLT_NODE_CONNECT) || (state == DLT_NODE_DISCONNECT)) { set_connection_state(state); set_command(DLT_SERVICE_ID_PASSIVE_NODE_CONNECT); } - else - { + else { pr_error("unknown connection state: %d\n", state); return -1; } + break; case 'h': usage(); @@ -395,21 +370,18 @@ static int parse_args(int argc, char *argv[]) pr_verbose("Now in verbose mode.\n"); break; case '?': + if (isprint(optopt)) - { pr_error("Unknown option -%c.\n", optopt); - } else - { pr_error("Unknown option character \\x%x.\n", optopt); - } + usage(); return -1; default: pr_error("Try %s -h for more information.\n", argv[0]); return -1; } - } return 0; } @@ -432,15 +404,12 @@ int main(int argc, char *argv[]) /* Get command line arguments */ if (parse_args(argc, argv) != 0) - { return -1; - } - if (get_command() == UNDEFINED || - (get_command() == DLT_SERVICE_ID_PASSIVE_NODE_CONNECT && - g_options.node_id[0] == '\0' && - g_options.connection_state == DLT_NODE_CONNECT_UNDEF)) - { + if ((get_command() == UNDEFINED) || + ((get_command() == DLT_SERVICE_ID_PASSIVE_NODE_CONNECT) && + (g_options.node_id[0] == '\0') && + (g_options.connection_state == DLT_NODE_CONNECT_UNDEF))) { pr_error("No valid parameter configuration given!\n"); usage(); return -1; diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c index e22d15e..9cfad36 100644 --- a/src/console/dlt-receive.c +++ b/src/console/dlt-receive.c @@ -22,7 +22,7 @@ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt-receive.cpp -*/ + */ /******************************************************************************* @@ -64,8 +64,8 @@ * $LastChangedRevision: 1670 $ * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $ * $LastChangedBy$ - Initials Date Comment - aw 13.01.2010 initial + * Initials Date Comment + * aw 13.01.2010 initial */ #include /* for isprint() */ @@ -78,9 +78,9 @@ #include #include #ifdef __linux__ -#include +# include #else -#include +# include #endif #include @@ -119,7 +119,7 @@ void usage() { char version[255]; - dlt_get_version(version,255); + dlt_get_version(version, 255); printf("Usage: dlt-receive [options] hostname/serial_device_name\n"); printf("Receive DLT messages from DLT daemon and print or store the messages.\n"); @@ -143,49 +143,40 @@ void usage() } -int64_t convert_arg_to_byte_size(char * arg) +int64_t convert_arg_to_byte_size(char *arg) { size_t i; int64_t factor; int64_t result; + /* check if valid input */ - for (i = 0; i result) - { + if (min_size > result) { char tmp[256]; - snprintf(tmp, 256, "ERROR: Specified limit: %" PRId64 "is smaller than a the size of a single message: %" PRId64 "!\n", result, min_size); + snprintf(tmp, + 256, + "ERROR: Specified limit: %" PRId64 "is smaller than a the size of a single message: %" PRId64 "!\n", + result, + min_size); dlt_log(LOG_ERR, tmp); result = -2; } @@ -211,22 +205,20 @@ int64_t convert_arg_to_byte_size(char * arg) /* * open output file */ -int dlt_receive_open_output_file(DltReceiveData * dltdata) +int dlt_receive_open_output_file(DltReceiveData *dltdata) { /* if (file_already_exists) */ glob_t outer; - if (glob(dltdata->ovalue, GLOB_TILDE | GLOB_NOSORT, NULL, &outer) == 0) - { - if (dltdata->vflag) - { - char tmp[256]; - snprintf(tmp, 256, "File %s already exists, need to rename first\n", dltdata->ovalue); - dlt_log(LOG_INFO, tmp); + + if (glob(dltdata->ovalue, GLOB_TILDE | GLOB_NOSORT, NULL, &outer) == 0) { + if (dltdata->vflag) { + char tmp[256]; + snprintf(tmp, 256, "File %s already exists, need to rename first\n", dltdata->ovalue); + dlt_log(LOG_INFO, tmp); } - if (dltdata->part_num < 0) - { - char pattern[PATH_MAX+1]; + if (dltdata->part_num < 0) { + char pattern[PATH_MAX + 1]; pattern[PATH_MAX] = 0; snprintf(pattern, PATH_MAX, "%s.*.dlt", dltdata->ovaluebase); glob_t inner; @@ -238,60 +230,55 @@ int dlt_receive_open_output_file(DltReceiveData * dltdata) * foo.1000.dlt * foo.11.dlt */ - if (glob(pattern, GLOB_TILDE | GLOB_NOSORT, NULL, &inner) == 0) - { - /* search for the highest number used */ - size_t i; - for (i= 0; i atoi("1.dlt"); - */ - int cur = atoi(&inner.gl_pathv[i][strlen(dltdata->ovaluebase)+1]); - if (cur > dltdata->part_num) - { - dltdata->part_num = cur; + if (glob(pattern, GLOB_TILDE | GLOB_NOSORT, NULL, &inner) == 0) { + /* search for the highest number used */ + size_t i; + + for (i = 0; i < inner.gl_pathc; ++i) { + /* convert string that follows the period after the initial portion, + * e.g. gt.gl_pathv[i] = foo.1.dlt -> atoi("1.dlt"); + */ + int cur = atoi(&inner.gl_pathv[i][strlen(dltdata->ovaluebase) + 1]); + + if (cur > dltdata->part_num) + dltdata->part_num = cur; } - } } + globfree(&inner); ++dltdata->part_num; } - char filename[PATH_MAX+1]; + char filename[PATH_MAX + 1]; filename[PATH_MAX] = 0; snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase, dltdata->part_num++); - if (rename(dltdata->ovalue, filename) != 0) - { - char tmp[256]; - snprintf(tmp, 256, "ERROR: rename %s to %s failed with error %s\n", dltdata->ovalue, filename, strerror(errno)); - dlt_log(LOG_ERR, tmp); + + if (rename(dltdata->ovalue, filename) != 0) { + char tmp[256]; + snprintf(tmp, 256, "ERROR: rename %s to %s failed with error %s\n", dltdata->ovalue, filename, + strerror(errno)); + dlt_log(LOG_ERR, tmp); } - else - { - if (dltdata->vflag) - { + else if (dltdata->vflag) { char tmp[256]; snprintf(tmp, 256, "Renaming existing file from %s to %s\n", dltdata->ovalue, filename); dlt_log(LOG_INFO, tmp); - } } - } /* if (file_already_exists) */ + globfree(&outer); - dltdata->ohandle = open(dltdata->ovalue, O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + dltdata->ohandle = open(dltdata->ovalue, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); return dltdata->ohandle; } -void dlt_receive_close_output_file(DltReceiveData * dltdata) +void dlt_receive_close_output_file(DltReceiveData *dltdata) { - if (dltdata->ohandle) - { + if (dltdata->ohandle) { close(dltdata->ohandle); dltdata->ohandle = -1; } @@ -301,9 +288,9 @@ void dlt_receive_close_output_file(DltReceiveData * dltdata) /** * Main function of tool. */ -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - DltClient dltclient; + DltClient dltclient; DltReceiveData dltdata; int c; int index; @@ -321,7 +308,7 @@ int main(int argc, char* argv[]) dltdata.evalue = 0; dltdata.bvalue = 0; dltdata.climit = -1; /* default: -1 = unlimited */ - dltdata.ohandle=-1; + dltdata.ohandle = -1; dltdata.totalbytes = 0; dltdata.part_num = -1; @@ -329,115 +316,108 @@ int main(int argc, char* argv[]) opterr = 0; while ((c = getopt (argc, argv, "vashyxmf:o:e:b:c:")) != -1) - switch (c) - { + switch (c) { case 'v': - { - dltdata.vflag = 1; - break; - } + { + dltdata.vflag = 1; + break; + } case 'a': - { - dltdata.aflag = 1; - break; - } + { + dltdata.aflag = 1; + break; + } case 's': - { - dltdata.sflag = 1; - break; - } + { + dltdata.sflag = 1; + break; + } case 'x': - { - dltdata.xflag = 1; - break; - } + { + dltdata.xflag = 1; + break; + } case 'm': - { - dltdata.mflag = 1; - break; - } + { + dltdata.mflag = 1; + break; + } case 'h': - { - usage(); - return -1; - } + { + usage(); + return -1; + } case 'y': - { - dltdata.yflag = 1; - break; - } + { + dltdata.yflag = 1; + break; + } case 'f': - { - dltdata.fvalue = optarg; - break; - } + { + dltdata.fvalue = optarg; + break; + } case 'o': - { - dltdata.ovalue = optarg; - size_t to_copy = strlen(dltdata.ovalue); - if (strcmp(&dltdata.ovalue[to_copy-4], ".dlt") == 0) - { - to_copy = to_copy - 4; - } - - dltdata.ovaluebase = (char *)calloc(1, to_copy + 1); - - if (dltdata.ovaluebase == NULL) - { - fprintf (stderr, "Memory allocation failed.\n"); - return -1; - } + { + dltdata.ovalue = optarg; + size_t to_copy = strlen(dltdata.ovalue); - dltdata.ovaluebase[to_copy] = '\0'; - memcpy(dltdata.ovaluebase, dltdata.ovalue, to_copy); - break; - } + if (strcmp(&dltdata.ovalue[to_copy - 4], ".dlt") == 0) + to_copy = to_copy - 4; + + dltdata.ovaluebase = (char *)calloc(1, to_copy + 1); + + if (dltdata.ovaluebase == NULL) { + fprintf (stderr, "Memory allocation failed.\n"); + return -1; + } + + dltdata.ovaluebase[to_copy] = '\0'; + memcpy(dltdata.ovaluebase, dltdata.ovalue, to_copy); + break; + } case 'e': - { - dltdata.evalue = optarg; - break; - } + { + dltdata.evalue = optarg; + break; + } case 'b': - { - dltdata.bvalue = atoi(optarg); - break; - } + { + dltdata.bvalue = atoi(optarg); + break; + } case 'c': - { - dltdata.climit = convert_arg_to_byte_size(optarg); - if (dltdata.climit < -1) - { - fprintf (stderr, "Invalid argument for option -c.\n"); - /* unknown or wrong option used, show usage information and terminate */ - usage(); - return -1; - } - break; - } + { + dltdata.climit = convert_arg_to_byte_size(optarg); + + if (dltdata.climit < -1) { + fprintf (stderr, "Invalid argument for option -c.\n"); + /* unknown or wrong option used, show usage information and terminate */ + usage(); + return -1; + } + + break; + } case '?': - { - if (optopt == 'o' || optopt == 'f' || optopt == 'c') - { - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - } - else if (isprint (optopt)) - { - fprintf (stderr, "Unknown option `-%c'.\n", optopt); - } - else - { - fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt); - } - /* unknown or wrong option used, show usage information and terminate */ - usage(); - return -1; - } + { + if ((optopt == 'o') || (optopt == 'f') || (optopt == 'c')) + fprintf (stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint (optopt)) + fprintf (stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + + /* unknown or wrong option used, show usage information and terminate */ + usage(); + return -1; + } default: - { - abort (); - return -1;//for parasoft - } + { + abort (); + return -1; /*for parasoft */ + } } /* Initialize DLT Client */ @@ -449,212 +429,183 @@ int main(int argc, char* argv[]) /* Setup DLT Client structure */ dltclient.mode = dltdata.yflag; - if (dltclient.mode==DLT_CLIENT_MODE_TCP) - { + if (dltclient.mode == DLT_CLIENT_MODE_TCP) { for (index = optind; index < argc; index++) - { - if(dlt_client_set_server_ip(&dltclient, argv[index]) == -1) - { - fprintf(stderr,"set server ip didn't succeed\n"); + 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) - { + + + if (dltclient.servIP == 0) { /* no hostname selected, show usage and terminate */ - fprintf(stderr,"ERROR: No hostname selected\n"); + fprintf(stderr, "ERROR: No hostname selected\n"); usage(); - dlt_client_cleanup(&dltclient,dltdata.vflag); + dlt_client_cleanup(&dltclient, dltdata.vflag); return -1; } } - else - { + else { for (index = optind; index < argc; index++) - { - if(dlt_client_set_serial_device(&dltclient, argv[index]) == -1) - { - fprintf(stderr,"set serial device didn't succeed\n"); + 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) - { + + + if (dltclient.serialDevice == 0) { /* no serial device name selected, show usage and terminate */ - fprintf(stderr,"ERROR: No serial device name specified\n"); + fprintf(stderr, "ERROR: No serial device name specified\n"); usage(); return -1; } - dlt_client_setbaudrate(&dltclient,dltdata.bvalue); + dlt_client_setbaudrate(&dltclient, dltdata.bvalue); } /* initialise structure to use DLT file */ - dlt_file_init(&(dltdata.file),dltdata.vflag); + dlt_file_init(&(dltdata.file), dltdata.vflag); /* first parse filter file if filter parameter is used */ - dlt_filter_init(&(dltdata.filter),dltdata.vflag); + dlt_filter_init(&(dltdata.filter), dltdata.vflag); - if (dltdata.fvalue) - { - if (dlt_filter_load(&(dltdata.filter),dltdata.fvalue,dltdata.vflag) < DLT_RETURN_OK) - { - dlt_file_free(&(dltdata.file),dltdata.vflag); + if (dltdata.fvalue) { + if (dlt_filter_load(&(dltdata.filter), dltdata.fvalue, dltdata.vflag) < DLT_RETURN_OK) { + dlt_file_free(&(dltdata.file), dltdata.vflag); return -1; } - dlt_file_set_filter(&(dltdata.file),&(dltdata.filter),dltdata.vflag); + dlt_file_set_filter(&(dltdata.file), &(dltdata.filter), dltdata.vflag); } /* open DLT output file */ - if (dltdata.ovalue) - { - if (dltdata.climit > -1) - { + if (dltdata.ovalue) { + if (dltdata.climit > -1) { char tmp[256]; snprintf(tmp, 256, "Using file size limit of %" PRId64 "bytes\n", dltdata.climit); dlt_log(LOG_INFO, tmp); dltdata.ohandle = dlt_receive_open_output_file(&dltdata); } - else /* in case no limit for the output file is given, we simply overwrite any existing file */ - { - dltdata.ohandle = open(dltdata.ovalue, O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + else { /* in case no limit for the output file is given, we simply overwrite any existing file */ + dltdata.ohandle = open(dltdata.ovalue, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); } - if (dltdata.ohandle == -1) - { - dlt_file_free(&(dltdata.file),dltdata.vflag); - fprintf(stderr,"ERROR: Output file %s cannot be opened!\n",dltdata.ovalue); + if (dltdata.ohandle == -1) { + dlt_file_free(&(dltdata.file), dltdata.vflag); + fprintf(stderr, "ERROR: Output file %s cannot be opened!\n", dltdata.ovalue); return -1; } } if (dltdata.evalue) - { - dlt_set_id(dltdata.ecuid,dltdata.evalue); - } - else - { - dlt_set_id(dltdata.ecuid,DLT_RECEIVE_ECU_ID); - } + dlt_set_id(dltdata.ecuid, dltdata.evalue); + else + dlt_set_id(dltdata.ecuid, DLT_RECEIVE_ECU_ID); /* Connect to TCP socket or open serial device */ - if (dlt_client_connect(&dltclient, dltdata.vflag) != DLT_RETURN_ERROR) - { + if (dlt_client_connect(&dltclient, dltdata.vflag) != DLT_RETURN_ERROR) { /* Dlt Client Main Loop */ dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag); /* Dlt Client Cleanup */ - dlt_client_cleanup(&dltclient,dltdata.vflag); + dlt_client_cleanup(&dltclient, dltdata.vflag); } /* dlt-receive cleanup */ if (dltdata.ovalue) - { close(dltdata.ohandle); - } free(dltdata.ovaluebase); - dlt_file_free(&(dltdata.file),dltdata.vflag); + dlt_file_free(&(dltdata.file), dltdata.vflag); - dlt_filter_free(&(dltdata.filter),dltdata.vflag); + dlt_filter_free(&(dltdata.filter), dltdata.vflag); return 0; } int dlt_receive_message_callback(DltMessage *message, void *data) { - DltReceiveData *dltdata; + DltReceiveData *dltdata; static char text[DLT_RECEIVE_BUFSIZE]; - struct iovec iov[2]; + struct iovec iov[2]; int bytes_written; - if ((message==0) || (data==0)) - { + if ((message == 0) || (data == 0)) return -1; - } - dltdata = (DltReceiveData*)data; + dltdata = (DltReceiveData *)data; /* prepare storage header */ if (DLT_IS_HTYP_WEID(message->standardheader->htyp)) - { - dlt_set_storageheader(message->storageheader,message->headerextra.ecu); - } + dlt_set_storageheader(message->storageheader, message->headerextra.ecu); else - { - dlt_set_storageheader(message->storageheader,dltdata->ecuid); - } + dlt_set_storageheader(message->storageheader, dltdata->ecuid); - if ((dltdata->fvalue==0) || - (dltdata->fvalue && dlt_message_filter_check(message,&(dltdata->filter),dltdata->vflag) == DLT_RETURN_TRUE)) - { + if ((dltdata->fvalue == 0) || + (dltdata->fvalue && + (dlt_message_filter_check(message, &(dltdata->filter), dltdata->vflag) == DLT_RETURN_TRUE))) { /* if no filter set or filter is matching display message */ - if (dltdata->xflag) - { - dlt_message_print_hex(message,text,DLT_RECEIVE_BUFSIZE,dltdata->vflag); + if (dltdata->xflag) { + dlt_message_print_hex(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); } else if (dltdata->aflag) { - dlt_message_header(message,text,DLT_RECEIVE_BUFSIZE,dltdata->vflag); + dlt_message_header(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); - printf("%s ",text); + printf("%s ", text); - dlt_message_payload(message,text,DLT_RECEIVE_BUFSIZE,DLT_OUTPUT_ASCII,dltdata->vflag); + dlt_message_payload(message, text, DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, dltdata->vflag); - printf("[%s]\n",text); + printf("[%s]\n", text); } else if (dltdata->mflag) { - dlt_message_print_mixed_plain(message,text,DLT_RECEIVE_BUFSIZE,dltdata->vflag); + dlt_message_print_mixed_plain(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); } else if (dltdata->sflag) { - dlt_message_header(message,text,DLT_RECEIVE_BUFSIZE,dltdata->vflag); + dlt_message_header(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); - printf("%s \n",text); + printf("%s \n", text); } /* if file output enabled write message */ - if (dltdata->ovalue) - { + if (dltdata->ovalue) { iov[0].iov_base = message->headerbuffer; iov[0].iov_len = message->headersize; iov[1].iov_base = message->databuffer; iov[1].iov_len = message->datasize; - if (dltdata->climit > -1) - { - int bytes_to_write = message->headersize + message->datasize; - - if ((bytes_to_write + dltdata->totalbytes > dltdata->climit)) - { + if (dltdata->climit > -1) { + int bytes_to_write = message->headersize + message->datasize; + + if ((bytes_to_write + dltdata->totalbytes > dltdata->climit)) { dlt_receive_close_output_file(dltdata); - - if (dlt_receive_open_output_file(dltdata) < 0) - { - printf("ERROR: dlt_receive_message_callback: Unable to open log when maximum filesize was reached!\n"); + + if (dlt_receive_open_output_file(dltdata) < 0) { + printf( + "ERROR: dlt_receive_message_callback: Unable to open log when maximum filesize was reached!\n"); return -1; - } - - dltdata->totalbytes = 0; - } + } + + dltdata->totalbytes = 0; + } } - + bytes_written = writev(dltdata->ohandle, iov, 2); dltdata->totalbytes += bytes_written; - if (0 > bytes_written){ - printf("dlt_receive_message_callback: writev(dltdata->ohandle, iov, 2); returned an error!" ); - return -1; + if (0 > bytes_written) { + printf("dlt_receive_message_callback: writev(dltdata->ohandle, iov, 2); returned an error!"); + return -1; } } } diff --git a/src/console/dlt-sortbytimestamp.c b/src/console/dlt-sortbytimestamp.c index 6d1d590..c006681 100644 --- a/src/console/dlt-sortbytimestamp.c +++ b/src/console/dlt-sortbytimestamp.c @@ -24,7 +24,7 @@ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt-sortbytimestamp.cpp -*/ + */ /******************************************************************************* ** ** @@ -86,16 +86,15 @@ int verbosity = 0; /** * Print information, conditional upon requested verbosity level */ -void verbose(int level, char * msg, ...) +void verbose(int level, char *msg, ...) { - if (level <= verbosity) - { - if (verbosity > 1) /* timestamp */ - { - time_t tnow = time((time_t*)0); + if (level <= verbosity) { + if (verbosity > 1) { /* timestamp */ + time_t tnow = time((time_t *)0); + if (tnow != -1) { - char * snow = ctime(&tnow); - /* suppress newline char */ + char *snow = ctime(&tnow); + /* suppress newline char */ snow[strlen(snow) - 1] = 0; printf("%s: ", snow); } @@ -107,26 +106,21 @@ void verbose(int level, char * msg, ...) vprintf(msg, args); /* lines without a terminal newline aren't guaranteed to be displayed */ - if (msg[len-1] != '\n') - { + if (msg[len - 1] != '\n') fflush(stdout); - } } } /** * Comparison function for use with qsort */ -int compare_index_timestamps(const void* a, const void *b) +int compare_index_timestamps(const void *a, const void *b) { - if (((TimestampIndex*)a)->tmsp > ((TimestampIndex*)b)->tmsp) - { + if (((TimestampIndex *)a)->tmsp > ((TimestampIndex *)b)->tmsp) return 1; - } - else if (((TimestampIndex*)a)->tmsp == ((TimestampIndex*)b)->tmsp) - { + else if (((TimestampIndex *)a)->tmsp == ((TimestampIndex *)b)->tmsp) return 0; - } + return -1; } @@ -140,23 +134,22 @@ void write_messages(int ohandle, DltFile *file, TimestampIndex *timestamps, int verbose(1, "Writing %d messages\n", message_count); - for (int i = 0; i < message_count; ++i) - { - if (0 == i % 1001 || i == message_count - 1) - { + for (int i = 0; i < message_count; ++i) { + if ((0 == i % 1001) || (i == message_count - 1)) verbose(2, "Writing message %d\r", i); - } - dlt_file_message(file,timestamps[i].num,0); + + dlt_file_message(file, timestamps[i].num, 0); iov[0].iov_base = file->msg.headerbuffer; iov[0].iov_len = file->msg.headersize; iov[1].iov_base = file->msg.databuffer; iov[1].iov_len = file->msg.datasize; bytes_written = writev(ohandle, iov, 2); - if (0 > bytes_written){ - printf("in main: writev(ohandle, iov, 2); returned an error!" ); - dlt_file_free(file,0); - exit (-1); + + if (0 > bytes_written) { + printf("in main: writev(ohandle, iov, 2); returned an error!"); + dlt_file_free(file, 0); + exit (-1); } } @@ -170,7 +163,7 @@ void usage() { char version[DLT_VERBUFSIZE]; - dlt_get_version(version,DLT_VERBUFSIZE); + dlt_get_version(version, DLT_VERBUFSIZE); printf("Usage: dlt-sortbytimestamp [options] [commands] file_in file_out\n"); printf("Read DLT file, sort by timestamp and store the messages again.\n"); @@ -190,7 +183,7 @@ void usage() /** * Main function of tool. */ -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int vflag = 0; int cflag = 0; @@ -208,7 +201,7 @@ int main(int argc, char* argv[]) DltFile file; DltFilter filter; - int ohandle=-1; + int ohandle = -1; int num, begin, end; @@ -217,168 +210,138 @@ int main(int argc, char* argv[]) verbose(1, "Configuring\n"); while ((c = getopt (argc, argv, "vchf:b:e:")) != -1) - switch (c) - { + switch (c) { case 'v': - { - verbosity += 1; - break; - } + { + verbosity += 1; + break; + } case 'c': - { - cflag = 1; - break; - } + { + cflag = 1; + break; + } case 'h': - { - usage(); - return -1; - } + { + usage(); + return -1; + } case 'f': - { - fvalue = optarg; - break; - } + { + fvalue = optarg; + break; + } case 'b': - { - bvalue = optarg; - break; - } + { + bvalue = optarg; + break; + } case 'e': - { - evalue = optarg; - break; - } + { + evalue = optarg; + break; + } case '?': - { - if (optopt == 'f' || optopt == 'b' || optopt == 'e') - { - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - } - else if (isprint (optopt)) - { - fprintf (stderr, "Unknown option `-%c'.\n", optopt); - } - else - { - fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt); - } - /* unknown or wrong option used, show usage information and terminate */ - usage(); - return -1; - } + { + if ((optopt == 'f') || (optopt == 'b') || (optopt == 'e')) + fprintf (stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint (optopt)) + fprintf (stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + + /* unknown or wrong option used, show usage information and terminate */ + usage(); + return -1; + } default: - { - abort(); - return -1;//for parasoft - } + { + abort(); + return -1; /*for parasoft */ + } } /* Don't use vflag on quietest levels */ if (verbosity > 2) - { vflag = 1; - } verbose (1, "Initializing\n"); /* initialise structure to use DLT file */ - dlt_file_init(&file,vflag); + dlt_file_init(&file, vflag); /* first parse filter file if filter parameter is used */ - if (fvalue) - { - if (bvalue || evalue) - { - fprintf(stderr,"ERROR: can't specify a range *and* filtering!\n"); - dlt_file_free(&file,vflag); + if (fvalue) { + if (bvalue || evalue) { + fprintf(stderr, "ERROR: can't specify a range *and* filtering!\n"); + dlt_file_free(&file, vflag); return -1; } - if (dlt_filter_load(&filter,fvalue,vflag) < DLT_RETURN_OK) - { - dlt_file_free(&file,vflag); + if (dlt_filter_load(&filter, fvalue, vflag) < DLT_RETURN_OK) { + dlt_file_free(&file, vflag); return -1; } - dlt_file_set_filter(&file,&filter,vflag); + dlt_file_set_filter(&file, &filter, vflag); } ivalue = argv[optind]; - if (!ivalue) - { - dlt_file_free(&file,vflag); - fprintf(stderr,"ERROR: Need an input file!\n"); + if (!ivalue) { + dlt_file_free(&file, vflag); + fprintf(stderr, "ERROR: Need an input file!\n"); return -1; } ovalue = argv[optind + 1]; - if (ovalue) - { - ohandle = open(ovalue,O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ - if (ohandle == -1) - { - dlt_file_free(&file,vflag); - fprintf(stderr,"ERROR: Output file %s cannot be opened!\n",ovalue); + if (ovalue) { + ohandle = open(ovalue, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ + + if (ohandle == -1) { + dlt_file_free(&file, vflag); + fprintf(stderr, "ERROR: Output file %s cannot be opened!\n", ovalue); return -1; } } - else - { - dlt_file_free(&file,vflag); - fprintf(stderr,"ERROR: Need an output file!\n"); + else { + dlt_file_free(&file, vflag); + fprintf(stderr, "ERROR: Need an output file!\n"); return -1; } verbose(1, "Loading\n"); /* load, analyse data file and create index list */ - if (dlt_file_open(&file,ivalue,vflag) >= DLT_RETURN_OK) - { - while (dlt_file_read(&file,vflag) >= DLT_RETURN_OK) - { - } + if (dlt_file_open(&file, ivalue, vflag) >= DLT_RETURN_OK) { + while (dlt_file_read(&file, vflag) >= DLT_RETURN_OK) {} } if (cflag) { if (fvalue) - { printf("Loaded %d messages, %d after filtering.\n", file.counter_total, file.counter); - } else - { printf("Loaded %d messages.\n", file.counter_total); - } } if (bvalue) - { begin = atoi(bvalue); - } else - { begin = 0; - } if (evalue) - { end = atoi(evalue); - } else - { - end = file.counter-1; - } + end = file.counter - 1; - if (begin<0 || begin>=file.counter || begin>end) - { - fprintf(stderr,"ERROR: Selected first message %d is out of range!\n",begin); + if ((begin < 0) || (begin >= file.counter) || (begin > end)) { + fprintf(stderr, "ERROR: Selected first message %d is out of range!\n", begin); return -1; } - if (end<0 || end=file.counter) - { - fprintf(stderr,"ERROR: Selected end message %d is out of range!\n",end); + + if ((end < 0) || (end < begin) || (end >= file.counter)) { + fprintf(stderr, "ERROR: Selected end message %d is out of range!\n", end); return -1; } @@ -388,31 +351,30 @@ int main(int argc, char* argv[]) message_count = 1 + end - begin; - timestamp_index = (TimestampIndex*)malloc(sizeof(TimestampIndex) * message_count); + timestamp_index = (TimestampIndex *)malloc(sizeof(TimestampIndex) * message_count); - if (timestamp_index == 0) - { - fprintf(stderr,"ERROR: Failed to allocate memory for message index!\n"); - dlt_file_free(&file,vflag); + if (timestamp_index == 0) { + fprintf(stderr, "ERROR: Failed to allocate memory for message index!\n"); + dlt_file_free(&file, vflag); return -1; } verbose(1, "Filling %d entries\n", message_count); - for (num = begin; num <= end; num++) - { - dlt_file_message(&file,num,vflag); + + for (num = begin; num <= end; num++) { + dlt_file_message(&file, num, vflag); timestamp_index[num - begin].num = num; timestamp_index[num - begin].tmsp = file.msg.headerextra.tmsp; } verbose(1, "Sorting\n"); - qsort((void*)timestamp_index, message_count, sizeof(TimestampIndex), compare_index_timestamps); + qsort((void *)timestamp_index, message_count, sizeof(TimestampIndex), compare_index_timestamps); write_messages(ohandle, &file, timestamp_index, message_count); close(ohandle); verbose(1, "Tidying up.\n"); free(timestamp_index); - dlt_file_free(&file,vflag); + dlt_file_free(&file, vflag); return 0; } diff --git a/src/console/logstorage/dlt-logstorage-common.c b/src/console/logstorage/dlt-logstorage-common.c index ae67c9a..0655d66 100644 --- a/src/console/logstorage/dlt-logstorage-common.c +++ b/src/console/logstorage/dlt-logstorage-common.c @@ -71,7 +71,7 @@ #include "dlt-logstorage-common.h" #ifdef DLT_LOGSTORAGE_CTRL_UDEV_ENABLE -#include "dlt-logstorage-udev.h" +# include "dlt-logstorage-udev.h" #endif #include "dlt-logstorage-prop.h" @@ -96,9 +96,7 @@ void set_handler_type(char *type) g_options.handler_type = CTRL_UDEV; if (type && check_proprietary_handling(type)) - { g_options.handler_type = CTRL_PROPRIETARY; - } } int get_default_event_type(void) @@ -121,9 +119,7 @@ void set_default_path(char *path) memset(g_options.device_path, 0, DLT_MOUNT_PATH_MAX); if (path != NULL) - { strncpy(g_options.device_path, path, DLT_MOUNT_PATH_MAX - 1); - } } /* Used by the handlers */ @@ -150,8 +146,7 @@ int dlt_logstorage_get_handler_fd(void) */ int dlt_logstorage_init_handler(void) { - switch (get_handler_type()) - { + switch (get_handler_type()) { case CTRL_PROPRIETARY: return dlt_logstorage_prop_init(); case CTRL_UDEV: @@ -170,8 +165,7 @@ int dlt_logstorage_init_handler(void) */ int dlt_logstorage_deinit_handler(void) { - switch (get_handler_type()) - { + switch (get_handler_type()) { case CTRL_PROPRIETARY: return dlt_logstorage_prop_deinit(); case CTRL_UDEV: @@ -179,7 +173,7 @@ int dlt_logstorage_deinit_handler(void) #ifdef DLT_LOGSTORAGE_CTRL_UDEV_ENABLE return dlt_logstorage_udev_deinit(); #else - return -1; + return -1; #endif } } @@ -200,8 +194,7 @@ int dlt_logstorage_check_config_file(char *mnt_point) int i = 0; int ret = 0; - if ((mnt_point == NULL) || (mnt_point[0] == '\0')) - { + if ((mnt_point == NULL) || (mnt_point[0] == '\0')) { pr_error("Mount point missing.\n"); return ret; } @@ -210,30 +203,24 @@ int dlt_logstorage_check_config_file(char *mnt_point) n = scandir(mnt_point, &files, NULL, alphasort); - if (n <= 0) - { + if (n <= 0) { pr_error("Cannot read mounted directory\n"); return ret; } - do - { + do { pr_verbose("Checking %s.\n", files[i]->d_name); - if (strncmp(files[i]->d_name, CONF_NAME, strlen(CONF_NAME)) == 0) - { + if (strncmp(files[i]->d_name, CONF_NAME, strlen(CONF_NAME)) == 0) { /* We found it ! */ pr_verbose("File found.\n"); ret = 1; break; } - } - while (++i < n); + } while (++i < n); - for (i = 0 ; i < n ; i++) - { + for (i = 0; i < n; i++) free(files[i]); - } free(files); return ret; @@ -247,16 +234,13 @@ int dlt_logstorage_check_config_file(char *mnt_point) */ int dlt_logstorage_check_directory_permission(char *mnt_point) { - if (mnt_point == NULL) - { + if (mnt_point == NULL) { pr_error("Given mount point is NULL\n"); return 0; } if (access(mnt_point, W_OK) == 0) - { return 1; - } return 0; } @@ -275,8 +259,7 @@ static DltControlMsgBody *prepare_message_body(DltControlMsgBody **body, { DltServiceOfflineLogstorage *serv = NULL; - if (path == NULL) - { + if (path == NULL) { pr_error("Mount path is uninitialized: %s\n", path); return NULL; } @@ -285,16 +268,14 @@ static DltControlMsgBody *prepare_message_body(DltControlMsgBody **body, *body = calloc(1, sizeof(DltControlMsgBody)); - if (!*body) - { + if (!*body) { pr_error("Not able to allocate memory for body.\n"); return *body; } (*body)->data = calloc(1, sizeof(DltServiceOfflineLogstorage)); - if (!(*body)->data) - { + if (!(*body)->data) { free(*body); *body = NULL; pr_error("Not able to allocate memory for body data.\n"); @@ -303,14 +284,14 @@ static DltControlMsgBody *prepare_message_body(DltControlMsgBody **body, (*body)->size = sizeof(DltServiceOfflineLogstorage); - serv = (DltServiceOfflineLogstorage *) (*body)->data; + serv = (DltServiceOfflineLogstorage *)(*body)->data; serv->service_id = DLT_SERVICE_ID_OFFLINE_LOGSTORAGE; serv->connection_type = conn_type; /* mount_point is DLT_MOUNT_PATH_MAX + 1 long, * and the memory is already zeroed. */ - strncpy(serv->mount_point, path, DLT_MOUNT_PATH_MAX-1); + strncpy(serv->mount_point, path, DLT_MOUNT_PATH_MAX - 1); pr_verbose("Body is now ready.\n"); @@ -330,8 +311,7 @@ int dlt_logstorage_send_event(int type, char *mount_point) DltControlMsgBody *msg_body = NULL; /* mount_point is checked against NULL in the preparation */ - if (!prepare_message_body(&msg_body, type, mount_point)) - { + if (!prepare_message_body(&msg_body, type, mount_point)) { pr_error("Data for Dlt Message body is NULL\n"); return -1; } diff --git a/src/console/logstorage/dlt-logstorage-ctrl.c b/src/console/logstorage/dlt-logstorage-ctrl.c index 87e303b..af014eb 100644 --- a/src/console/logstorage/dlt-logstorage-ctrl.c +++ b/src/console/logstorage/dlt-logstorage-ctrl.c @@ -66,7 +66,7 @@ #include #if defined(__linux__) -#include "sd-daemon.h" +# include "sd-daemon.h" #endif #include "dlt_protocol.h" @@ -111,8 +111,7 @@ int dlt_logstorage_must_exit(void) */ static void catch_signal(int signo) { - if (signo) - { + if (signo) { pr_error("Signal %d received, exiting.", signo); dlt_logstorage_exit(); } @@ -132,16 +131,13 @@ static void install_signal_handler(void) pr_verbose("Installing signal handler.\n"); /* install a signal handler for the above listed signals */ - for (i = 0 ; signals[i] ; i++) - { + for (i = 0; signals[i]; i++) { memset(&sa, 0, sizeof(sa)); sa.sa_handler = catch_signal; if (sigaction(signals[i], &sa, NULL) < 0) - { pr_error("Failed to install signal %u handler. Error: %s\n", signals[i], strerror(errno)); - } } } @@ -163,10 +159,8 @@ static int analyze_response(char *data, void *payload, int len) char resp_warning[MAX_RESPONSE_LENGTH] = { 0 }; char resp_perm_denied[MAX_RESPONSE_LENGTH] = { 0 }; - if (data == NULL || payload == NULL) - { + if ((data == NULL) || (payload == NULL)) return -1; - } /* satisfy compiler */ payload = payload; @@ -188,16 +182,14 @@ static int analyze_response(char *data, void *payload, int len) DLT_SERVICE_ID_OFFLINE_LOGSTORAGE); if (strncmp(data, resp_ok, strlen(resp_ok)) == 0) - { ret = 0; - } - if (strncmp(data, resp_warning, strlen(resp_warning)) == 0) - { + + if (strncmp(data, resp_warning, strlen(resp_warning)) == 0) { pr_error("Warning:Some filter configurations are ignored due to configuration issues \n"); ret = 0; } - if (strncmp(data, resp_perm_denied, strlen(resp_perm_denied)) == 0) - { + + if (strncmp(data, resp_perm_denied, strlen(resp_perm_denied)) == 0) { pr_error("Warning: Permission denied.\n"); ret = 0; } @@ -223,8 +215,7 @@ static int dlt_logstorage_ctrl_add_event(struct dlt_event *ev_hdl, int fd, void *cb) { - if ((fd < 0) || !cb || !ev_hdl) - { + if ((fd < 0) || !cb || !ev_hdl) { pr_error("Wrong parameter to add event (%d %p)\n", fd, cb); return -1; } @@ -251,28 +242,20 @@ static int dlt_logstorage_ctrl_execute_event_loop(struct dlt_event *ev) ret = poll(&ev->pfd, 1, POLL_TIME_OUT); - if (ret <= 0) - { + if (ret <= 0) { if (errno == EINTR) - { ret = 0; - } if (ret < 0) - { pr_error("poll error: %s\n", strerror(errno)); - } return ret; } if (ev->pfd.revents == 0) - { return 0; - } - if (ev->pfd.events & EV_MASK_REJECTED) - { + if (ev->pfd.events & EV_MASK_REJECTED) { pr_error("Error while polling. Event received: 0x%x\n", ev->pfd.events); /* We only support one event producer. * Error means that this producer died. @@ -284,8 +267,7 @@ static int dlt_logstorage_ctrl_execute_event_loop(struct dlt_event *ev) return -1; } - if (!callback) - { + if (!callback) { pr_error("Callback not found, exiting.\n"); dlt_logstorage_exit(); return -1; @@ -293,8 +275,7 @@ static int dlt_logstorage_ctrl_execute_event_loop(struct dlt_event *ev) pr_verbose("Got new event, calling %p.\n", callback); - if (callback() < 0) - { + if (callback() < 0) { pr_error("Error while calling the callback, exiting.\n"); dlt_logstorage_exit(); return -1; @@ -327,23 +308,20 @@ static int dlt_logstorage_ctrl_setup_event_loop(void) /* Initializing the communication with the daemon */ while (dlt_control_init(analyze_response, get_ecuid(), get_verbosity()) && - !dlt_logstorage_must_exit()) - { + !dlt_logstorage_must_exit()) { pr_error("Failed to initialize connection with the daemon.\n"); pr_error("Retrying to connect in %lds.\n", get_timeout()); sleep(get_timeout()); } - if (dlt_logstorage_must_exit()) - { + if (dlt_logstorage_must_exit()) { pr_verbose("Exiting.\n"); return 0; } pr_verbose("Initializing event generator.\n"); - if (dlt_logstorage_init_handler() < 0) - { + if (dlt_logstorage_init_handler() < 0) { pr_error("Failed to initialize handler.\n"); dlt_control_deinit(); return -1; @@ -351,16 +329,13 @@ static int dlt_logstorage_ctrl_setup_event_loop(void) if (dlt_logstorage_ctrl_add_event(&ev_hdl, dlt_logstorage_get_handler_fd(), - dlt_logstorage_get_handler_cb()) < 0) - { + dlt_logstorage_get_handler_cb()) < 0) { pr_error("add_event error: %s\n", strerror(errno)); dlt_logstorage_exit(); } while (!dlt_logstorage_must_exit() && (ret == 0)) - { ret = dlt_logstorage_ctrl_execute_event_loop(&ev_hdl); - } /* Clean up */ dlt_logstorage_deinit_handler(); @@ -378,19 +353,16 @@ static int dlt_logstorage_ctrl_single_request() int ret = 0; /* in case sync all caches, an empty path is given */ - if (get_default_event_type() != EVENT_SYNC_CACHE) - { + if (get_default_event_type() != EVENT_SYNC_CACHE) { /* Check if a 'CONF_NAME' file is present at the given path */ - if (!dlt_logstorage_check_config_file(get_default_path())) - { + if (!dlt_logstorage_check_config_file(get_default_path())) { pr_error("No '%s' file available at: %s\n", CONF_NAME, get_default_path()); return -1; } - if (!dlt_logstorage_check_directory_permission(get_default_path())) - { + if (!dlt_logstorage_check_directory_permission(get_default_path())) { pr_error("'%s' is not writable\n", get_default_path()); return -1; } @@ -398,8 +370,7 @@ static int dlt_logstorage_ctrl_single_request() /* Initializing the communication with the daemon */ while (dlt_control_init(analyze_response, get_ecuid(), get_verbosity()) && - !dlt_logstorage_must_exit()) - { + !dlt_logstorage_must_exit()) { pr_error("Failed to initialize connection with the daemon.\n"); pr_error("Retrying to connect in %lds.\n", get_timeout()); sleep(get_timeout()); @@ -441,15 +412,15 @@ static void usage(void) } static struct option long_options[] = { - {"command", required_argument, 0, 'c'}, - {"daemonize", optional_argument, 0, 'd'}, - {"ecuid", required_argument, 0, 'e'}, - {"help", no_argument, 0, 'h'}, - {"path", required_argument, 0, 'p'}, - {"snapshot", optional_argument, 0, 's'}, - {"timeout", required_argument, 0, 't'}, - {"verbose", no_argument, 0, 'v'}, - {0, 0, 0, 0} + { "command", required_argument, 0, 'c' }, + { "daemonize", optional_argument, 0, 'd' }, + { "ecuid", required_argument, 0, 'e' }, + { "help", no_argument, 0, 'h' }, + { "path", required_argument, 0, 'p' }, + { "snapshot", optional_argument, 0, 's' }, + { "timeout", required_argument, 0, 't' }, + { "verbose", no_argument, 0, 'v' }, + { 0, 0, 0, 0 } }; /** @brief Parses the application arguments @@ -471,14 +442,11 @@ static int parse_args(int argc, char *argv[]) ":s::t:he:p:d::c:v", long_options, &long_index)) != -1) - { - switch (c) - { + switch (c) { case 's': set_default_event_type(EVENT_SYNC_CACHE); - if (optarg != NULL && strlen(optarg) >= DLT_MOUNT_PATH_MAX) - { + if ((optarg != NULL) && (strlen(optarg) >= DLT_MOUNT_PATH_MAX)) { pr_error("Mount path '%s' too long\n", optarg); return -1; } @@ -501,8 +469,7 @@ static int parse_args(int argc, char *argv[]) break; case 'p': - if (strlen(optarg) >= DLT_MOUNT_PATH_MAX) - { + if (strlen(optarg) >= DLT_MOUNT_PATH_MAX) { pr_error("Mount path '%s' too long\n", optarg); return -1; } @@ -523,13 +490,9 @@ static int parse_args(int argc, char *argv[]) case '?': if (isprint(optopt)) - { pr_error("Unknown option -%c.\n", optopt); - } else - { pr_error("Unknown option character \\x%x.\n", optopt); - } usage(); return -1; @@ -537,11 +500,11 @@ static int parse_args(int argc, char *argv[]) pr_error("Try %s -h for more information.\n", argv[0]); return -1; } - } - if (get_default_event_type() == EVENT_SYNC_CACHE && - get_handler_type() != CTRL_NOHANDLER) - { + + + if ((get_default_event_type() == EVENT_SYNC_CACHE) && + (get_handler_type() != CTRL_NOHANDLER)) { pr_error("Sync caches not available in daemon mode\n"); return -1; } @@ -553,8 +516,8 @@ static int parse_args(int argc, char *argv[]) int sd_notify(int unset_environment, const char *state) { /* Satisfy Compiler for warnings */ - (void) unset_environment; - (void) state; + (void)unset_environment; + (void)state; return 0; } #endif @@ -577,36 +540,29 @@ int main(int argc, char *argv[]) /* Get command line arguments */ if (parse_args(argc, argv) != 0) - { return -1; - } /* all parameter valid, start communication with daemon or setup * communication with control daemon */ - if (get_handler_type() == CTRL_NOHANDLER) - { + if (get_handler_type() == CTRL_NOHANDLER) { pr_verbose("One shot.\n"); ret = dlt_logstorage_ctrl_single_request(); + if (ret < 0) - { pr_error("Message failed to be send. Please check DLT config.\n"); - } } - else - { + else { pr_verbose("Entering in daemon mode.\n"); /* Let's daemonize */ - if (sd_notify(0, "READY=1") <= 0) - { + if (sd_notify(0, "READY=1") <= 0) { pr_verbose("SD notify failed, manually daemonizing.\n"); /* No message can be sent or Systemd is not available. * Daemonizing manually. */ - if (daemon(1, 1)) - { + if (daemon(1, 1)) { pr_error("Failed to daemonize: %s\n", strerror(errno)); return EXIT_FAILURE; } diff --git a/src/console/logstorage/dlt-logstorage-list.c b/src/console/logstorage/dlt-logstorage-list.c index a18fca6..9adda9a 100644 --- a/src/console/logstorage/dlt-logstorage-list.c +++ b/src/console/logstorage/dlt-logstorage-list.c @@ -83,8 +83,7 @@ void print_list() struct LogstorageDeviceInfo *ptr = g_info; pr_verbose(" -------Device list-------\n"); - while (ptr != NULL) - { + while (ptr != NULL) { pr_verbose("%p:\t[%s][%s] \n", ptr, ptr->dev_node, ptr->mnt_point); ptr = ptr->next; } @@ -108,21 +107,16 @@ static struct LogstorageDeviceInfo *logstorage_find_dev_info(const char *node) struct LogstorageDeviceInfo *ptr = g_info; if (!node) - { return NULL; - } pr_verbose("Looking for %s.\n", node); - while (ptr != NULL) - { - if (strncmp(ptr->dev_node, node, DLT_MOUNT_PATH_MAX) == 0) - { + while (ptr != NULL) { + if (strncmp(ptr->dev_node, node, DLT_MOUNT_PATH_MAX) == 0) { pr_verbose("%s found in %p.\n", node, ptr); break; } - else - { + else { ptr = ptr->next; } } @@ -145,14 +139,12 @@ int logstorage_store_dev_info(const char *node, const char *path) struct LogstorageDeviceInfo *ptr = NULL; size_t path_len = 0; - if ((node == NULL) || (path == NULL)) - { + if ((node == NULL) || (path == NULL)) { pr_error("Invalid input\n"); return -1; } - if (logstorage_find_dev_info(node)) - { + if (logstorage_find_dev_info(node)) { pr_verbose("%s already in list.\n", node); print_list(); return 0; @@ -160,22 +152,20 @@ int logstorage_store_dev_info(const char *node, const char *path) ptr = calloc(1, sizeof(struct LogstorageDeviceInfo)); - if (ptr == NULL) - { + if (ptr == NULL) { pr_error("Node creation failed\n"); return -1; } ptr->dev_node = strdup(node); path_len = strlen(path); - if (path_len >DLT_MOUNT_PATH_MAX) - { + + if (path_len > DLT_MOUNT_PATH_MAX) path_len = (size_t)DLT_MOUNT_PATH_MAX; - } + ptr->mnt_point = (char *)calloc(1, path_len + 1); - if (ptr->mnt_point == NULL) - { + if (ptr->mnt_point == NULL) { pr_error("memory allocation failed for mnt_point\n"); return -1; } @@ -187,9 +177,7 @@ int logstorage_store_dev_info(const char *node, const char *path) ptr->next = g_info; if (g_info) - { g_info->prev = ptr; - } g_info = ptr; @@ -216,8 +204,7 @@ char *logstorage_delete_dev_info(const char *node) del = logstorage_find_dev_info(node); - if (del == NULL) - { + if (del == NULL) { pr_verbose("%s not found in list.\n", node); print_list(); return ret; @@ -227,19 +214,13 @@ char *logstorage_delete_dev_info(const char *node) ret = del->mnt_point; if (del->prev) - { del->prev->next = del->next; - } if (del->next) - { del->next->prev = del->prev; - } if (del == g_info) - { g_info = g_info->next; - } free(del->dev_node); free(del); diff --git a/src/console/logstorage/dlt-logstorage-prop.h b/src/console/logstorage/dlt-logstorage-prop.h index 836dc99..13eb57c 100644 --- a/src/console/logstorage/dlt-logstorage-prop.h +++ b/src/console/logstorage/dlt-logstorage-prop.h @@ -27,7 +27,8 @@ * * @return 0 */ -static inline int dlt_logstorage_prop_init(void) { +static inline int dlt_logstorage_prop_init(void) +{ return 0; } @@ -35,7 +36,8 @@ static inline int dlt_logstorage_prop_init(void) { * * @return 0 */ -static inline int dlt_logstorage_prop_deinit(void) { +static inline int dlt_logstorage_prop_deinit(void) +{ return 0; } @@ -43,7 +45,8 @@ static inline int dlt_logstorage_prop_deinit(void) { * * @return 0 */ -static inline int check_proprietary_handling(char *type) { +static inline int check_proprietary_handling(char *type) +{ (void)type; return 0; } #else diff --git a/src/console/logstorage/dlt-logstorage-udev.c b/src/console/logstorage/dlt-logstorage-udev.c index e3584d7..578f1fa 100644 --- a/src/console/logstorage/dlt-logstorage-udev.c +++ b/src/console/logstorage/dlt-logstorage-udev.c @@ -90,42 +90,33 @@ static char *dlt_logstorage_udev_get_mount_point(char *dev_node) char *mnt_point = NULL; if (dev_node == NULL) - { return NULL; - } f = setmntent("/proc/mounts", "r"); - if (f == NULL) - { + if (f == NULL) { pr_error("Cannot read /proc/mounts\n"); return NULL; } while (NULL != (ent = getmntent(f))) - { - if (strncmp(ent->mnt_fsname, dev_node, strlen(ent->mnt_fsname)) == 0) - { + if (strncmp(ent->mnt_fsname, dev_node, strlen(ent->mnt_fsname)) == 0) { mnt_point = strdup(ent->mnt_dir); - if (mnt_point == NULL) - { + if (mnt_point == NULL) { pr_error("Cannot duplicate string.\n"); return NULL; } /* Remounting rw */ if (strlen(mnt_point)) - { /* capabilities needed. Thus we don't really car on failure. * Therefor we can ignore the return value. */ - (void) mount(NULL, mnt_point, NULL, MS_REMOUNT, ent->mnt_opts); - } + (void)mount(NULL, mnt_point, NULL, MS_REMOUNT, ent->mnt_opts); break; } - } endmntent(f); @@ -153,56 +144,47 @@ static int check_mountpoint_from_partition(int event, struct udev_device *part) char *dev_node = NULL; int ret = 0; - if (!part) - { + if (!part) { pr_verbose("No partition structure given.\n"); return -1; } pr_verbose("Checking mount point.\n"); - if (!udev_device_get_devnode(part)) - { + if (!udev_device_get_devnode(part)) { pr_verbose("Skipping as no devnode.\n"); return 0; } dev_node = strdup(udev_device_get_devnode(part)); - if (dev_node == NULL) - { + + if (dev_node == NULL) { pr_error("Cannot allocate memory for to store string\n"); return -1; } - if (event == EVENT_MOUNTED) - { + if (event == EVENT_MOUNTED) { mnt_point = dlt_logstorage_udev_get_mount_point(dev_node); logstorage_dev = dlt_logstorage_check_config_file(mnt_point); - if (logstorage_dev) /* Configuration file available, add node to internal list */ - { + if (logstorage_dev) { /* Configuration file available, add node to internal list */ logstorage_store_dev_info(dev_node, mnt_point); } - else - { + else { free(mnt_point); mnt_point = NULL; } } - else - { + else { /* remove device information */ mnt_point = logstorage_delete_dev_info(dev_node); } - if (mnt_point) - { + if (mnt_point) { ret = dlt_logstorage_send_event(event, mnt_point); if (ret) - { pr_error("Can't send event for %s to DLT.\n", mnt_point); - } } free(dev_node); @@ -226,32 +208,28 @@ static int logstorage_udev_udevd_callback(void) LogstorageCtrlUdev *prvt = NULL; struct udev_device *partition = NULL; - if (!lctrl) - { + if (!lctrl) { pr_error("Not able to get logstorage control instance.\n"); return -1; } prvt = (LogstorageCtrlUdev *)lctrl->prvt; - if ((!prvt) || (!prvt->mon)) - { + if ((!prvt) || (!prvt->mon)) { pr_error("Not able to get private data.\n"); return -1; } partition = udev_monitor_receive_device(prvt->mon); - if (!partition) - { + if (!partition) { pr_error("Not able to get partition.\n"); return -1; } action = udev_device_get_action(partition); - if (!action) - { + if (!action) { pr_error("Not able to get action.\n"); udev_device_unref(partition); return -1; @@ -261,8 +239,7 @@ static int logstorage_udev_udevd_callback(void) action, udev_device_get_devnode(partition)); - if (strncmp(action, "add", sizeof("add")) == 0) - { + if (strncmp(action, "add", sizeof("add")) == 0) { /*TODO: This can be replaced by polling on /proc/mount. * we could get event on modification, and keep track on a list * of mounted devices. New devices could be check that way. @@ -294,8 +271,7 @@ static int logstorage_udev_udevd_callback(void) */ static int dlt_logstorage_udev_check_mounted(struct udev *udev) { - if (udev == NULL) - { + if (udev == NULL) { pr_error("%s: udev structure is NULL\n", __func__); return -1; } @@ -305,8 +281,7 @@ static int dlt_logstorage_udev_check_mounted(struct udev *udev) struct udev_list_entry *devices = NULL; struct udev_list_entry *dev_list_entry = NULL; - if (!enumerate) - { + if (!enumerate) { pr_error("Can't enumerate devices.\n"); return -1; } @@ -330,9 +305,7 @@ static int dlt_logstorage_udev_check_mounted(struct udev *udev) partition = udev_device_new_from_syspath(udev, path); if (!partition) - { continue; - } pr_verbose("Found device %s %s %s.\n", path, @@ -362,26 +335,18 @@ int dlt_logstorage_udev_deinit(void) LogstorageCtrlUdev *prvt = NULL; if (!lctrl) - { return -1; - } prvt = (LogstorageCtrlUdev *)lctrl->prvt; if (prvt == NULL) - { return -1; - } if (prvt->mon) - { udev_monitor_unref(prvt->mon); - } if (prvt->udev) - { udev_unref(prvt->udev); - } free(prvt); lctrl->prvt = NULL; @@ -404,16 +369,14 @@ int dlt_logstorage_udev_init(void) pr_verbose("Initializing.\n"); - if (!lctrl) - { + if (!lctrl) { pr_error("Not able to get logstorage control instance.\n"); return -1; } lctrl->prvt = calloc(1, sizeof(LogstorageCtrlUdev)); - if (!lctrl->prvt) - { + if (!lctrl->prvt) { pr_error("No memory to allocate private data.\n"); return -1; } @@ -423,8 +386,7 @@ int dlt_logstorage_udev_init(void) /* Initialize udev object */ prvt->udev = udev_new(); - if (!prvt->udev) - { + if (!prvt->udev) { pr_error("Cannot initialize udev object\n"); dlt_logstorage_udev_deinit(); return -1; @@ -435,8 +397,7 @@ int dlt_logstorage_udev_init(void) * "add", "remove", "change", etc */ prvt->mon = udev_monitor_new_from_netlink(prvt->udev, "udev"); - if (!prvt->mon) - { + if (!prvt->mon) { pr_error("Cannot initialize udev monitor\n"); dlt_logstorage_udev_deinit(); return -1; @@ -446,8 +407,7 @@ int dlt_logstorage_udev_init(void) "block", NULL); - if (ret) - { + if (ret) { pr_error("Cannot attach filter to monitor: %s.\n", strerror(-ret)); dlt_logstorage_udev_deinit(); return -1; @@ -455,8 +415,7 @@ int dlt_logstorage_udev_init(void) ret = udev_monitor_enable_receiving(prvt->mon); - if (ret < 0) - { + if (ret < 0) { pr_error("Cannot start receiving: %s.\n", strerror(-ret)); dlt_logstorage_udev_deinit(); return -1; -- cgit v1.2.1