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);
126 if(config->LogFile.Enable)
127 start_logfile(config);
129 if(config->Filetransfer.Enable)
130 start_filetransfer(config);
132 if(config->LogProcesses.Enable)
133 start_logprocess(config);
135 if(config->Syslog.Enable)
136 start_syslog(config);
140 * Wait for threads to exit.
141 * There's not actually a condition currently
142 * to bail out of file transfer without a signal.
147 DLT_LOG(dltsystem, DLT_LOG_DEBUG,
148 DLT_STRING("dlt-system-process-handling, waiting for threads to exit."));
150 if(threads.count < 1)
152 DLT_LOG(dltsystem, DLT_LOG_DEBUG,
153 DLT_STRING("dlt-system-process-handling, no threads, waiting for signal."));
158 DLT_LOG(dltsystem,DLT_LOG_DEBUG,
159 DLT_STRING("dlt-system-process-handling, thread count: "),
160 DLT_INT(threads.count));
162 for (i = 0; i < threads.count; i++)
164 pthread_join(threads.threads[i], NULL);
165 DLT_LOG(dltsystem,DLT_LOG_DEBUG,
166 DLT_STRING("dlt-system-process-handling, thread exit: "),
167 DLT_INT(threads.threads[i]));
172 void dlt_system_signal_handler(int sig)
174 DLT_LOG(dltsystem,DLT_LOG_DEBUG,
175 DLT_STRING("dlt-system-process-handling, signal handler"));
183 DLT_LOG(dltsystem,DLT_LOG_DEBUG,
184 DLT_STRING("dlt-system-process-handling, exit, signal: "),
189 DLT_LOG(dltsystem,DLT_LOG_WARN,
190 DLT_STRING("dlt-system-process-handling, unknown signal!"));