summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--[-rwxr-xr-x]src/daemon/dlt-daemon.c8
-rw-r--r--[-rwxr-xr-x]src/daemon/dlt_daemon_common.c51
-rw-r--r--[-rwxr-xr-x]src/daemon/dlt_daemon_common.h16
3 files changed, 73 insertions, 2 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 04612bb..69e4072 100755..100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -210,7 +210,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.offlineTraceMaxSize = 0;
daemon_local->flags.loggingMode = 0;
daemon_local->flags.loggingLevel = 6;
- strncpy(daemon_local->flags.loggingFilename,"/tmp/dlt.log",sizeof(daemon_local->flags.loggingFilename));
+ strncpy(daemon_local->flags.loggingFilename, DLT_USER_DIR "/dlt.log",sizeof(daemon_local->flags.loggingFilename));
/* open configuration file */
if(daemon_local->flags.cvalue[0])
@@ -974,6 +974,12 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_
dlt_log(LOG_ERR, "accept() failed!\n");
return -1 ;
}
+
+ /* 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,in_sock,verbose);
+ dlt_daemon_contexts_invalidate_fd(daemon,in_sock,verbose);
+
//sprintf("str,"Client Connection from %s\n", inet_ntoa(cli.sin_addr));
//dlt_log(str);
FD_SET(in_sock, &(daemon_local->master)); /* add to master set */
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 99bbabe..3bf940e 100755..100644
--- 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; i<daemon->num_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; i<daemon->num_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;
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index 9bbe3c7..48c8868 100755..100644
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -204,6 +204,14 @@ int dlt_daemon_applications_load(DltDaemon *daemon,const char *filename, int ver
*/
int dlt_daemon_applications_save(DltDaemon *daemon,const char *filename, int verbose);
/**
+ * Invalidate all applications fd, if fd is reused
+ * @param daemon pointer to dlt daemon structure
+ * @param fd file descriptor
+ * @param verbose if set to true verbose information is printed out.
+ * @return negative value if there was an error
+ */
+int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon,int fd,int verbose);
+/**
* Clear all applications in internal application management
* @param daemon pointer to dlt daemon structure
* @param verbose if set to true verbose information is printed out.
@@ -243,6 +251,14 @@ int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int ver
*/
DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,char *apid,char *ctid,int verbose);
/**
+ * Invalidate all contexts fd, if fd is reused
+ * @param daemon pointer to dlt daemon structure
+ * @param fd file descriptor
+ * @param verbose if set to true verbose information is printed out.
+ * @return negative value if there was an error
+ */
+int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon,int fd,int verbose);
+/**
* Clear all contexts in internal context management
* @param daemon pointer to dlt daemon structure
* @param verbose if set to true verbose information is printed out.