summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Vacek <stefan.vacek@intel.com>2015-12-09 15:30:36 +0100
committerLutz Helwing <lutz_helwing@mentor.com>2015-12-09 17:39:10 +0100
commitebb0a840b34c09e5b75f291b975c230b1ccb0b91 (patch)
tree3ce51fc04f22e092c8f2a73b7b15c523bd525ce8
parent135e75439eff9cb7171d8b5bcf2ff6a27d0bf132 (diff)
downloadDLT-daemon-ebb0a840b34c09e5b75f291b975c230b1ccb0b91.tar.gz
Fix fork()-handler in libdlt
Signed-off-by: Stefan Vacek <stefan.vacek@intel.com>
-rw-r--r--src/lib/dlt_user.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index d5ed200..6118e41 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -78,6 +78,10 @@ static pthread_t dlt_receiverthread_handle;
// calling dlt_user_atexit_handler() second time fails with error message
static int atexit_registered = 0;
+// calling atfork_handler() only once
+static int atfork_registered = 0;
+
+
/* Segmented Network Trace */
#define DLT_MAX_TRACE_SEGMENT_SIZE 1024
#define DLT_MESSAGE_QUEUE_NAME "/dlt_message_queue"
@@ -322,7 +326,11 @@ DltReturnValue dlt_init(void)
}
// prepare for fork() call
- pthread_atfork(&dlt_fork_pre_fork_handler, &dlt_fork_parent_fork_handler, &dlt_fork_child_fork_handler);
+ if (atfork_registered == 0)
+ {
+ atfork_registered = 1;
+ pthread_atfork(&dlt_fork_pre_fork_handler, &dlt_fork_parent_fork_handler, &dlt_fork_child_fork_handler);
+ }
return DLT_RETURN_OK;
}
@@ -4553,22 +4561,28 @@ static void dlt_fork_pre_fork_handler()
static void dlt_fork_parent_fork_handler()
{
- if (dlt_start_threads() < 0)
+ if (dlt_user_initialised)
{
- snprintf(str, DLT_USER_BUFFER_LENGTH,
+ 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();
+ 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()
{
+ if (dlt_user_initialised)
+ {
/* 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 */
+ }
}