summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralex <alex@alexpc.(none)>2011-11-04 23:11:37 +0100
committeralex <alex@alexpc.(none)>2011-11-04 23:11:37 +0100
commit41f53b3fa901479bee58cbae07bc5f9693a02058 (patch)
treeed0106a7ce8a3dc3f7aaff33ccb350f8f4938e89 /src
parentd38e570dcb3d8581fe399c569f30e39d683ef5ac (diff)
downloadDLT-daemon-41f53b3fa901479bee58cbae07bc5f9693a02058.tar.gz
Fixed shared memory problem in DLT library during startup, if application is started before daemon.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/lib/dlt_user.c33
-rw-r--r--src/shared/dlt_shm.c3
2 files changed, 26 insertions, 10 deletions
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 58032f5..bdb9efe 100755
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -159,14 +159,7 @@ int dlt_init(void)
dlt_user.dlt_is_file = 0;
dlt_user.overflow = 0;
-
- /* init shared memory */
- if (dlt_shm_init_client(&dlt_user.dlt_shm,DLT_SHM_KEY) < 0)
- {
- sprintf(str,"Loging disabled, Shared memory %d cannot be created!\n",DLT_SHM_KEY);
- dlt_log(LOG_WARNING, str);
- return 0;
- }
+ memset(&(dlt_user.dlt_shm),0,sizeof(DltShm));
/* create and open DLT user FIFO */
sprintf(filename,"%s/dlt%d",DLT_USER_DIR,getpid());
@@ -197,8 +190,19 @@ int dlt_init(void)
{
sprintf(str,"Loging disabled, FIFO %s cannot be opened with open()!\n",DLT_USER_FIFO);
dlt_log(LOG_WARNING, str);
- return 0;
+ //return 0;
}
+ else
+ {
+ /* init shared memory */
+ if (dlt_shm_init_client(&(dlt_user.dlt_shm),DLT_SHM_KEY) < 0)
+ {
+ sprintf(str,"Loging disabled, Shared memory %d cannot be created!\n",DLT_SHM_KEY);
+ dlt_log(LOG_WARNING, str);
+ //return 0;
+ }
+ }
+
if (dlt_receiver_init(&(dlt_user.receiver),dlt_user.dlt_user_handle, DLT_USER_RCVBUF_MAX_SIZE)==-1)
{
@@ -2217,6 +2221,9 @@ int dlt_user_log_send_log(DltContextData *log, int mtype)
close(dlt_user.dlt_log_handle);
dlt_user.dlt_log_handle = -1;
+ /* free shared memory */
+ dlt_shm_free_client(&dlt_user.dlt_shm);
+
if (dlt_user.local_print_mode == DLT_PM_AUTOMATIC)
{
dlt_user_print_msg(&msg, log);
@@ -2763,6 +2770,14 @@ void dlt_user_log_reattach_to_daemon(void)
return;
}
+ /* init shared memory */
+ if (dlt_shm_init_client(&dlt_user.dlt_shm,DLT_SHM_KEY) < 0)
+ {
+ sprintf(str,"Loging disabled, Shared memory %d cannot be created!\n",DLT_SHM_KEY);
+ dlt_log(LOG_WARNING, str);
+ //return 0;
+ }
+
dlt_log(LOG_NOTICE, "Logging re-enabled!\n");
/* Re-register application */
diff --git a/src/shared/dlt_shm.c b/src/shared/dlt_shm.c
index 33c43e0..9d33fe6 100644
--- a/src/shared/dlt_shm.c
+++ b/src/shared/dlt_shm.c
@@ -74,6 +74,7 @@
#include <string.h>
#include <dlt_shm.h>
+#include <dlt_common.h>
void dlt_shm_print_hex(char *ptr,int size)
{
@@ -266,7 +267,7 @@ int dlt_shm_push(DltShm *buf,const unsigned char *data1,unsigned int size1,const
if(!buf->mem) {
// shm not initialised
- printf("SHM: SHM not initialised\n");
+ //printf("SHM: SHM not initialised\n");
return -1; /* ERROR */
}