summaryrefslogtreecommitdiff
path: root/src/system/dlt-system.h
blob: bbd09fdc5360482cc321e7c3a9f4efa6362b77dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 * SPDX license identifier: MPL-2.0
 *
 * Copyright (C) 2011-2015, BMW AG
 *
 * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
 *
 * This Source Code Form is subject to the terms of the
 * Mozilla Public License (MPL), v. 2.0.
 * If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * For further information see http://www.genivi.org/.
 */

/*!
 * \author Lassi Marttala <lassi.lm.marttala@partner.bmw.de>
 *
 * \copyright Copyright © 2011-2015 BMW AG. \n
 * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
 *
 * \file dlt-system.h
 */

/*******************************************************************************
**                                                                            **
**  SRC-MODULE: dlt-system.h                                                  **
**                                                                            **
**  TARGET    : linux                                                         **
**                                                                            **
**  PROJECT   : DLT                                                           **
**                                                                            **
**  AUTHOR    : Lassi Marttala <lassi.lm.marttala@partner.bmw.de>             **
**                                                                            **
**  PURPOSE   :                                                               **
**                                                                            **
**  REMARKS   :                                                               **
**                                                                            **
**  PLATFORM DEPENDANT [yes/no]: yes                                          **
**                                                                            **
**  TO BE CHANGED BY USER [yes/no]: no                                        **
**                                                                            **
*******************************************************************************/

/*******************************************************************************
**                      Author Identity                                       **
********************************************************************************
**                                                                            **
** Initials     Name                       Company                            **
** --------     -------------------------  ---------------------------------- **
**  lm          Lassi Marttala             BMW                                **
*******************************************************************************/

#ifndef DLT_SYSTEM_H_
#define DLT_SYSTEM_H_

#include <systemd/sd-journal.h>
#include <poll.h>

/* DLT related includes. */
#include "dlt.h"
#include "dlt_common.h"

/* Constants */
#define DEFAULT_CONF_FILE (CONFIGURATION_FILES_DIR "/dlt-system.conf")
#define DLT_SYSTEM_LOG_FILE_MAX 32
#define DLT_SYSTEM_LOG_DIRS_MAX 32
#define DLT_SYSTEM_LOG_PROCESSES_MAX 32

#define DLT_SYSTEM_MODE_OFF 0
#define DLT_SYSTEM_MODE_STARTUP 1
#define DLT_SYSTEM_MODE_REGULAR 2

#define MAX_LINE 1024

/** Total number of file descriptors needed for processing all features:
*   - Journal file descriptor
*   - Syslog file descriptor
*   - Timer file descriptor for processing LogFile and LogProcesses every second
*   - Inotify file descriptor for FileTransfer
*   - Timer file descriptor for Watchdog 
*/
#define MAX_FD_NUMBER   5

/* Macros */
#define MALLOC_ASSERT(x) if (x == NULL) { \
        fprintf(stderr, "Out of memory\n"); \
        abort(); }

/* enum for classification of FD */
enum fdType {
    fdType_journal = 0,
    fdType_syslog,
    fdType_filetransfer,
    fdType_timer,
    fdType_watchdog,
};

/**
 * Configuration structures.
 * Please see dlt-system.conf for explanation of all the options.
 */

/* Command line options */
typedef struct {
    char *ConfigurationFileName;
    int Daemonize;
} DltSystemCliOptions;

/* Configuration shell options */
typedef struct {
    int Enable;
} ShellOptions;

/* Configuration syslog options */
typedef struct {
    int Enable;
    char ContextId[DLT_ID_SIZE];
    int Port;
} SyslogOptions;

/* Configuration journal options */
typedef struct {
    int Enable;
    char ContextId[DLT_ID_SIZE];
    int CurrentBoot;
    int Follow;
    int MapLogLevels;
    int UseOriginalTimestamp;
} JournalOptions;

typedef struct {
    int Enable;
    char ContextId[DLT_ID_SIZE];
    int TimeStartup;
    int TimeoutBetweenLogs;
    char *TempDir;

    /* Variable number of file transfer dirs */
    int Count;
    int Compression[DLT_SYSTEM_LOG_DIRS_MAX];
    int CompressionLevel[DLT_SYSTEM_LOG_DIRS_MAX];
    char *Directory[DLT_SYSTEM_LOG_DIRS_MAX];
} FiletransferOptions;

typedef struct {
    int handle;
    int fd[DLT_SYSTEM_LOG_DIRS_MAX];
} s_ft_inotify;

typedef struct {
    int Enable;

    /* Variable number of files to transfer */
    int Count;
    char ContextId[DLT_SYSTEM_LOG_FILE_MAX][DLT_ID_SIZE];
    char *Filename[DLT_SYSTEM_LOG_FILE_MAX];
    int Mode[DLT_SYSTEM_LOG_FILE_MAX];
    int TimeDelay[DLT_SYSTEM_LOG_FILE_MAX];
} LogFileOptions;

typedef struct {
    int Enable;
    char ContextId[DLT_ID_SIZE];

    /* Variable number of processes */
    int Count;
    char *Name[DLT_SYSTEM_LOG_PROCESSES_MAX];
    char *Filename[DLT_SYSTEM_LOG_PROCESSES_MAX];
    int Mode[DLT_SYSTEM_LOG_PROCESSES_MAX];
    int TimeDelay[DLT_SYSTEM_LOG_PROCESSES_MAX];
} LogProcessOptions;

typedef struct {
    char ApplicationId[DLT_ID_SIZE];
    ShellOptions Shell;
    SyslogOptions Syslog;
    JournalOptions Journal;
    FiletransferOptions Filetransfer;
    LogFileOptions LogFile;
    LogProcessOptions LogProcesses;
} DltSystemConfiguration;

/**
 * Forward declarations for the whole application
 */

/* In dlt-system-options.c */
int read_command_line(DltSystemCliOptions *options, int argc, char *argv[]);
int read_configuration_file(DltSystemConfiguration *config, char *file_name);
void cleanup_config(DltSystemConfiguration *config, DltSystemCliOptions *options);

/* For dlt-process-handling.c */
int daemonize();
void init_shell();
void dlt_system_signal_handler(int sig);

/* Main function for creating/registering all needed file descriptors and starting the poll for all of them. */
void start_dlt_system_processes(DltSystemConfiguration *config);

/* Init process, create file descriptors and register them into main pollfd. */
int register_watchdog_fd(struct pollfd *pollfd, int fdcnt);
int init_filetransfer_dirs(DltSystemConfiguration *config);
void logfile_init(void *v_conf);
void logprocess_init(void *v_conf);
void register_journal_fd(sd_journal **j, struct pollfd *pollfd, int i,  DltSystemConfiguration *config);
int register_syslog_fd(struct pollfd *pollfd, int i, DltSystemConfiguration *config);

/* Routines that are called, when a fd event was raised. */
void logfile_fd_handler(void *v_conf);
void logprocess_fd_handler(void *v_conf);
void filetransfer_fd_handler(DltSystemConfiguration *config);
void watchdog_fd_handler(int fd);
void journal_fd_handler(sd_journal *j, DltSystemConfiguration *config);
void syslog_fd_handler(int syslogSock);

#endif /* DLT_SYSTEM_H_ */