From e8120186b8ffdbd705d94737c874a6230afdaa2b Mon Sep 17 00:00:00 2001 From: Lassi Marttala Date: Mon, 7 May 2012 15:36:31 +0200 Subject: [D4099]: Integrated fix from Alexander Wenzel. This will check for duplicate file handles, and clean them up if found. Signed-off-by: Christian Muck --- src/daemon/dlt_daemon_common.c | 51 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) mode change 100755 => 100644 src/daemon/dlt_daemon_common.c (limited to 'src/daemon/dlt_daemon_common.c') diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c old mode 100755 new mode 100644 index 99bbabe..3bf940e --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -208,6 +208,28 @@ int dlt_daemon_free(DltDaemon *daemon,int verbose) return 0; } +int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon,int fd,int verbose) +{ + int i; + + PRINT_FUNCTION_VERBOSE(verbose); + + if (daemon==0) + { + return -1; + } + + for (i=0; inum_applications; i++) + { + if (daemon->applications[i].user_handle==fd) + { + daemon->applications[i].user_handle = 0; + } + } + + return 0; +} + int dlt_daemon_applications_clear(DltDaemon *daemon,int verbose) { int i; @@ -349,6 +371,11 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pi dlt_log(LOG_ERR, str); } /* if */ + /* check if file file descriptor was already used, and make it invalid if it is reused */ + /* This prevents sending messages to wrong file descriptor */ + dlt_daemon_applications_invalidate_fd(daemon,dlt_user_handle,verbose); + dlt_daemon_contexts_invalidate_fd(daemon,dlt_user_handle,verbose); + application->user_handle = dlt_user_handle; } @@ -600,7 +627,7 @@ DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon,char *apid,char *ctid if (context->context_description) { free(context->context_description); - context->context_description=0; // opt mb: moved inside the if clause (very minor opt) + context->context_description=0; } if (description) @@ -707,6 +734,28 @@ DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,char *apid,char *cti return (DltDaemonContext*)bsearch(&context,daemon->contexts,daemon->num_contexts,sizeof(DltDaemonContext),dlt_daemon_cmp_apid_ctid); } +int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon,int fd,int verbose) +{ + int i; + + PRINT_FUNCTION_VERBOSE(verbose); + + if (daemon==0) + { + return -1; + } + + for (i=0; inum_contexts; i++) + { + if (daemon->contexts[i].user_handle==fd) + { + daemon->contexts[i].user_handle = 0; + } + } + + return 0; +} + int dlt_daemon_contexts_clear(DltDaemon *daemon,int verbose) { int i; -- cgit v1.2.1