From f8f80a07afd45d60c2975bfd7e4b859fb8c10a96 Mon Sep 17 00:00:00 2001 From: Lassi Marttala Date: Wed, 16 May 2012 10:10:12 +0200 Subject: [GDLT-67] dlt-system v2.0, check full commit message for rebase details [GDLT-67] Prepare build system. [GDLT-67] Config parsing, structure for thread handling [GDLT-67] Finalize configuration reading. [GDLT-67] Reimplementation of syslog, logfile, logprocess, shell. [GDLT-67] First complete version of the new dlt-system. [GDLT-67] Fixed header comments. authors, file names. [GDLT-67] Final touches. [GDLT-67] Fixed a problem with thread creation in optimized release binary. [GDLT-67] New configuration file. [GDLT-67] Added dlt debug output Signed-off-by: Christian Muck --- src/system/dlt-system-processes.c | 167 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 src/system/dlt-system-processes.c (limited to 'src/system/dlt-system-processes.c') diff --git a/src/system/dlt-system-processes.c b/src/system/dlt-system-processes.c new file mode 100644 index 0000000..fd475b8 --- /dev/null +++ b/src/system/dlt-system-processes.c @@ -0,0 +1,167 @@ +/** + * @licence app begin@ + * Copyright (C) 2012 BMW AG + * + * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, 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/. + * + * + * \author Lassi Marttala BMW 2012 + * + * \file dlt-system-logfile.c + * For further information see http://www.genivi.org/. + * @licence end@ + */ + +/******************************************************************************* +** ** +** SRC-MODULE: dlt-system-processes.c ** +** ** +** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Lassi Marttala ** +** Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dlt-system.h" + +// Modes of sending +#define SEND_MODE_OFF 0 +#define SEND_MODE_ONCE 1 +#define SEND_MODE_ON 2 + +extern DltSystemThreads threads; + +DLT_IMPORT_CONTEXT(dltsystem) +DLT_DECLARE_CONTEXT(procContext) + +void send_process(LogProcessOptions popts, int n) +{ + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-processes, send process info.")); + FILE * pFile; + struct dirent *dp; + char filename[256]; + char buffer[1024]; + int bytes; + int found = 0; + + /* go through all process files in directory */ + DIR *dir = opendir("/proc"); + if(dir>0) + { + while ((dp=readdir(dir)) != NULL) + { + if(isdigit(dp->d_name[0])) + { + buffer[0] = 0; + sprintf(filename, "/proc/%s/cmdline",dp->d_name); + pFile = fopen(filename, "r"); + if(pFile>0) + { + bytes = fread(buffer, 1, sizeof(buffer)-1, pFile); + fclose(pFile); + } + if((strcmp(popts.Name[n], "*")==0) || + (strcmp(buffer, popts.Name[n])==0)) + { + found = 1; + sprintf(filename, "/proc/%s/%s", dp->d_name,popts.Filename[n]); + pFile = fopen(filename, "r"); + if(pFile>0) + { + bytes = fread(buffer, 1, sizeof(buffer)-1, pFile); + fclose(pFile); + + if(bytes>0) + { + buffer[bytes] = 0; + DLT_LOG(procContext, DLT_LOG_INFO, DLT_INT(atoi(dp->d_name)), DLT_STRING(popts.Filename[n]), DLT_STRING(buffer)); + } + } + if(strcmp(popts.Name[n], "*") !=0) + break; + } + } + } + closedir(dir); + } + + if(!found) { + DLT_LOG(procContext, DLT_LOG_INFO, DLT_STRING("Process"), DLT_STRING(popts.Name[n]),DLT_STRING("not running!")); + } +} + +void logprocess_thread(void *v_conf) +{ + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-processes, in thread.")); + + DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf; + DLT_REGISTER_CONTEXT(procContext, conf->LogProcesses.ContextId, "Log Processes"); + + int process_delays[DLT_SYSTEM_LOG_PROCESSES_MAX]; + int i; + for(i = 0;i < conf->LogProcesses.Count;i++) + process_delays[i] = conf->LogProcesses.TimeDelay[i]; + + while(!threads.shutdown) + { + sleep(1); + for(i = 0;i < conf->LogProcesses.Count;i++) + { + if(conf->LogProcesses.Mode[i] == SEND_MODE_OFF) + continue; + + if(process_delays[i] <= 0) + { + send_process(conf->LogProcesses, i); + process_delays[i] = conf->LogProcesses.TimeDelay[i]; + if(conf->LogProcesses.Mode[i] == SEND_MODE_ONCE) + conf->LogProcesses.Mode[i] = SEND_MODE_OFF; + } + else + { + process_delays[i]--; + } + } + } +} + +void start_logprocess(DltSystemConfiguration *conf) +{ + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-processes, starting process log.")); + static pthread_attr_t t_attr; + static pthread_t pt; + pthread_create(&pt, &t_attr, (void *)logprocess_thread, conf); + threads.threads[threads.count++] = pt; +} -- cgit v1.2.1