automotive-dlt
dlt-system.c
Go to the documentation of this file.
1 /*
2  * @licence app begin@
3  * SPDX license identifier: MPL-2.0
4  *
5  * Copyright (C) 2011-2015, BMW AG
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 /*******************************************************************************
28 ** **
29 ** SRC-MODULE: dlt-system.c **
30 ** **
31 ** TARGET : linux **
32 ** **
33 ** PROJECT : DLT **
34 ** **
35 ** AUTHOR : Lassi Marttala <lassi.lm.marttala@partner.bmw.de> **
36 ** Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
37 ** **
38 ** PURPOSE : **
39 ** **
40 ** REMARKS : **
41 ** **
42 ** PLATFORM DEPENDANT [yes/no]: yes **
43 ** **
44 ** TO BE CHANGED BY USER [yes/no]: no **
45 ** **
46 *******************************************************************************/
47 
48 #include "dlt-system.h"
49 
50 #include <stdio.h>
51 #include <string.h>
52 #include <errno.h>
53 #include <signal.h>
54 
55 #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
56 #include "sd-daemon.h"
57 #endif
58 
60 
61 int main(int argc, char* argv[])
62 {
63  DltSystemCliOptions options;
65 
66 #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
67  int ret;
68 #endif
69 
70  if(read_command_line(&options, argc, argv) < 0)
71  {
72  fprintf(stderr, "Failed to read command line!\n");
73  return -1;
74  }
75 
76  if(read_configuration_file(&config, options.ConfigurationFileName) < 0)
77  {
78  fprintf(stderr, "Failed to read configuration file!\n");
79  return -1;
80  }
81  DLT_REGISTER_APP(config.ApplicationId, "DLT System Manager");
82  DLT_REGISTER_CONTEXT(dltsystem,"MGR", "Context of main dlt system manager");
83 
84 #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
85  ret = sd_booted();
86 
87  if(ret == 0){
88  DLT_LOG(dltsystem, DLT_LOG_INFO, DLT_STRING("system not booted with systemd!\n"));
89  }
90  else if(ret < 0)
91  {
92  DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("sd_booted failed!\n"));
93  return -1;
94  }
95  else
96  {
97  DLT_LOG(dltsystem, DLT_LOG_INFO, DLT_STRING("system booted with systemd\n"));
98  }
99 #endif
100 
101  DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Configuration loaded."));
102 
103  if(options.Daemonize > 0)
104  {
105  if(daemonize() < 0)
106  {
107  DLT_LOG(dltsystem, DLT_LOG_FATAL, DLT_STRING("Daemonization failed!"));
108  return -1;
109  }
110  DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system daemonized."));
111  }
112 
113  DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Setting signal handlers for abnormal exit"));
114  signal(SIGTERM, dlt_system_signal_handler);
115  signal(SIGHUP, dlt_system_signal_handler);
116  signal(SIGQUIT, dlt_system_signal_handler);
117  signal(SIGINT, dlt_system_signal_handler);
118 
119  DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Launching threads."));
120 
121 
122  start_threads(&config);
123  join_threads();
124  return 0;
125 }
126 
127 
void start_threads(DltSystemConfiguration *config)
int daemonize()
DltKpiConfig config
Definition: dlt-kpi.c:37
int main(int argc, char *argv[])
Definition: dlt-control.c:276
void dlt_system_signal_handler(int sig)
void join_threads()
int read_configuration_file(DltDBusConfiguration *config, char *file_name)
#define DLT_REGISTER_APP(APPID, DESCRIPTION)
#define DLT_STRING(TEXT)
#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION)
#define DLT_LOG(CONTEXT, LOGLEVEL, ARGS...)
int read_command_line(DltDBusCliOptions *options, int argc, char *argv[])
char * ConfigurationFileName
Definition: dlt-system.h:89
DLT_DECLARE_CONTEXT(dltsystem)
Definition: dlt-system.c:59