summaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon')
-rwxr-xr-xsrc/daemon/dlt-daemon.c80
-rwxr-xr-xsrc/daemon/dlt-daemon.h1
-rwxr-xr-xsrc/daemon/dlt_daemon_common.c105
-rwxr-xr-xsrc/daemon/dlt_daemon_common.h20
-rwxr-xr-xsrc/daemon/dlt_daemon_common_cfg.h2
5 files changed, 182 insertions, 26 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 7dcf025..86315c6 100755
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -464,7 +464,7 @@ int main(int argc, char* argv[])
{
if (FD_ISSET(i, &(daemon_local.read_fds)))
{
- if (i == daemon_local.sock)
+ if (i == daemon_local.sock && ((daemon.mode == DLT_USER_MODE_EXTERNAL) || (daemon.mode == DLT_USER_MODE_BOTH)))
{
/* event from TCP server socket, new connection */
if (dlt_daemon_process_client_connect(&daemon, &daemon_local, daemon_local.flags.vflag)==-1)
@@ -562,7 +562,7 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
} /* if */
#endif
/* init offline trace */
- if(daemon_local->flags.offlineTraceDirectory[0])
+ if(((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && daemon_local->flags.offlineTraceDirectory[0])
{
if (dlt_offline_trace_init(&(daemon_local->offlineTrace),daemon_local->flags.offlineTraceDirectory,daemon_local->flags.offlineTraceFileSize,daemon_local->flags.offlineTraceMaxSize)==-1)
{
@@ -1234,6 +1234,7 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_l
break;
}
case DLT_USER_MESSAGE_LOG:
+ case DLT_USER_MESSAGE_LOG_SHM:
{
if (dlt_daemon_process_user_message_log(daemon, daemon_local, daemon_local->flags.vflag)==-1)
{
@@ -1265,6 +1266,14 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_l
}
break;
}
+ case DLT_USER_MESSAGE_LOG_MODE:
+ {
+ if (dlt_daemon_process_user_message_log_mode(daemon, daemon_local, daemon_local->flags.vflag)==-1)
+ {
+ run_loop=0;
+ }
+ break;
+ }
default:
{
dlt_log(LOG_ERR,"(Internal) Invalid user message type received!\n");
@@ -1770,26 +1779,11 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
}
/* print message header only */
} /* if */
-
-#if 0
- /* if file output enabled write message */
- if (daemon_local->flags.ovalue[0])
- {
- /* write message to output buffer */
- if (dlt_user_log_out2(daemon_local->ohandle,
- daemon_local->msg.headerbuffer,
- daemon_local->msg.headersize,
- daemon_local->msg.databuffer,
- daemon_local->msg.datasize) !=DLT_RETURN_OK)
- {
- dlt_log(LOG_ERR,"Writing to output file failed!\n");
- }
- } /* if */
-#endif
+
sent=0;
/* write message to offline trace */
- if(daemon_local->flags.offlineTraceDirectory[0])
+ if(((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && daemon_local->flags.offlineTraceDirectory[0])
{
dlt_offline_trace_write(&(daemon_local->offlineTrace),daemon_local->msg.headerbuffer,daemon_local->msg.headersize,
daemon_local->msg.databuffer,daemon_local->msg.datasize,0,0);
@@ -1797,7 +1791,7 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
}
/* look if TCP connection to client is available */
- for (j = 0; j <= daemon_local->fdmax; j++)
+ for (j = 0;((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && (j <= daemon_local->fdmax); j++)
{
/* send to everyone! */
if (FD_ISSET(j, &(daemon_local->master)))
@@ -1848,16 +1842,16 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
} /* for */
/* Message was not sent to client, so store it in client ringbuffer */
- if (sent==0)
+ if (sent==1 || (daemon->mode == DLT_USER_MODE_OFF))
{
- /* dlt message was not sent, keep in buffer */
- break;
+ /* dlt message was sent, remove from buffer */
+ dlt_shm_remove(&(daemon_local->dlt_shm));
}
else
{
- /* dlt message was sent, remove from buffer */
- dlt_shm_remove(&(daemon_local->dlt_shm));
+ /* dlt message was not sent, keep in buffer */
+ break;
}
}
@@ -1948,6 +1942,42 @@ int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, DltDaemonLo
return 0;
}
+int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
+{
+ DltUserControlMsgLogMode *logmode;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon==0) || (daemon_local==0))
+ {
+ dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_log_mode()\n");
+ return -1;
+ }
+
+ if (daemon_local->receiver.bytesRcvd < (sizeof(DltUserHeader)+sizeof(DltUserControlMsgUnregisterContext)))
+ {
+ /* Not enough bytes received */
+ return -1;
+ }
+
+ logmode = (DltUserControlMsgLogMode*) (daemon_local->receiver.buf+sizeof(DltUserHeader));
+
+ /* set the new log mode */
+ daemon->mode = logmode->log_mode;
+
+ /* write configuration persistantly */
+ dlt_daemon_configuration_save(daemon, daemon->runtime_configuration, verbose);
+
+ /* keep not read data in buffer */
+ if (dlt_receiver_remove(&(daemon_local->receiver),sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogMode))==-1)
+ {
+ dlt_log(LOG_ERR,"Can't remove bytes from receiver for user message log mode\n");
+ return -1;
+ }
+
+ return 0;
+}
+
void dlt_daemon_timingpacket_thread(void *ptr)
{
DltDaemonPeriodicData info;
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index 4c8f121..9d71a6e 100755
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -169,6 +169,7 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, DltDaemo
int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
+int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
void dlt_daemon_timingpacket_thread(void *ptr);
int dlt_daemon_make_periodic (unsigned int period, DltDaemonPeriodicData *info, int verbose);
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 003dc33..e10b20d 100755
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -152,6 +152,8 @@ int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory, int verbose
daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
daemon->runtime_context_cfg_loaded = 0;
+
+ daemon->mode = DLT_USER_MODE_EXTERNAL;
/* prepare filenames for configuration */
if(runtime_directory[0])
@@ -164,6 +166,11 @@ int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory, int verbose
else
strcpy(daemon->runtime_context_cfg,DLT_RUNTIME_DEFAULT_DIRECTORY);
strcat(daemon->runtime_context_cfg,DLT_RUNTIME_CONTEXT_CFG);
+ if(runtime_directory[0])
+ strcpy(daemon->runtime_configuration,runtime_directory);
+ else
+ strcpy(daemon->runtime_configuration,DLT_RUNTIME_DEFAULT_DIRECTORY);
+ strcat(daemon->runtime_configuration,DLT_RUNTIME_CONFIGURATION);
/* Check for runtime cfg, if it is loadable, load it! */
if ((dlt_daemon_applications_load(daemon,daemon->runtime_application_cfg, verbose)==0) &&
@@ -171,7 +178,10 @@ int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory, int verbose
{
daemon->runtime_context_cfg_loaded = 1;
}
-
+
+ /* load configuration if available */
+ dlt_daemon_configuration_load(daemon,daemon->runtime_configuration, verbose);
+
daemon->sendserialheader = 0;
daemon->timingpackets = 0;
@@ -827,6 +837,99 @@ int dlt_daemon_contexts_save(DltDaemon *daemon,const char *filename, int verbose
return 0;
}
+int dlt_daemon_configuration_save(DltDaemon *daemon,const char *filename, int verbose)
+{
+ FILE *fd;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon==0) || (filename==0) ||( filename[0]=='\0'))
+ {
+ return -1;
+ }
+
+ fd=fopen(filename, "w");
+ if (fd!=0)
+ {
+ fprintf(fd,"# 0 = off, 1 = external, 2 = internal, 3 = both\n");
+ fprintf(fd,"LoggingMode = %d\n",daemon->mode);
+
+ fclose(fd);
+ }
+
+ return 0;
+}
+
+int dlt_daemon_configuration_load(DltDaemon *daemon,const char *filename, int verbose)
+{
+ FILE * pFile;
+ char line[1024];
+ char token[1024];
+ char value[1024];
+ char *pch;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ pFile = fopen (filename,"r");
+
+ if (pFile!=NULL)
+ {
+ while(1)
+ {
+ /* fetch line from configuration file */
+ if ( fgets (line , 1024 , pFile) != NULL )
+ {
+ pch = strtok (line," =\r\n");
+ token[0]=0;
+ value[0]=0;
+
+ while (pch != NULL)
+ {
+ if(strcmp(pch,"#")==0)
+ break;
+
+ if(token[0]==0)
+ {
+ strncpy(token,pch,sizeof(token));
+ }
+ else
+ {
+ strncpy(value,pch,sizeof(value));
+ break;
+ }
+
+ pch = strtok (NULL, " =\r\n");
+ }
+
+ if(token[0] && value[0])
+ {
+ /* parse arguments here */
+ if(strcmp(token,"LoggingMode")==0)
+ {
+ daemon->mode = atoi(value);
+ printf("Option: %s=%s\n",token,value);
+ }
+ else
+ {
+ fprintf(stderr, "Unknown option: %s=%s\n",token,value);
+ }
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ fclose (pFile);
+ }
+ else
+ {
+ fprintf(stderr, "Cannot open configuration file: %s\n",filename);
+ }
+
+ return 0;
+}
+
int dlt_daemon_user_send_log_level(DltDaemon *daemon,DltDaemonContext *context,int verbose)
{
DltUserHeader userheader;
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index bdacfd7..1fd3d2e 100755
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -90,6 +90,7 @@
#include <semaphore.h>
#include "dlt_common.h"
+#include "dlt_user.h"
#ifdef __cplusplus
extern "C" {
@@ -150,6 +151,8 @@ typedef struct
int timingpackets; /**< 1: send continous timing packets; 0 don't send continous timing packets */
char runtime_application_cfg[256]; /**< Path and filename of persistent application configuration */
char runtime_context_cfg[256]; /**< Path and filename of persistent context configuration */
+ char runtime_configuration[256]; /**< Path and filename of persistent configuration */
+ DltUserLogMode mode; /**< Mode used for tracing: off, external, internal, both */
} DltDaemon;
/**
@@ -273,6 +276,23 @@ int dlt_daemon_contexts_load(DltDaemon *daemon,const char *filename, int verbose
* @return negative value if there was an error
*/
int dlt_daemon_contexts_save(DltDaemon *daemon,const char *filename, int verbose);
+/**
+ * Load persistant configuration
+ * @param daemon pointer to dlt daemon structure
+ * @param filename name of file to be used for loading
+ * @param verbose if set to true verbose information is printed out.
+ * @return negative value if there was an error
+ */
+int dlt_daemon_configuration_load(DltDaemon *daemon,const char *filename, int verbose);
+/**
+ * Save configuration persistantly
+ * @param daemon pointer to dlt daemon structure
+ * @param filename name of file to be used for saving
+ * @param verbose if set to true verbose information is printed out.
+ * @return negative value if there was an error
+ */
+int dlt_daemon_configuration_save(DltDaemon *daemon,const char *filename, int verbose);
+
/**
* Send user message DLT_USER_MESSAGE_LOG_LEVEL to user application
diff --git a/src/daemon/dlt_daemon_common_cfg.h b/src/daemon/dlt_daemon_common_cfg.h
index 0d076fe..9248bfb 100755
--- a/src/daemon/dlt_daemon_common_cfg.h
+++ b/src/daemon/dlt_daemon_common_cfg.h
@@ -90,6 +90,8 @@
#define DLT_RUNTIME_APPLICATION_CFG "/dlt-runtime-application.cfg"
/* Path and filename for runtime configuration (contexts) */
#define DLT_RUNTIME_CONTEXT_CFG "/dlt-runtime-context.cfg"
+/* Path and filename for runtime configuration */
+#define DLT_RUNTIME_CONFIGURATION "/dlt-runtime.cfg"
/* Size of text buffer */
#define DLT_DAEMON_TEXTBUFSIZE 255