summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVo Trung Chi <Chi.VoTrung@vn.bosch.com>2019-05-15 16:16:30 +0700
committerSaya Sugiura <ssugiura@jp.adit-jv.com>2019-06-18 17:22:09 +0900
commitc6be4affa0b817437e5c11ced065195459818be3 (patch)
tree6cc1b30e8c61fb7dc01634e22120054640a242fa
parent3580c5640c5578f508e93a8a851231b389d327cd (diff)
downloadDLT-daemon-c6be4affa0b817437e5c11ced065195459818be3.tar.gz
daemon: Loop for client fds
In dlt_daemon_client_send_all_multiple(), while in the loop, the connection to client may be destroyed by recursive call to dlt_daemon_close_socket(). So in some scenario we still use the removed connection, which is unexpected behavior. Solution: loop on the fds array and find the client connection corresponds to. Signed-off-by: Vo Trung Chi <Chi.VoTrung@vn.bosch.com>
-rw-r--r--src/daemon/dlt_daemon_client.c28
-rw-r--r--src/daemon/dlt_daemon_connection.c3
-rw-r--r--src/daemon/dlt_daemon_event_handler.c9
3 files changed, 21 insertions, 19 deletions
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index d8062d5..fd2bde4 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -64,6 +64,7 @@
#include "dlt_daemon_client.h"
#include "dlt_daemon_connection.h"
+#include "dlt_daemon_event_handler.h"
#include "dlt_daemon_offline_logstorage.h"
#include "dlt_gateway.h"
@@ -109,27 +110,32 @@ static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon,
int size2,
int verbose)
{
- int j, sent = 0;
+ int sent = 0;
+ unsigned int i = 0;
+ int ret = 0;
DltConnection *temp = NULL;
int type_mask =
(DLT_CON_MASK_CLIENT_MSG_TCP | DLT_CON_MASK_CLIENT_MSG_SERIAL);
+ PRINT_FUNCTION_VERBOSE(verbose);
+
if ((daemon == NULL) || (daemon_local == NULL)) {
dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
return 0;
}
- temp = daemon_local->pEvent.connections;
- temp = dlt_connection_get_next(temp, type_mask);
+ for (i = 0; i < daemon_local->pEvent.nfds; i++)
+ {
+ temp = dlt_event_handler_find_connection(&(daemon_local->pEvent),
+ daemon_local->pEvent.pfd[i].fd);
+
+ if ((temp == NULL) || (temp->receiver == NULL) ||
+ !((1 << temp->type) & type_mask)) {
+ dlt_vlog(LOG_DEBUG, "The connection not found or the connection type not TCP/Serial.\n");
+ continue;
+ }
- /* FIXME: the lock shall include the for loop as data
- * can be affect between each iteration, but
- * dlt_daemon_close_socket may call us too ...
- */
- for (j = 0; ((j < daemon_local->client_connections) && (temp != NULL)); j++) {
- int ret = 0;
DLT_DAEMON_SEM_LOCK();
- DltConnection *next = dlt_connection_get_next(temp->next, type_mask);
ret = dlt_connection_send_multiple(temp,
data1,
@@ -154,8 +160,6 @@ static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon,
* then do not store in ring buffer
*/
sent = 1;
-
- temp = next;
} /* for */
return sent;
diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c
index 456a075..b1a4080 100644
--- a/src/daemon/dlt_daemon_connection.c
+++ b/src/daemon/dlt_daemon_connection.c
@@ -340,9 +340,6 @@ void dlt_connection_destroy(DltConnection *to_destroy)
to_destroy->id = 0;
close(to_destroy->receiver->fd);
dlt_connection_destroy_receiver(to_destroy);
- /* connection pointer might be in poll queue and used even after destroying
- * it. To make sure it is not used anymore, connection type is invalidated */
- to_destroy->type = DLT_CONNECTION_TYPE_MAX;
free(to_destroy);
}
diff --git a/src/daemon/dlt_daemon_event_handler.c b/src/daemon/dlt_daemon_event_handler.c
index 895a896..38aa022 100644
--- a/src/daemon/dlt_daemon_event_handler.c
+++ b/src/daemon/dlt_daemon_event_handler.c
@@ -285,14 +285,15 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent,
*
* @return The found connection pointer, NULL otherwise.
*/
-DltConnection *dlt_event_handler_find_connection(DltEventHandler *ev,
- int fd)
+DltConnection *dlt_event_handler_find_connection(DltEventHandler *ev, int fd)
{
-
DltConnection *temp = ev->connections;
- while ((temp != NULL) && (temp->receiver->fd != fd))
+ while (temp != NULL) {
+ if ((temp->receiver != NULL) && (temp->receiver->fd == fd))
+ return temp;
temp = temp->next;
+ }
return temp;
}