From 2a32e86d29e4c727a4dd7d95dc487b6632cdd6d7 Mon Sep 17 00:00:00 2001 From: "Biastoch, Darian (ADITG/ESM)" Date: Fri, 16 Jul 2021 00:29:10 +0000 Subject: system: use signalfd for dlt-system 1: Move the call of pthread_sigmask in dlt-qnx-systems main before DLT_REGISTER_APP, because this already spawns a thread, what was done without applying pthread_sigmask before. 2: Replaced all threads in dlt-system, that are spawned for each feature, through one poll. This poll waits for a file descriptor event, that triggers the feature routine, that was executed before in the thread. Done this for following processes: * reading syslog and journal * frequently reading logfile and logprocess * triggering filetransfer, if a file was added/changed in watched directory * checking watchdog timer of systemd service file with defined intervall Signed-off-by: dbiastoch --- src/system/dlt-system.h | 73 ++++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 28 deletions(-) (limited to 'src/system/dlt-system.h') diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h index e60cb9b..9be1cf4 100644 --- a/src/system/dlt-system.h +++ b/src/system/dlt-system.h @@ -54,6 +54,9 @@ #ifndef DLT_SYSTEM_H_ #define DLT_SYSTEM_H_ +#include +#include + /* DLT related includes. */ #include "dlt.h" #include "dlt_common.h" @@ -70,13 +73,29 @@ #define MAX_LINE 1024 -#define MAX_THREADS 8 +/** 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. @@ -114,7 +133,6 @@ typedef struct { int Enable; char *ContextId; int TimeStartup; - int TimeDelay; int TimeoutBetweenLogs; char *TempDir; @@ -125,6 +143,11 @@ typedef struct { 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; @@ -158,12 +181,6 @@ typedef struct { LogProcessOptions LogProcesses; } DltSystemConfiguration; -typedef struct { - pthread_t threads[MAX_THREADS]; - int count; - int shutdown; -} DltSystemThreads; - /** * Forward declarations for the whole application */ @@ -172,28 +189,28 @@ typedef struct { int read_command_line(DltSystemCliOptions *options, int argc, char *argv[]); int read_configuration_file(DltSystemConfiguration *config, char *file_name); -/* In dlt-process-handling.c */ +/* For dlt-process-handling.c */ int daemonize(); -void start_threads(DltSystemConfiguration *config); -void start_thread(DltSystemConfiguration *conf, - void (thread)(void *), const char *nam); -void join_threads(); +void init_shell(); void dlt_system_signal_handler(int sig); -void register_with_dlt(DltSystemConfiguration *config); -/* Threads */ -void init_shell(); -void syslog_thread(void *v_conf); -void filetransfer_thread(void *v_conf); -void logfile_thread(void *v_conf); -void logprocess_thread(void *v_conf); - -#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) -void watchdog_thread(void *v_conf); -#endif - -#if defined(DLT_SYSTEMD_JOURNAL_ENABLE) -void journal_thread(void *v_conf); -#endif +/* 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_ */ -- cgit v1.2.1