automotive-dlt
dlt-test-fork-handler.c
Go to the documentation of this file.
1 /*
2  * @licence app begin@
3  * SPDX license identifier: MPL-2.0
4  *
5  * Copyright (C) 2015 Intel Corporation
6  *
7  * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
8  *
9  * This Source Code Form is subject to the terms of the
10  * Mozilla Public License (MPL), v. 2.0.
11  * If a copy of the MPL was not distributed with this file,
12  * You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  * For further information see http://www.genivi.org/.
15  * @licence end@
16  */
17 
27 #include <unistd.h> /* for fork() */
28 
29 #include "dlt.h"
30 
34 int main()
35 {
36  DltContext mainContext;
37 
38  DLT_REGISTER_APP("PRNT", "Parent application");
39  DLT_REGISTER_CONTEXT(mainContext, "CTXP", "Parent context");
40  DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before fork"));
41  usleep(200000);
42 
43  pid_t pid = fork();
44  if (pid == 0) /* child process */
45  {
46  /* this message should not be visible */
47  /* DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's first message after fork, pid: "), DLT_INT32(getpid())); */
48  /* unfortunately, this message does arrive, I assume because it still has (locally) valid data ... */
49 
50  DLT_REGISTER_APP("CHLD", "Child application");
51  DLT_REGISTER_CONTEXT(mainContext, "CTXC", "Child context");
52  DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's second message after fork, pid: "), DLT_INT32(getpid()));
53  usleep(400000);
54  }
55  else if (pid == -1) /* error in fork */
56  {
57  return -1;
58  }
59  else /* parent */
60  {
61  DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Parent's first message after fork, pid: "), DLT_INT32(getpid()));
62  usleep(500000);
63  }
64 
66  ;
67 
68  return 0;
69 }
#define DLT_UNREGISTER_APP()
int main()
sample code for using at_fork-handler
#define DLT_INT32(INT_VAR)
#define DLT_REGISTER_APP(APPID, DESCRIPTION)
#define DLT_STRING(TEXT)
#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION)
#define DLT_LOG(CONTEXT, LOGLEVEL, ARGS...)