summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Herrmann <fherrmann@de.adit-jv.com>2020-06-03 16:46:40 +0200
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2020-07-06 10:04:07 +0900
commitb185489eb4445bd1d5bca1f82c8e52af258ee69a (patch)
tree385c84272cc0452266f300722385bd3d96d2a224
parent06b71ade4ad5f988ef18dcbec1e5e28b0ce57166 (diff)
downloadDLT-daemon-b185489eb4445bd1d5bca1f82c8e52af258ee69a.tar.gz
limit logspam in gateway on client overflow
update client buffer overflow counter in send function. Gather all overflow checks into dlt_daemon_client. Signed-off-by: Felix Herrmann <fherrmann@de.adit-jv.com> Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
-rw-r--r--src/daemon/dlt-daemon.c30
-rw-r--r--src/daemon/dlt_daemon_client.c62
-rw-r--r--src/gateway/dlt_gateway.c8
3 files changed, 39 insertions, 61 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 7abd4d5..cb9b7f0 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -1636,7 +1636,6 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, cha
uint32_t uiType;
uint16_t uiSize;
uint32_t uiExtraSize;
- int ret;
PRINT_FUNCTION_VERBOSE(verbose);
@@ -1692,20 +1691,14 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, cha
memcpy((uint8_t *)(msg.databuffer + msg.datasize), str, uiSize);
msg.datasize += uiSize;
- /* Calc lengths */
+ /* Calc length */
msg.standardheader->len = DLT_HTOBE_16(msg.headersize - sizeof(DltStorageHeader) + msg.datasize);
- /* Sending data... */
- {
- ret = dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local,
- msg.headerbuffer, sizeof(DltStorageHeader),
- msg.headerbuffer + sizeof(DltStorageHeader),
- msg.headersize - sizeof(DltStorageHeader),
- msg.databuffer, msg.datasize, verbose);
-
- if (ret == DLT_DAEMON_ERROR_BUFFER_FULL)
- daemon->overflow_counter++;
- }
+ dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local,
+ msg.headerbuffer, sizeof(DltStorageHeader),
+ msg.headerbuffer + sizeof(DltStorageHeader),
+ msg.headersize - sizeof(DltStorageHeader),
+ msg.databuffer, msg.datasize, verbose);
free(msg.databuffer);
@@ -2869,16 +2862,7 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon,
return DLT_DAEMON_ERROR_UNKNOWN;
}
- ret = dlt_daemon_client_send_message_to_all_client(daemon,
- daemon_local, verbose);
-
- if (ret == DLT_DAEMON_ERROR_BUFFER_FULL && daemon->overflow_counter == 1) {
- dlt_vlog(LOG_WARNING, "%s: buffer full, messages will be discarded.\n",
- __func__);
- } else if (ret != DLT_DAEMON_ERROR_OK &&
- ret != DLT_DAEMON_ERROR_BUFFER_FULL) {
- dlt_vlog(LOG_ERR, "%s: failed to send message to client\n", __func__);
- }
+ dlt_daemon_client_send_message_to_all_client(daemon, daemon_local, verbose);
/* keep not read data in buffer */
size = daemon_local->msg.headersize +
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index 3560910..9450e77 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -187,7 +187,7 @@ int dlt_daemon_client_send(int sock,
if ((ret = dlt_daemon_serial_send(sock, data1, size1, data2, size2, daemon->sendserialheader))) {
DLT_DAEMON_SEM_FREE();
- dlt_log(LOG_WARNING, "dlt_daemon_client_send: serial send dlt message failed\n");
+ dlt_vlog(LOG_WARNING, "%s: serial send dlt message failed\n", __func__);
return ret;
}
@@ -198,7 +198,7 @@ int dlt_daemon_client_send(int sock,
if ((ret = dlt_daemon_socket_send(sock, data1, size1, data2, size2, daemon->sendserialheader))) {
DLT_DAEMON_SEM_FREE();
- dlt_log(LOG_WARNING, "dlt_daemon_client_send: socket send dlt message failed\n");
+ dlt_vlog(LOG_WARNING, "%s: socket send dlt message failed\n", __func__);
return ret;
}
@@ -220,7 +220,7 @@ int dlt_daemon_client_send(int sock,
static int error_dlt_offline_trace_write_failed = 0;
if (!error_dlt_offline_trace_write_failed) {
- dlt_log(LOG_ERR, "dlt_daemon_client_send: dlt_offline_trace_write failed!\n");
+ dlt_vlog(LOG_ERR, "%s: dlt_offline_trace_write failed!\n", __func__);
error_dlt_offline_trace_write_failed = 1;
}
@@ -273,20 +273,31 @@ int dlt_daemon_client_send(int sock,
if ((sock != DLT_DAEMON_SEND_FORCE) &&
((daemon->state == DLT_DAEMON_STATE_BUFFER) || (daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) ||
(daemon->state == DLT_DAEMON_STATE_BUFFER_FULL))) {
- if (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL)
- return DLT_DAEMON_ERROR_BUFFER_FULL;
+ if (daemon->state != DLT_DAEMON_STATE_BUFFER_FULL) {
+ DLT_DAEMON_SEM_LOCK();
+ /* Store message in history buffer */
+ ret = dlt_buffer_push3(&(daemon->client_ringbuffer), data1, size1, data2, size2, 0, 0);
+ DLT_DAEMON_SEM_FREE();
- DLT_DAEMON_SEM_LOCK();
+ if (ret < DLT_RETURN_OK) {
+ dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_BUFFER_FULL);
+ }
+ }
+ if (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL) {
+ daemon->overflow_counter += 1;
+ if (daemon->overflow_counter == 1)
+ dlt_vlog(LOG_INFO, "%s: Buffer is full! Messages will be discarded.\n", __func__);
- /* Store message in history buffer */
- if (dlt_buffer_push3(&(daemon->client_ringbuffer), data1, size1, data2, size2, 0, 0) < DLT_RETURN_OK) {
- DLT_DAEMON_SEM_FREE();
- dlt_log(LOG_DEBUG, "dlt_daemon_client_send: Buffer is full! Message discarded.\n");
- dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_BUFFER_FULL);
return DLT_DAEMON_ERROR_BUFFER_FULL;
}
-
- DLT_DAEMON_SEM_FREE();
+ } else {
+ if ((daemon->overflow_counter > 0) &&
+ (daemon_local->client_connections > 0) &&
+ (dlt_daemon_send_message_overflow(daemon, daemon_local, verbose) == DLT_DAEMON_ERROR_OK)) {
+ dlt_vlog(LOG_WARNING, "%s: %u messages discarded! Now able to send messages to the client.\n",
+ __func__, daemon->overflow_counter);
+ daemon->overflow_counter = 0;
+ }
}
return DLT_DAEMON_ERROR_OK;
@@ -297,7 +308,6 @@ int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
int verbose)
{
- int ret = DLT_DAEMON_ERROR_OK;
static char text[DLT_DAEMON_TEXTSIZE];
char * ecu_ptr = NULL;
@@ -359,27 +369,13 @@ int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon,
dlt_log(LOG_WARNING, "dlt_message_print_header() failed!\n");
}
- /* check if overflow occurred */
- if (daemon->overflow_counter == 1) {
- ret = dlt_daemon_send_message_overflow(daemon, daemon_local, verbose);
- if (DLT_DAEMON_ERROR_OK == ret) {
- dlt_vlog(LOG_WARNING, "%s: %u messages discarded! Now able to send messages to the client.\n",
- __func__, daemon->overflow_counter);
- daemon->overflow_counter = 0;
- }
- }
-
/* send message to client or write to log file */
- ret = dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local,
- daemon_local->msg.headerbuffer, sizeof(DltStorageHeader),
- daemon_local->msg.headerbuffer + sizeof(DltStorageHeader),
- daemon_local->msg.headersize - sizeof(DltStorageHeader),
- daemon_local->msg.databuffer, daemon_local->msg.datasize, verbose);
-
- if (ret == DLT_DAEMON_ERROR_BUFFER_FULL)
- daemon->overflow_counter++;
+ return dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local,
+ daemon_local->msg.headerbuffer, sizeof(DltStorageHeader),
+ daemon_local->msg.headerbuffer + sizeof(DltStorageHeader),
+ daemon_local->msg.headersize - sizeof(DltStorageHeader),
+ daemon_local->msg.databuffer, daemon_local->msg.datasize, verbose);
- return ret;
}
int dlt_daemon_client_send_control_message(int sock,
diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c
index 7cad893..9c6578f 100644
--- a/src/gateway/dlt_gateway.c
+++ b/src/gateway/dlt_gateway.c
@@ -1416,7 +1416,7 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
return DLT_RETURN_ERROR;
}
- if (dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL,
+ dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL,
daemon,
daemon_local,
msg.headerbuffer,
@@ -1425,10 +1425,8 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
msg.headersize - sizeof(DltStorageHeader),
msg.databuffer,
msg.datasize,
- verbose) != DLT_DAEMON_ERROR_OK)
- dlt_log(LOG_WARNING, "Forward message to clients failed!\n");
- }
- else { /* otherwise remove this connection and do not connect again */
+ verbose);
+ } else { /* otherwise remove this connection and do not connect again */
dlt_vlog(LOG_WARNING,
"Received ECUid (%s) differs to configured ECUid(%s). "
"Discard this message.\n",