3 * Copyright (C) 2012 BMW AG
5 * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
7 * Contributions are licensed to the GENIVI Alliance under one or more
8 * Contribution License Agreements.
11 * This Source Code Form is subject to the terms of the
12 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
13 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
16 * \author Lassi Marttala <lassi.lm.marttala@partner.bmw.de> BMW 2012
18 * \file dlt-system-process-handling.c
19 * For further information see http://www.genivi.org/.
23 /*******************************************************************************
25 ** SRC-MODULE: dlt-systemprocess-handling.c **
31 ** AUTHOR : Lassi Marttala <lassi.lm.marttala@partner.bmw.de> **
37 ** PLATFORM DEPENDANT [yes/no]: yes **
39 ** TO BE CHANGED BY USER [yes/no]: no **
41 *******************************************************************************/
44 #include "dlt-system.h"
54 volatile DltSystemThreads threads;
56 DLT_IMPORT_CONTEXT(dltsystem);
60 DLT_LOG(dltsystem,DLT_LOG_DEBUG,
61 DLT_STRING("dlt-system-process-handling, daemonize"));
71 // Create a new process group
76 * Close all file descriptors and point
77 * stdin, stdout and stderr to /dev/null
80 for(i = getdtablesize(); i >= 0; i--)
83 int fd = open("/dev/null",O_RDWR);
89 if(dup(fd) < 0 || dup(fd) < 0)
96 * Ignore signals related to child processes and
99 signal(SIGCHLD, SIG_IGN);
100 signal(SIGTSTP, SIG_IGN);
101 signal(SIGTTOU, SIG_IGN);
102 signal(SIGTTIN, SIG_IGN);
103 //no close(fd); - we just intentionally pointed stdx to null! tbd: set ignore for coverity
107 void start_threads(DltSystemConfiguration *config)
109 DLT_LOG(dltsystem,DLT_LOG_DEBUG,
110 DLT_STRING("dlt-system-process-handling, start threads"));
114 threads.shutdown = 0;
115 for(i = 0;i < MAX_THREADS; i++)
117 threads.threads[i] = 0;
120 #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE)
121 start_systemd_watchdog(config);
124 if(config->Shell.Enable)
127 if(config->LogFile.Enable)
128 start_logfile(config);
130 if(config->Filetransfer.Enable)
131 start_filetransfer(config);
133 if(config->LogProcesses.Enable)
134 start_logprocess(config);
136 if(config->Syslog.Enable)
137 start_syslog(config);
139 #if defined(DLT_SYSTEMD_JOURNAL_ENABLE)
140 if(config->Journal.Enable)
141 start_systemd_journal(config);
146 * Wait for threads to exit.
147 * There's not actually a condition currently
148 * to bail out of file transfer without a signal.
153 DLT_LOG(dltsystem, DLT_LOG_DEBUG,
154 DLT_STRING("dlt-system-process-handling, waiting for threads to exit."));
156 if(threads.count < 1)
158 DLT_LOG(dltsystem, DLT_LOG_DEBUG,
159 DLT_STRING("dlt-system-process-handling, no threads, waiting for signal."));
164 DLT_LOG(dltsystem,DLT_LOG_DEBUG,
165 DLT_STRING("dlt-system-process-handling, thread count: "),
166 DLT_INT(threads.count));
168 for (i = 0; i < threads.count; i++)
170 pthread_join(threads.threads[i], NULL);
171 DLT_LOG(dltsystem,DLT_LOG_DEBUG,
172 DLT_STRING("dlt-system-process-handling, thread exit: "),
173 DLT_INT(threads.threads[i]));
178 void dlt_system_signal_handler(int sig)
180 DLT_LOG(dltsystem,DLT_LOG_DEBUG,
181 DLT_STRING("dlt-system-process-handling, signal handler"));
189 DLT_LOG(dltsystem,DLT_LOG_DEBUG,
190 DLT_STRING("dlt-system-process-handling, exit, signal: "),
195 DLT_LOG(dltsystem,DLT_LOG_WARN,
196 DLT_STRING("dlt-system-process-handling, unknown signal!"));