summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLutz Helwing <lutz_helwing@mentor.com>2015-09-22 10:49:29 +0200
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2015-10-07 10:37:19 +0200
commit4c8d43322e89b87288fb5ba12e523237e620481b (patch)
tree202bc05d45f14f7f30dd3826362811d3ce8840fd /src
parente5ffa017047525ed2e3ee41ea2294546ee64894c (diff)
downloadDLT-daemon-4c8d43322e89b87288fb5ba12e523237e620481b.tar.gz
Fixed whitespace and formatting of new code Fixed licence headers
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Diffstat (limited to 'src')
-rw-r--r--src/console/dlt-logstorage-ctrl.c28
-rw-r--r--src/console/dlt-receive.c16
-rw-r--r--src/examples/dlt-example-user.c2
-rw-r--r--src/lib/dlt_env_ll.c28
-rw-r--r--src/lib/dlt_user.c258
-rw-r--r--src/tests/dlt-test-fork-handler.c90
6 files changed, 232 insertions, 190 deletions
diff --git a/src/console/dlt-logstorage-ctrl.c b/src/console/dlt-logstorage-ctrl.c
index 4e34c6f..24742f0 100644
--- a/src/console/dlt-logstorage-ctrl.c
+++ b/src/console/dlt-logstorage-ctrl.c
@@ -1,25 +1,31 @@
-/**
+/*
* @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
* Copyright (C) 2013 - 2015 Advanced Driver Information Technology.
* This code is developed by Advanced Driver Information Technology.
- * Copyright of Advanced Driver Information Technology, Bosch and DENSO.
- *
- * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
+ * Copyright of Advanced Driver Information Technology, Bosch and DENSO
*
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
*
- * \copyright
* This Source Code Form is subject to the terms of the
- * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
- * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
*
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
* \author Syed Hameed <shameed@jp.adit-jv.com> ADIT 2013 - 2015
* \author Christoph Lipka <clipka@jp.adit-jv.com> ADIT 2015
*
+ * \copyright Copyright © 2013-2015 Advanced Driver Information Technology. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
* \file dlt-logstorage-ctrl.c
- * For further information see http://www.genivi.org/.
- * @licence end@
- */
+*/
/*******************************************************************************
** **
diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c
index 071c1ba..99268e5 100644
--- a/src/console/dlt-receive.c
+++ b/src/console/dlt-receive.c
@@ -493,14 +493,14 @@ int main(int argc, char* argv[])
{
if (dltdata.climit > -1)
{
- char tmp[256];
- snprintf(tmp, 256, "Using file size limit of %li bytes\n", dltdata.climit);
- dlt_log(LOG_INFO, tmp);
- dltdata.ohandle = dlt_receive_open_output_file(&dltdata);
+ char tmp[256];
+ snprintf(tmp, 256, "Using file size limit of %li bytes\n", dltdata.climit);
+ dlt_log(LOG_INFO, tmp);
+ dltdata.ohandle = dlt_receive_open_output_file(&dltdata);
}
else /* in case no limit for the output file is given, we simply overwrite any existing file */
{
- dltdata.ohandle = open(dltdata.ovalue, O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ dltdata.ohandle = open(dltdata.ovalue, O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
}
if (dltdata.ohandle == -1)
@@ -612,17 +612,21 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
if (dltdata->climit > -1)
{
int bytes_to_write = message->headersize + message->datasize;
+
if ((bytes_to_write + dltdata->totalbytes > dltdata->climit))
{
- dlt_receive_close_output_file(dltdata);
+ dlt_receive_close_output_file(dltdata);
+
if (dlt_receive_open_output_file(dltdata) < 0)
{
printf("ERROR: dlt_receive_message_callback: Unable to open log when maximum filesize was reached!\n");
return -1;
}
+
dltdata->totalbytes = 0;
}
}
+
bytes_written = writev(dltdata->ohandle, iov, 2);
dltdata->totalbytes += bytes_written;
diff --git a/src/examples/dlt-example-user.c b/src/examples/dlt-example-user.c
index 5f4abc9..61550fc 100644
--- a/src/examples/dlt-example-user.c
+++ b/src/examples/dlt-example-user.c
@@ -269,7 +269,7 @@ int main(int argc, char* argv[])
if(mvalue)
{
printf("Set log mode to %d\n",atoi(mvalue));
- dlt_set_log_mode(atoi(mvalue));
+ dlt_set_log_mode(atoi(mvalue));
}
diff --git a/src/lib/dlt_env_ll.c b/src/lib/dlt_env_ll.c
index d2ef7b1..a3e3a16 100644
--- a/src/lib/dlt_env_ll.c
+++ b/src/lib/dlt_env_ll.c
@@ -1,25 +1,29 @@
-/**
+/*
* @licence app begin@
- * Copyright (C) 2015 Intel Corporation
+ * SPDX license identifier: MPL-2.0
*
- * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
+ * Copyright (C) 2015 Intel Corporation
*
- * Contributions are licensed to the GENIVI Alliance under one or more
- * Contribution License Agreements.
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
*
- * \copyright
* This Source Code Form is subject to the terms of the
- * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
- * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- *
- * \author Stefan Vacek <stefan.vacek@intel.com> Intel Corporation
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
*
- * \file dlt_env_ll.c
* For further information see http://www.genivi.org/.
* @licence end@
*/
+/*!
+ * \author Stefan Vacek <stefan.vacek@intel.com> Intel Corporation
+ *
+ * \copyright Copyright © 2015 Intel Corporation. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt_env_ll.c
+*/
+
#include "dlt_user.h"
#include <string.h>
#include <stdlib.h>
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index b996726..9cf4070 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -83,22 +83,22 @@ pthread_cond_t mq_init_condition;
void dlt_lock_mutex(pthread_mutex_t *mutex)
{
- int32_t lock_mutex_result = pthread_mutex_lock(mutex);
- if (lock_mutex_result == EOWNERDEAD)
- {
- pthread_mutex_consistent(mutex);
- lock_mutex_result = 0;
- }
- else if ( lock_mutex_result != 0 )
- {
- snprintf(str,DLT_USER_BUFFER_LENGTH, "Mutex lock failed unexpected pid=%i with result %i!\n", getpid(), lock_mutex_result);
- dlt_log(LOG_ERR, str);
- }
+ int32_t lock_mutex_result = pthread_mutex_lock(mutex);
+ if (lock_mutex_result == EOWNERDEAD)
+ {
+ pthread_mutex_consistent(mutex);
+ lock_mutex_result = 0;
+ }
+ else if ( lock_mutex_result != 0 )
+ {
+ snprintf(str,DLT_USER_BUFFER_LENGTH, "Mutex lock failed unexpected pid=%i with result %i!\n", getpid(), lock_mutex_result);
+ dlt_log(LOG_ERR, str);
+ }
}
inline void dlt_unlock_mutex(pthread_mutex_t *mutex)
{
- pthread_mutex_unlock(mutex);
+ pthread_mutex_unlock(mutex);
}
/* Structure to pass data to segmented thread */
@@ -286,14 +286,14 @@ int dlt_init(void)
pthread_mutexattr_t attr;
if (pthread_mutexattr_init(&attr) != 0)
{
- dlt_user_initialised = 0;
- return -1;
+ dlt_user_initialised = 0;
+ return -1;
}
/* make mutex robust to prevent from deadlock when the segmented thread was cancelled, but held the mutex */
if ( pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST) != 0 )
{
- dlt_user_initialised = 0;
- return -1;
+ dlt_user_initialised = 0;
+ return -1;
}
pthread_mutex_init(&mq_mutex, &attr);
@@ -302,8 +302,8 @@ int dlt_init(void)
if (dlt_start_threads() < 0)
{
- dlt_user_initialised = 0;
- return -1;
+ dlt_user_initialised = 0;
+ return -1;
}
// prepare for fork() call
@@ -471,11 +471,11 @@ int dlt_init_common(void)
env_initial_log_level = getenv("DLT_INITIAL_LOG_LEVEL");
if( env_initial_log_level != NULL )
{
- if (dlt_env_extract_ll_set(&env_initial_log_level, &dlt_user.initial_ll_set) != 0)
- {
- snprintf(str, DLT_USER_BUFFER_LENGTH, "Unable to parse initial set of log-levels from environment! Env:\n%s\n", getenv("DLT_INITIAL_LOG_LEVEL"));
- dlt_log(LOG_WARNING, str);
- }
+ if (dlt_env_extract_ll_set(&env_initial_log_level, &dlt_user.initial_ll_set) != 0)
+ {
+ snprintf(str, DLT_USER_BUFFER_LENGTH, "Unable to parse initial set of log-levels from environment! Env:\n%s\n", getenv("DLT_INITIAL_LOG_LEVEL"));
+ dlt_log(LOG_WARNING, str);
+ }
}
/* Initialize LogLevel/TraceStatus field */
@@ -496,8 +496,8 @@ int dlt_init_common(void)
if (atexit_registered == 0)
{
- atexit_registered = 1;
- atexit(dlt_user_atexit_handler);
+ atexit_registered = 1;
+ atexit(dlt_user_atexit_handler);
}
#ifdef DLT_TEST_ENABLE
@@ -3443,7 +3443,7 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype)
ret = DLT_RETURN_OK;
if((dlt_user.dlt_log_handle!=-1) && (dlt_user.appID[0]!='\0'))
{
- ret = dlt_user_log_resend_buffer();
+ ret = dlt_user_log_resend_buffer();
}
if((ret == DLT_RETURN_OK) && (dlt_user.appID[0] != '\0'))
{
@@ -3706,7 +3706,7 @@ int dlt_user_log_send_register_context(DltContextData *log)
/* log to FIFO */
if (dlt_user.appID[0]!='\0')
{
- ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterContext),log->context_description,usercontext.description_length);
+ ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterContext),log->context_description,usercontext.description_length);
}
@@ -3727,7 +3727,7 @@ int dlt_user_log_send_register_context(DltContextData *log)
DLT_SEM_FREE();
- if((dlt_user.appID[0] != '\0') && (dlt_user_queue_resend() < 0) && (dlt_user.dlt_log_handle >= 0))
+ if ((dlt_user.appID[0] != '\0') && (dlt_user_queue_resend() < 0) && (dlt_user.dlt_log_handle >= 0))
{
;//dlt_log(LOG_WARNING, "dlt_user_log_send_register_context: Failed to queue resending.\n");
}
@@ -4164,7 +4164,7 @@ int dlt_user_log_resend_buffer(void)
if (dlt_user.appID[0]=='\0')
{
- return 0;
+ return 0;
}
/* Send content of ringbuffer */
@@ -4180,37 +4180,37 @@ int dlt_user_log_resend_buffer(void)
if (size>0)
{
- DltUserHeader *userheader = (DltUserHeader*) (dlt_user.resend_buffer);
- /* Add application id to the messages of needed*/
- if (dlt_user_check_userheader(userheader))
- {
- switch (userheader->message)
- {
- case DLT_USER_MESSAGE_REGISTER_CONTEXT:
- {
- DltUserControlMsgRegisterContext *usercontext = (DltUserControlMsgRegisterContext*) (dlt_user.resend_buffer+sizeof(DltUserHeader));
- if ((usercontext != 0) && (usercontext->apid[0]=='\0'))
+ DltUserHeader *userheader = (DltUserHeader*) (dlt_user.resend_buffer);
+ /* Add application id to the messages of needed*/
+ if (dlt_user_check_userheader(userheader))
{
- dlt_set_id(usercontext->apid,dlt_user.appID);
- }
- break;
- }
- case DLT_USER_MESSAGE_LOG:
- {
- DltExtendedHeader * extendedHeader = (DltExtendedHeader *)(dlt_user.resend_buffer+sizeof(DltUserHeader)+
- sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra) - DLT_ID_SIZE);
- if ((extendedHeader) != 0 && (extendedHeader->apid[0]=='\0'))
- { // if application id is empty, add it
- dlt_set_id(extendedHeader->apid,dlt_user.appID);
+ switch (userheader->message)
+ {
+ case DLT_USER_MESSAGE_REGISTER_CONTEXT:
+ {
+ DltUserControlMsgRegisterContext *usercontext = (DltUserControlMsgRegisterContext*) (dlt_user.resend_buffer+sizeof(DltUserHeader));
+ if ((usercontext != 0) && (usercontext->apid[0]=='\0'))
+ {
+ dlt_set_id(usercontext->apid,dlt_user.appID);
+ }
+ break;
+ }
+ case DLT_USER_MESSAGE_LOG:
+ {
+ DltExtendedHeader * extendedHeader = (DltExtendedHeader *)(dlt_user.resend_buffer+sizeof(DltUserHeader)+
+ sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra) - DLT_ID_SIZE);
+ if ((extendedHeader) != 0 && (extendedHeader->apid[0]=='\0'))
+ { // if application id is empty, add it
+ dlt_set_id(extendedHeader->apid,dlt_user.appID);
+ }
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
}
- break;
- }
- default:
- {
- break;
- }
- }
- }
#ifdef DLT_SHM_ENABLE
dlt_shm_push(&dlt_user.dlt_shm,dlt_user.resend_buffer+sizeof(DltUserHeader),size-sizeof(DltUserHeader),0,0,0,0);
@@ -4377,101 +4377,107 @@ void dlt_user_test_corrupt_message_size(int enable,int16_t size)
int dlt_start_threads()
{
- /* Start receiver thread */
- if (pthread_create(&(dlt_receiverthread_handle),
- 0,
- (void *) &dlt_user_receiverthread_function,
- 0)!=0)
- {
- dlt_log(LOG_CRIT, "Can't create receiver thread!\n");
- return -1;
- }
+ /* Start receiver thread */
+ if (pthread_create(&(dlt_receiverthread_handle),
+ 0,
+ (void *) &dlt_user_receiverthread_function,
+ 0) != 0)
+ {
+ dlt_log(LOG_CRIT, "Can't create receiver thread!\n");
+ return -1;
+ }
- /* Start the segmented thread */
- if (pthread_create(&(dlt_user.dlt_segmented_nwt_handle), NULL,
- (void *)dlt_user_trace_network_segmented_thread, NULL))
- {
- dlt_log(LOG_CRIT, "Can't start segmented thread!\n");
- return -1;
- }
+ /* Start the segmented thread */
+ if (pthread_create(&(dlt_user.dlt_segmented_nwt_handle), NULL,
+ (void *) dlt_user_trace_network_segmented_thread, NULL))
+ {
+ dlt_log(LOG_CRIT, "Can't start segmented thread!\n");
+ return -1;
+ }
- return 0;
+ return 0;
}
-
void dlt_stop_threads()
{
- int dlt_receiverthread_result = 0;
- int dlt_segmented_nwt_result = 0;
- if (dlt_receiverthread_handle)
- {
- /* do not ignore return value */
- dlt_receiverthread_result = pthread_cancel(dlt_receiverthread_handle);
- if (dlt_receiverthread_result != 0)
+ int dlt_receiverthread_result = 0;
+ int dlt_segmented_nwt_result = 0;
+ if (dlt_receiverthread_handle)
{
- snprintf(str,DLT_USER_BUFFER_LENGTH, "ERROR pthread_cancel(dlt_receiverthread_handle): %s\n", strerror(errno));
- dlt_log(LOG_ERR, str);
+ /* do not ignore return value */
+ dlt_receiverthread_result = pthread_cancel(dlt_receiverthread_handle);
+ if (dlt_receiverthread_result != 0)
+ {
+ snprintf(str, DLT_USER_BUFFER_LENGTH,
+ "ERROR pthread_cancel(dlt_receiverthread_handle): %s\n",
+ strerror(errno));
+ dlt_log(LOG_ERR, str);
+ }
}
- }
- if (dlt_user.dlt_segmented_nwt_handle)
- {
- dlt_segmented_nwt_result = pthread_cancel(dlt_user.dlt_segmented_nwt_handle);
- if (dlt_segmented_nwt_result != 0)
+ if (dlt_user.dlt_segmented_nwt_handle)
{
- snprintf(str,DLT_USER_BUFFER_LENGTH, "ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n", strerror(errno));
- dlt_log(LOG_ERR, str);
+ dlt_segmented_nwt_result = pthread_cancel(dlt_user.dlt_segmented_nwt_handle);
+ if (dlt_segmented_nwt_result != 0)
+ {
+ snprintf(str, DLT_USER_BUFFER_LENGTH,
+ "ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n",
+ strerror(errno));
+ dlt_log(LOG_ERR, str);
+ }
}
- }
- /* make sure that the threads really finished working */
- if ((dlt_receiverthread_result==0) && dlt_receiverthread_handle)
- {
- int joined = pthread_join(dlt_receiverthread_handle, NULL);
- if (joined < 0)
+ /* make sure that the threads really finished working */
+ if ((dlt_receiverthread_result == 0) && dlt_receiverthread_handle)
{
- snprintf(str,DLT_USER_BUFFER_LENGTH, "ERROR pthread_join(dlt_receiverthread_handle, NULL): %s\n", strerror(errno));
- dlt_log(LOG_ERR, str);
+ int joined = pthread_join(dlt_receiverthread_handle, NULL);
+ if (joined < 0)
+ {
+ snprintf(str, DLT_USER_BUFFER_LENGTH,
+ "ERROR pthread_join(dlt_receiverthread_handle, NULL): %s\n",
+ strerror(errno));
+ dlt_log(LOG_ERR, str);
+ }
+ dlt_receiverthread_handle = 0; /* set to invalid */
}
- dlt_receiverthread_handle = 0; /* set to invalid */
- }
- if ((dlt_segmented_nwt_result==0) && dlt_user.dlt_segmented_nwt_handle)
- {
- int joined = pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL);
- if (joined < 0)
+ if ((dlt_segmented_nwt_result == 0) && dlt_user.dlt_segmented_nwt_handle)
{
- snprintf(str,DLT_USER_BUFFER_LENGTH, "ERROR pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL): %s\n", strerror(errno));
- dlt_log(LOG_ERR, str);
+ int joined = pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL);
+ if (joined < 0)
+ {
+ snprintf(str, DLT_USER_BUFFER_LENGTH,
+ "ERROR pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL): %s\n",
+ strerror(errno));
+ dlt_log(LOG_ERR, str);
+ }
+ dlt_user.dlt_segmented_nwt_handle = 0; /* set to invalid */
}
- dlt_user.dlt_segmented_nwt_handle = 0; /* set to invalid */
- }
}
-
static void dlt_fork_pre_fork_handler()
{
- dlt_stop_threads();
+ dlt_stop_threads();
}
-
static void dlt_fork_parent_fork_handler()
{
- if (dlt_start_threads() < 0)
- {
- snprintf(str,DLT_USER_BUFFER_LENGTH,"Logging disabled, failed re-start thread after fork(pid=%i)!\n", getpid());
- dlt_log(LOG_WARNING, str);
- /* cleanup is the only thing we can do here */
- dlt_log_free();
- dlt_free();
- }
+ if (dlt_start_threads() < 0)
+ {
+ snprintf(str, DLT_USER_BUFFER_LENGTH,
+ "Logging disabled, failed re-start thread after fork(pid=%i)!\n",
+ getpid());
+ dlt_log(LOG_WARNING, str);
+ /* cleanup is the only thing we can do here */
+ dlt_log_free();
+ dlt_free();
+ }
}
-
static void dlt_fork_child_fork_handler()
{
- /* don't start anything else but cleanup everything and avoid blow-out of buffers*/
- dlt_log_free();
- dlt_free();
- /* the only thing that remains is the atexit-handler */
+ /* don't start anything else but cleanup everything and avoid blow-out of buffers*/
+ dlt_log_free();
+ dlt_free();
+ /* the only thing that remains is the atexit-handler */
}
diff --git a/src/tests/dlt-test-fork-handler.c b/src/tests/dlt-test-fork-handler.c
index d9c65e5..84685f9 100644
--- a/src/tests/dlt-test-fork-handler.c
+++ b/src/tests/dlt-test-fork-handler.c
@@ -1,8 +1,29 @@
-/**
- * Copyright (C) 2015 Intel Corporation
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2015 Intel Corporation
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
*
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
*/
+/*!
+ * \author Stefan Vacek <stefan.vacek@intel.com> Intel Corporation
+ *
+ * \copyright Copyright © 2015 Intel Corporation. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-test-fork-handler.c
+*/
+
#include <unistd.h> /* for fork() */
#include "dlt.h"
@@ -12,36 +33,37 @@
*/
int main()
{
- DltContext mainContext;
-
- DLT_REGISTER_APP("PRNT", "Parent application");
- DLT_REGISTER_CONTEXT(mainContext, "CTXP", "Parent context");
- DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before fork"));
- usleep(200000);
-
- pid_t pid = fork();
- if (pid == 0) /* child process */
- {
- /* this message should not be visible */
- /* DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's first message after fork, pid: "), DLT_INT32(getpid())); */
- /* unfortunately, this message does arrive, I assume because it still has (locally) valid data ... */
-
- DLT_REGISTER_APP("CHLD", "Child application");
- DLT_REGISTER_CONTEXT(mainContext, "CTXC", "Child context");
- DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's second message after fork, pid: "), DLT_INT32(getpid()));
- usleep(400000);
- }
- else if (pid == -1) /* error in fork */
- {
- return -1;
- }
- else /* parent */
- {
- DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Parent's first message after fork, pid: "), DLT_INT32(getpid()));
- usleep(500000);
- }
-
- DLT_UNREGISTER_APP();
-
- return 0;
+ DltContext mainContext;
+
+ DLT_REGISTER_APP("PRNT", "Parent application");
+ DLT_REGISTER_CONTEXT(mainContext, "CTXP", "Parent context");
+ DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before fork"));
+ usleep(200000);
+
+ pid_t pid = fork();
+ if (pid == 0) /* child process */
+ {
+ /* this message should not be visible */
+ /* DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's first message after fork, pid: "), DLT_INT32(getpid())); */
+ /* unfortunately, this message does arrive, I assume because it still has (locally) valid data ... */
+
+ DLT_REGISTER_APP("CHLD", "Child application");
+ DLT_REGISTER_CONTEXT(mainContext, "CTXC", "Child context");
+ DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's second message after fork, pid: "), DLT_INT32(getpid()));
+ usleep(400000);
+ }
+ else if (pid == -1) /* error in fork */
+ {
+ return -1;
+ }
+ else /* parent */
+ {
+ DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Parent's first message after fork, pid: "), DLT_INT32(getpid()));
+ usleep(500000);
+ }
+
+ DLT_UNREGISTER_APP()
+ ;
+
+ return 0;
}