summaryrefslogtreecommitdiff
path: root/src/system
diff options
context:
space:
mode:
Diffstat (limited to 'src/system')
-rw-r--r--src/system/dlt-system-filetransfer.c481
-rw-r--r--src/system/dlt-system-journal.c586
-rw-r--r--src/system/dlt-system-logfile.c152
-rw-r--r--src/system/dlt-system-options.c693
-rw-r--r--src/system/dlt-system-process-handling.c195
-rw-r--r--src/system/dlt-system-processes.c189
-rw-r--r--src/system/dlt-system-shell.c92
-rw-r--r--src/system/dlt-system-syslog.c161
-rw-r--r--src/system/dlt-system-watchdog.c142
-rw-r--r--src/system/dlt-system.c86
-rw-r--r--src/system/dlt-system.h128
11 files changed, 1440 insertions, 1465 deletions
diff --git a/src/system/dlt-system-filetransfer.c b/src/system/dlt-system-filetransfer.c
index 819b6de..9bb1d56 100644
--- a/src/system/dlt-system-filetransfer.c
+++ b/src/system/dlt-system-filetransfer.c
@@ -54,7 +54,7 @@
#include <pthread.h>
#include <unistd.h>
#ifdef linux
-#include <sys/inotify.h>
+# include <sys/inotify.h>
#endif
#include <libgen.h>
#include <dirent.h>
@@ -69,10 +69,10 @@
#include "dlt_filetransfer.h"
#ifdef linux
-#define INOTIFY_SZ (sizeof(struct inotify_event))
-#define INOTIFY_LEN (INOTIFY_SZ + NAME_MAX + 1)
+# define INOTIFY_SZ (sizeof(struct inotify_event))
+# define INOTIFY_LEN (INOTIFY_SZ + NAME_MAX + 1)
#endif
-#define Z_CHUNK_SZ 1024*128
+#define Z_CHUNK_SZ 1024 * 128
#define COMPRESS_EXTENSION ".gz"
#define SUBDIR_COMPRESS ".tocompress"
#define SUBDIR_TOSEND ".tosend"
@@ -80,8 +80,8 @@
extern DltSystemThreads threads;
-// From dlt_filetransfer
-extern uint32_t getFileSerialNumber(const char* file, int *ok);
+/* From dlt_filetransfer */
+extern uint32_t getFileSerialNumber(const char *file, int *ok);
DLT_IMPORT_CONTEXT(dltsystem)
DLT_DECLARE_CONTEXT(filetransferContext)
@@ -96,11 +96,12 @@ s_ft_inotify ino;
#endif
-char *origin_name(char *src){
- if (strlen( (char*) basename(src)) > 10 ){
- return (char*)(basename(src)+10);
+char *origin_name(char *src)
+{
+ if (strlen((char *)basename(src)) > 10) {
+ return (char *)(basename(src) + 10);
}
- else{
+ else {
DLT_LOG(dltsystem, DLT_LOG_ERROR,
DLT_STRING("dlt-system-filetransfer, error in recreating origin name!"));
return NULL;
@@ -114,68 +115,73 @@ char *unique_name(char *src)
time_t t = time(NULL);
int ok;
uint32_t l = getFileSerialNumber(src, &ok) ^ t;
- if (!ok){
- return (char*) NULL;
- }
+
+ if (!ok)
+ return (char *)NULL;
char *basename_f = basename(src);
- // Length of ULONG_MAX + 1
- int len = 11+strlen(basename_f);
- if (len > NAME_MAX){
+ /* Length of ULONG_MAX + 1 */
+ int len = 11 + strlen(basename_f);
+
+ if (len > NAME_MAX) {
DLT_LOG(dltsystem, DLT_LOG_WARN,
- DLT_STRING("dlt-system-filetransfer, unique name creation needs to shorten the filename:"),DLT_STRING(basename_f));
+ DLT_STRING("dlt-system-filetransfer, unique name creation needs to shorten the filename:"),
+ DLT_STRING(basename_f));
len = NAME_MAX;
}
char *ret = malloc(len);
MALLOC_ASSERT(ret);
- snprintf(ret, len, "%010" PRIu32 "%s", l,basename_f);
+ snprintf(ret, len, "%010" PRIu32 "%s", l, basename_f);
return ret;
}
/**
- * Function which only calls the relevant part to transfer the payload
- */
+ * Function which only calls the relevant part to transfer the payload
+ */
-void send_dumped_file(FiletransferOptions const *opts,char *dst_tosend)
+void send_dumped_file(FiletransferOptions const *opts, char *dst_tosend)
{
- // check if a client is connected to the deamon. If not, try again in a second
- while(dlt_get_log_state() != 1)
+ /* check if a client is connected to the deamon. If not, try again in a second */
+ while (dlt_get_log_state() != 1)
sleep(1);
char *fn = origin_name(dst_tosend);
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-filetransfer, sending dumped file:"),DLT_STRING(fn));
- if(dlt_user_log_file_header_alias(&filetransferContext, dst_tosend, fn) == 0)
- {
+ DLT_STRING("dlt-system-filetransfer, sending dumped file:"), DLT_STRING(fn));
+
+ if (dlt_user_log_file_header_alias(&filetransferContext, dst_tosend, fn) == 0) {
int pkgcount = dlt_user_log_file_packagesCount(&filetransferContext, dst_tosend);
int lastpkg = 0;
int success = 1;
- while(lastpkg < pkgcount)
- {
+
+ while (lastpkg < pkgcount) {
int total = 2;
int used = 2;
dlt_user_check_buffer(&total, &used);
- while((total-used) < (total/2))
- {
+
+ while ((total - used) < (total / 2)) {
struct timespec t;
t.tv_sec = 0;
- t.tv_nsec = 1000000ul*opts->TimeoutBetweenLogs;
+ t.tv_nsec = 1000000ul * opts->TimeoutBetweenLogs;
nanosleep(&t, NULL);
dlt_user_log_resend_buffer();
dlt_user_check_buffer(&total, &used);
}
+
lastpkg++;
- if(dlt_user_log_file_data(&filetransferContext, dst_tosend, lastpkg, opts->TimeoutBetweenLogs) < 0)
- {
+
+ if (dlt_user_log_file_data(&filetransferContext, dst_tosend, lastpkg, opts->TimeoutBetweenLogs) < 0) {
success = 0;
break;
}
}
+
if (success)
dlt_user_log_file_end(&filetransferContext, dst_tosend, 1);
}
+
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
DLT_STRING("dlt-system-filetransfer, sent dumped file"));
}
@@ -187,31 +193,33 @@ void send_dumped_file(FiletransferOptions const *opts,char *dst_tosend)
* @param src File to be sent
* @param dst destination where to compress the file
* @param level of compression
-**/
+ **/
int compress_file_to(char *src, char *dst, int level)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-filetransfer, compressing file from:"),DLT_STRING(src),DLT_STRING("to:"),DLT_STRING(dst));
+ DLT_LOG(dltsystem,
+ DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-filetransfer, compressing file from:"),
+ DLT_STRING(src),
+ DLT_STRING("to:"),
+ DLT_STRING(dst));
char *buf;
char dst_mode[8];
- snprintf(dst_mode,8, "wb%d", level);
+ snprintf(dst_mode, 8, "wb%d", level);
gzFile dst_file;
FILE *src_file;
dst_file = gzopen(dst, dst_mode);
- if(dst_file == Z_NULL)
- {
+
+ if (dst_file == Z_NULL)
return -1;
- }
src_file = fopen(src, "r");
- if(src_file == NULL)
- {
+ if (src_file == NULL) {
gzclose(dst_file);
return -1;
@@ -220,22 +228,23 @@ int compress_file_to(char *src, char *dst, int level)
buf = malloc(Z_CHUNK_SZ);
MALLOC_ASSERT(buf);
- while(!feof(src_file))
- {
+ while (!feof(src_file)) {
int read = fread(buf, 1, Z_CHUNK_SZ, src_file);
- if(ferror(src_file))
- {
+
+ if (ferror(src_file)) {
free(buf);
gzclose(dst_file);
fclose(src_file);
return -1;
}
+
gzwrite(dst_file, buf, read);
}
- if(remove(src) < 0)
+ if (remove(src) < 0)
DLT_LOG(dltsystem, DLT_LOG_WARN, DLT_STRING("Could not remove file"), DLT_STRING(src));
+
free(buf);
fclose(src_file);
gzclose(dst_file);
@@ -243,7 +252,7 @@ int compress_file_to(char *src, char *dst, int level)
return 0;
}
-//!Sends one file over DLT.
+/*!Sends one file over DLT. */
/**
* If configured in opts, compresses it, then sends it.
* uses subdirecties for compressing and before sending, to avoid that those files get changed in the meanwhile
@@ -255,49 +264,46 @@ int send_one(char *src, FiletransferOptions const *opts, int which)
DLT_STRING("dlt-system-filetransfer, sending a file."));
sleep(opts->TimeDelay);
- // Prepare all needed file names
+ /* Prepare all needed file names */
char *fn = basename(src);
- if (fn == NULL)
- {
+
+ if (fn == NULL) {
DLT_LOG(dltsystem,
DLT_LOG_ERROR,
DLT_STRING("basename not valid"));
return -1;
}
- char *fdir = strndup(src,PATH_MAX);
+ char *fdir = strndup(src, PATH_MAX);
MALLOC_ASSERT(fdir);
- fdir = dirname(fdir);//dirname overwrites its argument anyway
- char *dst_tosend;//file which is going to be sent
+ fdir = dirname(fdir);/*dirname overwrites its argument anyway */
+ char *dst_tosend;/*file which is going to be sent */
- char *rn = unique_name(src);//new unique filename based on inode
+ char *rn = unique_name(src);/*new unique filename based on inode */
- if (rn == NULL)
- {
+ if (rn == NULL) {
DLT_LOG(dltsystem,
DLT_LOG_ERROR,
DLT_STRING("file information not available, may be file got overwritten"));
return -1;
}
- // Compress if needed
- if(opts->Compression[which] > 0)
- {
+ /* Compress if needed */
+ if (opts->Compression[which] > 0) {
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
DLT_STRING("dlt-system-filetransfer, Moving file to tmp directory for compressing it."));
- char *dst_tocompress;//file which is going to be compressed, the compressed one is named dst_tosend
+ char *dst_tocompress;/*file which is going to be compressed, the compressed one is named dst_tosend */
- int len = strlen(fdir)+strlen(SUBDIR_COMPRESS)+strlen(rn)+3;//the filename in .tocompress +2 for 2*"/", +1 for \0
+ int len = strlen(fdir) + strlen(SUBDIR_COMPRESS) + strlen(rn) + 3;/*the filename in .tocompress +2 for 2*"/", +1 for \0 */
dst_tocompress = malloc(len);
MALLOC_ASSERT(dst_tocompress);
- snprintf(dst_tocompress,len,"%s/%s/%s",fdir,SUBDIR_COMPRESS,rn);
+ snprintf(dst_tocompress, len, "%s/%s/%s", fdir, SUBDIR_COMPRESS, rn);
- //moving in subdir, from where it can be compressed
- if(rename(src, dst_tocompress) < 0)
- {
+ /*moving in subdir, from where it can be compressed */
+ if (rename(src, dst_tocompress) < 0) {
DLT_LOG(dltsystem, DLT_LOG_ERROR,
DLT_STRING("Could not move file"),
DLT_STRING(src),
@@ -307,35 +313,38 @@ int send_one(char *src, FiletransferOptions const *opts, int which)
free(fdir);
return -1;
}
- len = strlen(fdir)+strlen(SUBDIR_TOSEND)+strlen(rn)+strlen(COMPRESS_EXTENSION)+3;//the resulting filename in .tosend +2 for 2*"/", +1 for \0
+
+ len = strlen(fdir) + strlen(SUBDIR_TOSEND) + strlen(rn) + strlen(COMPRESS_EXTENSION) + 3;/*the resulting filename in .tosend +2 for 2*"/", +1 for \0 */
dst_tosend = malloc(len);
MALLOC_ASSERT(dst_tosend);
- snprintf(dst_tosend,len,"%s/%s/%s%s",fdir,SUBDIR_TOSEND,rn,COMPRESS_EXTENSION);
+ snprintf(dst_tosend, len, "%s/%s/%s%s", fdir, SUBDIR_TOSEND, rn, COMPRESS_EXTENSION);
- if (compress_file_to(dst_tocompress,dst_tosend, opts->CompressionLevel[which]) != 0){
+ if (compress_file_to(dst_tocompress, dst_tosend, opts->CompressionLevel[which]) != 0) {
free(rn);
free(dst_tosend);
free(dst_tocompress);
free(fdir);
return -1;
}
+
free(dst_tocompress);
}
- else{
- //move it directly into "tosend"
+ else {
+ /*move it directly into "tosend" */
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
DLT_STRING("dlt-system-filetransfer, Moving file to tmp directory."));
- int len = strlen(fdir)+strlen(SUBDIR_TOSEND)+strlen(rn)+3;
- dst_tosend = malloc(len);//the resulting filename in .tosend +2 for 2*"/", +1 for \0
+ int len = strlen(fdir) + strlen(SUBDIR_TOSEND) + strlen(rn) + 3;
+ dst_tosend = malloc(len);/*the resulting filename in .tosend +2 for 2*"/", +1 for \0 */
- snprintf(dst_tosend,len,"%s/%s/%s",fdir,SUBDIR_TOSEND,rn);
+ snprintf(dst_tosend, len, "%s/%s/%s", fdir, SUBDIR_TOSEND, rn);
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-filetransfer, Rename:"),DLT_STRING(src),DLT_STRING("to: "),DLT_STRING(dst_tosend));
- //moving in subdir, from where it can be compressed
- if(rename(src, dst_tosend) < 0)
- {
+ DLT_STRING("dlt-system-filetransfer, Rename:"), DLT_STRING(src), DLT_STRING("to: "),
+ DLT_STRING(dst_tosend));
+
+ /*moving in subdir, from where it can be compressed */
+ if (rename(src, dst_tosend) < 0) {
DLT_LOG(dltsystem, DLT_LOG_ERROR,
DLT_STRING("Could not move file"),
DLT_STRING(src),
@@ -345,13 +354,12 @@ int send_one(char *src, FiletransferOptions const *opts, int which)
free(fdir);
return -1;
}
-
}
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
DLT_STRING("dlt-system-filetransfer, File ready to send"));
- send_dumped_file(opts,dst_tosend);
+ send_dumped_file(opts, dst_tosend);
free(rn);
@@ -362,192 +370,195 @@ int send_one(char *src, FiletransferOptions const *opts, int which)
}
-int flush_dir_send(FiletransferOptions const *opts, const char *compress_dir, const char *send_dir){
+int flush_dir_send(FiletransferOptions const *opts, const char *compress_dir, const char *send_dir)
+{
struct dirent *dp;
DIR *dir;
dir = opendir(send_dir);
- if(dir != NULL)
- {
- while((dp = readdir(dir)) != NULL)
- {
- if(dp->d_type != DT_REG)
+ if (dir != NULL) {
+ while ((dp = readdir(dir)) != NULL) {
+ if (dp->d_type != DT_REG)
continue;
+
char *fn;
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-filetransfer, old compressed file found in send directory:"),DLT_STRING(dp->d_name));
- int len = strlen(send_dir)+strlen(dp->d_name)+2;
+ DLT_STRING("dlt-system-filetransfer, old compressed file found in send directory:"),
+ DLT_STRING(dp->d_name));
+ int len = strlen(send_dir) + strlen(dp->d_name) + 2;
fn = malloc(len);
MALLOC_ASSERT(fn);
- snprintf(fn,len, "%s/%s", send_dir, dp->d_name);
-
+ snprintf(fn, len, "%s/%s", send_dir, dp->d_name);
- //if we have a file here and in the to_compress dir, we delete the to_send file: we can not be sure, that it has been properly compressed!
- if (!strncmp( dp->d_name+strlen(dp->d_name)-strlen(COMPRESS_EXTENSION),COMPRESS_EXTENSION,strlen(COMPRESS_EXTENSION)))
- {
+ /*if we have a file here and in the to_compress dir, we delete the to_send file: we can not be sure, that it has been properly compressed! */
+ if (!strncmp(dp->d_name + strlen(dp->d_name) - strlen(COMPRESS_EXTENSION), COMPRESS_EXTENSION,
+ strlen(COMPRESS_EXTENSION))) {
- //ends with ".gz"
- //old file name (not: path) would have been:
- char tmp[strlen(dp->d_name)-strlen(COMPRESS_EXTENSION)+1];
- strncpy(tmp,dp->d_name,strlen(dp->d_name)-strlen(COMPRESS_EXTENSION));
- tmp[strlen(dp->d_name)-strlen(COMPRESS_EXTENSION)]='\0';
+ /*ends with ".gz" */
+ /*old file name (not: path) would have been: */
+ char tmp[strlen(dp->d_name) - strlen(COMPRESS_EXTENSION) + 1];
+ strncpy(tmp, dp->d_name, strlen(dp->d_name) - strlen(COMPRESS_EXTENSION));
+ tmp[strlen(dp->d_name) - strlen(COMPRESS_EXTENSION)] = '\0';
- int len = strlen(tmp)+strlen(compress_dir)+1+1;//2 sizes + 1*"/" + \0
+ int len = strlen(tmp) + strlen(compress_dir) + 1 + 1;/*2 sizes + 1*"/" + \0 */
char *path_uncompressed = malloc(len);
MALLOC_ASSERT(path_uncompressed);
- snprintf(path_uncompressed,len,"%s/%s",compress_dir,tmp);
+ snprintf(path_uncompressed, len, "%s/%s", compress_dir, tmp);
struct stat sb;
- if (stat(path_uncompressed,&sb)==-1)
- {
- //uncompressed equivalent does not exist. We can send it out.
+
+ if (stat(path_uncompressed, &sb) == -1) {
+ /*uncompressed equivalent does not exist. We can send it out. */
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
DLT_STRING("dlt-system-filetransfer, sending file."));
- send_dumped_file(opts,fn);
+ send_dumped_file(opts, fn);
}
- else
- {
- //There is an uncompressed file. Compression seems to have been interrupted -> delete the compressed file instead of sending it!
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-filetransfer, uncompressed version exists. Deleting partially compressed version."));
- if (sb.st_mode & S_IFREG)
- {
+ else {
+ /*There is an uncompressed file. Compression seems to have been interrupted -> delete the compressed file instead of sending it! */
+ DLT_LOG(dltsystem,
+ DLT_LOG_DEBUG,
+ DLT_STRING(
+ "dlt-system-filetransfer, uncompressed version exists. Deleting partially compressed version."));
+ if (sb.st_mode & S_IFREG) {
- if( remove(fn ) != 0 )
- {
- //"Error deleting file". Continue? If we would cancel, maybe the dump is never sent! Deletion would again be tried in next LC.
+ if (remove(fn) != 0)
+ /*"Error deleting file". Continue? If we would cancel, maybe the dump is never sent! Deletion would again be tried in next LC. */
DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("Error deleting file:"),DLT_STRING(fn));
- }
+ DLT_STRING("Error deleting file:"), DLT_STRING(fn));
}
- else
- {
- //"Oldfile is a not reg file. Is this possible? Can we compress a directory?: %s\n",path_uncompressed);
+ else {
+ /*"Oldfile is a not reg file. Is this possible? Can we compress a directory?: %s\n",path_uncompressed); */
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-filetransfer, Oldfile is a not regular file! Do we have a problem?"),DLT_STRING(fn));
+ DLT_STRING(
+ "dlt-system-filetransfer, Oldfile is a not regular file! Do we have a problem?"),
+ DLT_STRING(fn));
}
-
}
- free(path_uncompressed);//it is no more used. It would be transferred in next step.
- }//it is a .gz file
- else{
- //uncompressed file. We can just resend it, the action to put it here was a move action.
+
+ free(path_uncompressed);/*it is no more used. It would be transferred in next step. */
+ }/*it is a .gz file */
+ else {
+ /*uncompressed file. We can just resend it, the action to put it here was a move action. */
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-filetransfer, Sending uncompressed file from previous LC."),DLT_STRING(fn));
- send_dumped_file(opts,fn);
+ DLT_STRING("dlt-system-filetransfer, Sending uncompressed file from previous LC."),
+ DLT_STRING(fn));
+ send_dumped_file(opts, fn);
}
+
free(fn);
}
}
- else
- {
+ else {
DLT_LOG(dltsystem, DLT_LOG_ERROR,
DLT_STRING("Could not open directory"),
DLT_STRING(send_dir));
return -1;
}
- closedir(dir);//end: send_dir
+
+ closedir(dir);/*end: send_dir */
return 0;
}
-int flush_dir_compress(FiletransferOptions const *opts, int which, const char *compress_dir, const char *send_dir){
+int flush_dir_compress(FiletransferOptions const *opts, int which, const char *compress_dir, const char *send_dir)
+{
- //check for files in compress_dir. Assumption: a file which lies here, should have been compressed, but that action was interrupted.
- //As it can arrive here only by a rename, it is most likely to be a complete file
+ /*check for files in compress_dir. Assumption: a file which lies here, should have been compressed, but that action was interrupted. */
+ /*As it can arrive here only by a rename, it is most likely to be a complete file */
struct dirent *dp;
DIR *dir;
dir = opendir(compress_dir);
- if(dir != NULL)
- {
- while((dp = readdir(dir)) != NULL)
- {
- if(dp->d_type != DT_REG)
+
+ if (dir != NULL) {
+ while ((dp = readdir(dir)) != NULL) {
+ if (dp->d_type != DT_REG)
continue;
+
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
DLT_STRING("dlt-system-filetransfer, old file found in compress-directory."));
- //compress file into to_send dir
- int len = strlen(compress_dir)+strlen(dp->d_name)+2;
+ /*compress file into to_send dir */
+ int len = strlen(compress_dir) + strlen(dp->d_name) + 2;
char *cd_filename = malloc(len);
MALLOC_ASSERT(cd_filename);
- snprintf(cd_filename,len,"%s/%s",compress_dir,dp->d_name);
+ snprintf(cd_filename, len, "%s/%s", compress_dir, dp->d_name);
- len = strlen(send_dir)+strlen(dp->d_name)+strlen(COMPRESS_EXTENSION)+2;
- char *dst_tosend = malloc(len);//the resulting filename in .tosend +2 for 1*"/", +1 for \0 + .gz
+ len = strlen(send_dir) + strlen(dp->d_name) + strlen(COMPRESS_EXTENSION) + 2;
+ char *dst_tosend = malloc(len);/*the resulting filename in .tosend +2 for 1*"/", +1 for \0 + .gz */
MALLOC_ASSERT(dst_tosend);
- snprintf(dst_tosend,len,"%s/%s%s",send_dir,dp->d_name,COMPRESS_EXTENSION);
+ snprintf(dst_tosend, len, "%s/%s%s", send_dir, dp->d_name, COMPRESS_EXTENSION);
- if (compress_file_to(cd_filename,dst_tosend, opts->CompressionLevel[which]) != 0){
+ if (compress_file_to(cd_filename, dst_tosend, opts->CompressionLevel[which]) != 0) {
free(dst_tosend);
free(cd_filename);
closedir(dir);
return -1;
}
- //send file
- send_dumped_file(opts,dst_tosend);
+ /*send file */
+ send_dumped_file(opts, dst_tosend);
free(dst_tosend);
free(cd_filename);
}
}
- else
- {
+ else {
DLT_LOG(dltsystem, DLT_LOG_ERROR,
DLT_STRING("Could not open directory"),
DLT_STRING(compress_dir));
return -1;
}
- closedir(dir);//end: compress_dir
+
+ closedir(dir);/*end: compress_dir */
return 0;
}
-int flush_dir_original(FiletransferOptions const *opts, int which){
+int flush_dir_original(FiletransferOptions const *opts, int which)
+{
struct dirent *dp;
DIR *dir;
const char *sdir = opts->Directory[which];
dir = opendir(sdir);
- if(dir != NULL)
- {
- while((dp = readdir(dir)) != NULL)
- {
- if(dp->d_type != DT_REG){
- //we don't send directories
+
+ if (dir != NULL) {
+ while ((dp = readdir(dir)) != NULL) {
+ if (dp->d_type != DT_REG)
+ /*we don't send directories */
continue;
- }
+
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
DLT_STRING("dlt-system-filetransfer, old file found in directory."));
- int len = strlen(sdir)+strlen(dp->d_name)+2;
+ int len = strlen(sdir) + strlen(dp->d_name) + 2;
char *fn = malloc(len);
MALLOC_ASSERT(fn);
- snprintf(fn,len, "%s/%s", sdir, dp->d_name);
- if(send_one(fn, opts, which) < 0)
- {
+ snprintf(fn, len, "%s/%s", sdir, dp->d_name);
+
+ if (send_one(fn, opts, which) < 0) {
closedir(dir);
free(fn);
return -1;
}
+
free(fn);
}
}
- else
- {
+ else {
DLT_LOG(dltsystem, DLT_LOG_ERROR,
DLT_STRING("Could not open directory"),
DLT_STRING(sdir));
return -1;
}
+
closedir(dir);
return 0;
}
-//!Cleans the surveyed directories and subdirectories. Sends residing files into trace
+/*!Cleans the surveyed directories and subdirectories. Sends residing files into trace */
/**
* @param opts FiletransferOptions
* @param which which directory is affected -> position in list of opts->Directory
@@ -562,42 +573,41 @@ int flush_dir(FiletransferOptions const *opts, int which)
char *compress_dir;
char *send_dir;
- int len = strlen(opts->Directory[which])+strlen(SUBDIR_COMPRESS)+2;
+ int len = strlen(opts->Directory[which]) + strlen(SUBDIR_COMPRESS) + 2;
compress_dir = malloc (len);
MALLOC_ASSERT(compress_dir);
- snprintf(compress_dir,len,"%s/%s",opts->Directory[which],SUBDIR_COMPRESS);
+ snprintf(compress_dir, len, "%s/%s", opts->Directory[which], SUBDIR_COMPRESS);
- len = strlen(opts->Directory[which])+strlen(SUBDIR_TOSEND)+2;
+ len = strlen(opts->Directory[which]) + strlen(SUBDIR_TOSEND) + 2;
send_dir = malloc (len);
MALLOC_ASSERT(send_dir);
- snprintf(send_dir,len,"%s/%s",opts->Directory[which],SUBDIR_TOSEND);
+ snprintf(send_dir, len, "%s/%s", opts->Directory[which], SUBDIR_TOSEND);
- //1st: scan the tosend directory.
- if ( 0 != flush_dir_send(opts, compress_dir, send_dir) ){
+ /*1st: scan the tosend directory. */
+ if (0 != flush_dir_send(opts, compress_dir, send_dir)) {
free(send_dir);
free(compress_dir);
return -1;
}
- //1nd: scan the tocompress directory.
- if (0 != flush_dir_compress(opts, which, compress_dir, send_dir)){
+ /*1nd: scan the tocompress directory. */
+ if (0 != flush_dir_compress(opts, which, compress_dir, send_dir)) {
free(send_dir);
free(compress_dir);
return -1;
}
- free(send_dir);//no more used
+ free(send_dir);/*no more used */
free(compress_dir);
- //last step: scan the original directory - we can reuse the send_one function
- if ( 0 != flush_dir_original(opts,which)){
+ /*last step: scan the original directory - we can reuse the send_one function */
+ if (0 != flush_dir_original(opts, which))
return -1;
- }
return 0;
}
-//!Initializes the surveyed directories
+/*!Initializes the surveyed directories */
/**On startup, the inotifiy handlers are created, and existing files shall be sent into DLT stream
* @param opts FiletransferOptions
* @return Returns 0 if everything was okay. If there was a failure a value < 0 will be returned.
@@ -610,51 +620,61 @@ int init_filetransfer_dirs(FiletransferOptions const *opts)
#ifdef linux
ino.handle = inotify_init();
- if(ino.handle < 0)
- {
+ if (ino.handle < 0) {
DLT_LOG(filetransferContext, DLT_LOG_FATAL,
DLT_STRING("Failed to initialize inotify in dlt-system file transfer."));
return -1;
}
+
#endif
- for(i = 0;i < opts->Count;i++)
- {
- //create subdirectories for processing the files
+ for (i = 0; i < opts->Count; i++) {
+ /*create subdirectories for processing the files */
char *subdirpath;
- int len = strlen(opts->Directory[i])+strlen(SUBDIR_COMPRESS)+2;
- subdirpath= malloc (len);
+ int len = strlen(opts->Directory[i]) + strlen(SUBDIR_COMPRESS) + 2;
+ subdirpath = malloc (len);
MALLOC_ASSERT(subdirpath);
- snprintf(subdirpath,len,"%s/%s",opts->Directory[i],SUBDIR_COMPRESS);
- int ret = mkdir(subdirpath,0777);
-
- if (0 != ret && EEXIST != errno){
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-filetransfer, error creating subdirectory: "),DLT_STRING(subdirpath),DLT_STRING(" Errorcode: "),DLT_INT(errno));
+ snprintf(subdirpath, len, "%s/%s", opts->Directory[i], SUBDIR_COMPRESS);
+ int ret = mkdir(subdirpath, 0777);
+
+ if ((0 != ret) && (EEXIST != errno)) {
+ DLT_LOG(dltsystem,
+ DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-filetransfer, error creating subdirectory: "),
+ DLT_STRING(subdirpath),
+ DLT_STRING(" Errorcode: "),
+ DLT_INT(errno));
free (subdirpath);
return -1;
}
+
free(subdirpath);
- len = strlen(opts->Directory[i])+strlen(SUBDIR_TOSEND)+2;
- subdirpath= malloc (len);
+ len = strlen(opts->Directory[i]) + strlen(SUBDIR_TOSEND) + 2;
+ subdirpath = malloc (len);
MALLOC_ASSERT(subdirpath);
- snprintf(subdirpath,len,"%s/%s",opts->Directory[i],SUBDIR_TOSEND);
- ret = mkdir(subdirpath,0777);
- if (0 != ret && EEXIST != errno){
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-filetransfer, error creating subdirectory: "),DLT_STRING(subdirpath),DLT_STRING(" Errorcode: "),DLT_INT(errno));
+ snprintf(subdirpath, len, "%s/%s", opts->Directory[i], SUBDIR_TOSEND);
+ ret = mkdir(subdirpath, 0777);
+
+ if ((0 != ret) && (EEXIST != errno)) {
+ DLT_LOG(dltsystem,
+ DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-filetransfer, error creating subdirectory: "),
+ DLT_STRING(subdirpath),
+ DLT_STRING(" Errorcode: "),
+ DLT_INT(errno));
free (subdirpath);
return -1;
}
+
free(subdirpath);
#ifdef linux
ino.fd[i] = inotify_add_watch(ino.handle, opts->Directory[i],
- IN_CLOSE_WRITE|IN_MOVED_TO);
- if(ino.fd[i] < 0)
- {
+ IN_CLOSE_WRITE | IN_MOVED_TO);
+
+ if (ino.fd[i] < 0) {
char buf[1024];
snprintf(buf, 1024, "Failed to add inotify watch to directory %s in dlt-system file transfer.",
opts->Directory[i]);
@@ -662,11 +682,13 @@ int init_filetransfer_dirs(FiletransferOptions const *opts)
DLT_STRING(buf));
return -1;
}
+
#endif
flush_dir(opts, i);
}
+
return 0;
}
@@ -676,44 +698,50 @@ int wait_for_files(FiletransferOptions const *opts)
DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, waiting for files."));
static char buf[INOTIFY_LEN];
ssize_t len = read(ino.handle, buf, INOTIFY_LEN);
- if(len < 0)
- {
+
+ if (len < 0) {
DLT_LOG(filetransferContext, DLT_LOG_ERROR,
DLT_STRING("Error while waiting for files in dlt-system file transfer."));
return -1;
}
unsigned int i = 0;
- while(i < (len-INOTIFY_SZ))
- {
+
+ while (i < (len - INOTIFY_SZ)) {
struct inotify_event *ie = (struct inotify_event *)&buf[i];
- if(ie->len > 0)
- {
- if((ie->mask & IN_CLOSE_WRITE) || (ie->mask & IN_MOVED_TO))
- {
+
+ if (ie->len > 0) {
+ if ((ie->mask & IN_CLOSE_WRITE) || (ie->mask & IN_MOVED_TO)) {
int j;
- for(j = 0;j < opts->Count;j++)
- {
- if(ie->wd == ino.fd[j])
- {
- DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, found new file."), DLT_STRING(ie->name));
- int length = strlen(opts->Directory[j])+ie->len+1;
- if (length > PATH_MAX)
- {
- DLT_LOG(filetransferContext, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-filetransfer: Very long path for file transfer. Cancelling transfer! Length is: "),DLT_INT(length));
+
+ for (j = 0; j < opts->Count; j++)
+ if (ie->wd == ino.fd[j]) {
+ DLT_LOG(dltsystem,
+ DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-filetransfer, found new file."),
+ DLT_STRING(ie->name));
+ int length = strlen(opts->Directory[j]) + ie->len + 1;
+
+ if (length > PATH_MAX) {
+ DLT_LOG(filetransferContext,
+ DLT_LOG_ERROR,
+ DLT_STRING(
+ "dlt-system-filetransfer: Very long path for file transfer. Cancelling transfer! Length is: "),
+ DLT_INT(length));
return -1;
}
+
char *tosend = malloc(length);
- snprintf(tosend,length, "%s/%s", opts->Directory[j], ie->name);
+ snprintf(tosend, length, "%s/%s", opts->Directory[j], ie->name);
send_one(tosend, opts, j);
free(tosend);
}
- }
}
}
+
i += INOTIFY_SZ + ie->len;
}
+
#endif
return 0;
}
@@ -721,22 +749,21 @@ int wait_for_files(FiletransferOptions const *opts)
void filetransfer_thread(void *v_conf)
{
DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, in thread."));
- DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf;
+ DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf;
DLT_REGISTER_CONTEXT(filetransferContext, conf->Filetransfer.ContextId,
"File transfer manager.");
sleep(conf->Filetransfer.TimeStartup);
- if(init_filetransfer_dirs(&(conf->Filetransfer)) < 0)
+ if (init_filetransfer_dirs(&(conf->Filetransfer)) < 0)
return;
- while(!threads.shutdown)
- {
- if(wait_for_files(&(conf->Filetransfer)) < 0)
- {
+ while (!threads.shutdown) {
+ if (wait_for_files(&(conf->Filetransfer)) < 0) {
DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while waiting files. File transfer shutdown."));
return;
}
+
sleep(conf->Filetransfer.TimeDelay);
}
}
diff --git a/src/system/dlt-system-journal.c b/src/system/dlt-system-journal.c
index 5d9d7ef..32c6e13 100644
--- a/src/system/dlt-system-journal.c
+++ b/src/system/dlt-system-journal.c
@@ -65,12 +65,12 @@ extern DltSystemThreads threads;
#define DLT_SYSTEM_JOURNAL_BUFFER_SIZE_BIG 2048
#define DLT_SYSTEM_JOURNAL_ASCII_FIRST_VISIBLE_CHARACTER 31
-#define DLT_SYSTEM_JOURNAL_BOOT_ID_MAX_LENGTH 9+32+1
+#define DLT_SYSTEM_JOURNAL_BOOT_ID_MAX_LENGTH 9 + 32 + 1
typedef struct
{
- char real[DLT_SYSTEM_JOURNAL_BUFFER_SIZE];
- char monotonic[DLT_SYSTEM_JOURNAL_BUFFER_SIZE];
+ char real[DLT_SYSTEM_JOURNAL_BUFFER_SIZE];
+ char monotonic[DLT_SYSTEM_JOURNAL_BUFFER_SIZE];
} MessageTimestamp;
DLT_IMPORT_CONTEXT(dltsystem)
@@ -78,327 +78,321 @@ DLT_DECLARE_CONTEXT(journalContext)
int journal_checkUserBufferForFreeSpace()
{
- int total_size, used_size;
+ int total_size, used_size;
- dlt_user_check_buffer(&total_size, &used_size);
+ dlt_user_check_buffer(&total_size, &used_size);
- if((total_size - used_size) < (total_size/2))
- {
- return -1;
- }
- return 1;
+ if ((total_size - used_size) < (total_size / 2))
+ return -1;
+
+ return 1;
}
-int dlt_system_journal_get(sd_journal* j,char *target,const char *field,size_t max_size)
+int dlt_system_journal_get(sd_journal *j, char *target, const char *field, size_t max_size)
{
- char *data;
- size_t length;
- int error_code;
- size_t field_size;
-
- // pre check parameters
- if(max_size<1 || target == 0 || field == 0 || j == 0)
- return -1;
-
- // intialise empty target
- target[0]=0;
-
- // get data from journal
- error_code = sd_journal_get_data(j, field,(const void **) &data, &length);
-
- // check if an error
- if(error_code)
- return error_code;
-
- // calculate field size
- field_size = strlen(field)+1;
-
- //check length
- if(length<field_size)
- return -1;
-
- // copy string
- if(max_size<=(length-field_size))
- {
- // truncate
- strncpy(target,data+field_size,max_size-1);
- target[max_size-1]=0;
- }
- else
- {
- // full copy
- strncpy(target,data+field_size,length-field_size);
- target[length-field_size]=0;
-
- }
-
- // debug messages
- //printf("%s = %s\n",field,target);
-
- // Success
- return 0;
+ char *data;
+ size_t length;
+ int error_code;
+ size_t field_size;
+
+ /* pre check parameters */
+ if ((max_size < 1) || (target == 0) || (field == 0) || (j == 0))
+ return -1;
+
+ /* intialise empty target */
+ target[0] = 0;
+
+ /* get data from journal */
+ error_code = sd_journal_get_data(j, field, (const void **)&data, &length);
+
+ /* check if an error */
+ if (error_code)
+ return error_code;
+
+ /* calculate field size */
+ field_size = strlen(field) + 1;
+
+ /*check length */
+ if (length < field_size)
+ return -1;
+
+ /* copy string */
+ if (max_size <= (length - field_size)) {
+ /* truncate */
+ strncpy(target, data + field_size, max_size - 1);
+ target[max_size - 1] = 0;
+ }
+ else {
+ /* full copy */
+ strncpy(target, data + field_size, length - field_size);
+ target[length - field_size] = 0;
+
+ }
+
+ /* debug messages */
+ /*printf("%s = %s\n",field,target); */
+
+ /* Success */
+ return 0;
}
void dlt_system_journal_get_timestamp(sd_journal *journal, MessageTimestamp *timestamp)
{
- int ret = 0;
- uint64_t time_secs = 0;
- uint64_t time_usecs = 0;
- struct tm * timeinfo = NULL;
-
- char buffer_realtime[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 };
- char buffer_realtime_formatted[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 };
- char buffer_monotime[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 };
-
- /* Try to get realtime from message source and if not successful try to get realtime from journal entry */
- ret = dlt_system_journal_get(journal, buffer_realtime, "_SOURCE_REALTIME_TIMESTAMP", sizeof(buffer_realtime));
- if (ret == 0 && strlen(buffer_realtime) > 0)
- {
- errno = 0;
- time_usecs = strtoull(buffer_realtime, NULL, 10);
- if (errno != 0)
- time_usecs = 0;
- }
- else
- {
- if ((ret = sd_journal_get_realtime_usec(journal, &time_usecs)) < 0)
- {
- DLT_LOG(dltsystem, DLT_LOG_WARN,
- DLT_STRING("dlt-system-journal failed to get realtime: "),
- DLT_STRING(strerror(-ret)));
-
- /* just to be sure to have a defined value */
- time_usecs = 0;
- }
- }
-
- time_secs = time_usecs / 1000000;
- timeinfo = localtime((const time_t*) (&time_secs));
- strftime(buffer_realtime_formatted, sizeof(buffer_realtime_formatted), "%Y/%m/%d %H:%M:%S", timeinfo);
-
- snprintf(timestamp->real, sizeof(timestamp->real), "%s.%06"PRIu64, buffer_realtime_formatted, time_usecs % 1000000);
-
- /* Try to get monotonic time from message source and if not successful try to get monotonic time from journal entry */
- ret = dlt_system_journal_get(journal, buffer_monotime, "_SOURCE_MONOTONIC_TIMESTAMP", sizeof(buffer_monotime));
- if (ret == 0 && strlen(buffer_monotime) > 0)
- {
- errno = 0;
- time_usecs = strtoull(buffer_monotime, NULL, 10);
- if (errno != 0)
- time_usecs = 0;
- }
- else
- {
- if ((ret = sd_journal_get_monotonic_usec(journal, &time_usecs, NULL)) < 0)
- {
- DLT_LOG(dltsystem, DLT_LOG_WARN,
- DLT_STRING("dlt-system-journal failed to get monotonic time: "),
- DLT_STRING(strerror(-ret)));
-
- /* just to be sure to have a defined value */
- time_usecs = 0;
- }
- }
-
- snprintf(timestamp->monotonic, sizeof(timestamp->monotonic), "%"PRId64".%06"PRIu64, time_usecs / 1000000, time_usecs % 1000000);
+ int ret = 0;
+ uint64_t time_secs = 0;
+ uint64_t time_usecs = 0;
+ struct tm *timeinfo = NULL;
+
+ char buffer_realtime[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 };
+ char buffer_realtime_formatted[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 };
+ char buffer_monotime[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 };
+
+ /* Try to get realtime from message source and if not successful try to get realtime from journal entry */
+ ret = dlt_system_journal_get(journal, buffer_realtime, "_SOURCE_REALTIME_TIMESTAMP", sizeof(buffer_realtime));
+
+ if ((ret == 0) && (strlen(buffer_realtime) > 0)) {
+ errno = 0;
+ time_usecs = strtoull(buffer_realtime, NULL, 10);
+
+ if (errno != 0)
+ time_usecs = 0;
+ }
+ else if ((ret = sd_journal_get_realtime_usec(journal, &time_usecs)) < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_WARN,
+ DLT_STRING("dlt-system-journal failed to get realtime: "),
+ DLT_STRING(strerror(-ret)));
+
+ /* just to be sure to have a defined value */
+ time_usecs = 0;
+ }
+
+ time_secs = time_usecs / 1000000;
+ timeinfo = localtime((const time_t *)(&time_secs));
+ strftime(buffer_realtime_formatted, sizeof(buffer_realtime_formatted), "%Y/%m/%d %H:%M:%S", timeinfo);
+
+ snprintf(timestamp->real, sizeof(timestamp->real), "%s.%06" PRIu64, buffer_realtime_formatted,
+ time_usecs % 1000000);
+
+ /* Try to get monotonic time from message source and if not successful try to get monotonic time from journal entry */
+ ret = dlt_system_journal_get(journal, buffer_monotime, "_SOURCE_MONOTONIC_TIMESTAMP", sizeof(buffer_monotime));
+
+ if ((ret == 0) && (strlen(buffer_monotime) > 0)) {
+ errno = 0;
+ time_usecs = strtoull(buffer_monotime, NULL, 10);
+
+ if (errno != 0)
+ time_usecs = 0;
+ }
+ else if ((ret = sd_journal_get_monotonic_usec(journal, &time_usecs, NULL)) < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_WARN,
+ DLT_STRING("dlt-system-journal failed to get monotonic time: "),
+ DLT_STRING(strerror(-ret)));
+
+ /* just to be sure to have a defined value */
+ time_usecs = 0;
+ }
+
+ snprintf(timestamp->monotonic,
+ sizeof(timestamp->monotonic),
+ "%" PRId64 ".%06" PRIu64,
+ time_usecs / 1000000,
+ time_usecs % 1000000);
}
void journal_thread(void *v_conf)
{
- int r;
- sd_journal *j;
- char match[DLT_SYSTEM_JOURNAL_BOOT_ID_MAX_LENGTH] = "_BOOT_ID=";
- sd_id128_t boot_id;
-
- char buffer_process[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 },
- buffer_priority[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 },
- buffer_pid[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 },
- buffer_comm[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 },
+ int r;
+ sd_journal *j;
+ char match[DLT_SYSTEM_JOURNAL_BOOT_ID_MAX_LENGTH] = "_BOOT_ID=";
+ sd_id128_t boot_id;
+
+ char buffer_process[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 },
+ buffer_priority[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 },
+ buffer_pid[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 },
+ buffer_comm[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 },
buffer_message[DLT_SYSTEM_JOURNAL_BUFFER_SIZE_BIG] = { 0 },
- buffer_transport[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 };
+ buffer_transport[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 };
MessageTimestamp timestamp;
- int loglevel,systemd_loglevel;
- char* systemd_log_levels[] = { "Emergency","Alert","Critical","Error","Warning","Notice","Informational","Debug" };
-
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-journal, in thread."));
-
- DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf;
- DLT_REGISTER_CONTEXT(journalContext, conf->Journal.ContextId, "Journal Adapter");
-
- r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY/*SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_RUNTIME_ONLY*/);
- printf("journal open return %d\n", r);
- if (r < 0) {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-journal, cannot open journal:"),DLT_STRING(strerror(-r)));
- printf("journal open failed: %s\n", strerror(-r));
- return;
- }
-
- if(conf->Journal.CurrentBoot)
- {
- /* show only current boot entries */
- r = sd_id128_get_boot(&boot_id);
- if(r<0)
- {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-journal failed to get boot id:"),DLT_STRING(strerror(-r)));
- sd_journal_close(j);
- return;
-
- }
- sd_id128_to_string(boot_id, match + 9);
- r = sd_journal_add_match(j,match,strlen(match));
- if(r<0)
- {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-journal failed to get match:"),DLT_STRING(strerror(-r)));
- sd_journal_close(j);
- return;
-
- }
- }
-
- if(conf->Journal.Follow)
- {
- /* show only last 10 entries and follow */
+ int loglevel, systemd_loglevel;
+ char *systemd_log_levels[] =
+ { "Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Informational", "Debug" };
+
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-journal, in thread."));
+
+ DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf;
+ DLT_REGISTER_CONTEXT(journalContext, conf->Journal.ContextId, "Journal Adapter");
+
+ r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY /*SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_RUNTIME_ONLY*/);
+ printf("journal open return %d\n", r);
+
+ if (r < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-journal, cannot open journal:"), DLT_STRING(strerror(-r)));
+ printf("journal open failed: %s\n", strerror(-r));
+ return;
+ }
+
+ if (conf->Journal.CurrentBoot) {
+ /* show only current boot entries */
+ r = sd_id128_get_boot(&boot_id);
+
+ if (r < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-journal failed to get boot id:"), DLT_STRING(strerror(-r)));
+ sd_journal_close(j);
+ return;
+
+ }
+
+ sd_id128_to_string(boot_id, match + 9);
+ r = sd_journal_add_match(j, match, strlen(match));
+
+ if (r < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-journal failed to get match:"), DLT_STRING(strerror(-r)));
+ sd_journal_close(j);
+ return;
+
+ }
+ }
+
+ if (conf->Journal.Follow) {
+ /* show only last 10 entries and follow */
r = sd_journal_seek_tail(j);
- if(r<0)
- {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-journal failed to seek to tail:"),DLT_STRING(strerror(-r)));
- sd_journal_close(j);
- return;
-
- }
+
+ if (r < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-journal failed to seek to tail:"), DLT_STRING(strerror(-r)));
+ sd_journal_close(j);
+ return;
+
+ }
+
r = sd_journal_previous_skip(j, 10);
- if(r<0)
- {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-journal failed to seek back 10 entries:"),DLT_STRING(strerror(-r)));
- sd_journal_close(j);
- return;
-
- }
-
- }
-
- while(!threads.shutdown)
- {
-
- r = sd_journal_next(j);
- if(r<0)
- {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-journal failed to get next entry:"),DLT_STRING(strerror(-r)));
- sd_journal_close(j);
- return;
-
- }
- else if(r>0)
- {
- /* get all data from current journal entry */
- dlt_system_journal_get_timestamp(j, &timestamp);
-
- /* get data from journal entry, empty string if invalid fields */
- dlt_system_journal_get(j,buffer_comm,"_COMM",sizeof(buffer_comm));
- dlt_system_journal_get(j,buffer_pid,"_PID",sizeof(buffer_pid));
- dlt_system_journal_get(j,buffer_priority,"PRIORITY",sizeof(buffer_priority));
- dlt_system_journal_get(j,buffer_message,"MESSAGE",sizeof(buffer_message));
- dlt_system_journal_get(j,buffer_transport,"_TRANSPORT",sizeof(buffer_transport));
-
- /* prepare process string */
- if(strcmp(buffer_transport,"kernel")==0)
- snprintf(buffer_process,DLT_SYSTEM_JOURNAL_BUFFER_SIZE,"kernel:");
- else
- snprintf(buffer_process,DLT_SYSTEM_JOURNAL_BUFFER_SIZE,"%s[%s]:",buffer_comm,buffer_pid);
-
- /* map log level on demand */
- loglevel = DLT_LOG_INFO;
- systemd_loglevel = atoi(buffer_priority);
- if(conf->Journal.MapLogLevels)
- {
- /* Map log levels from journal to DLT */
- switch(systemd_loglevel)
- {
- case 0: /* Emergency */
- case 1: /* Alert */
- case 2: /* Critical */
- loglevel = DLT_LOG_FATAL;
- break;
- case 3: /* Error */
- loglevel = DLT_LOG_ERROR;
- break;
- case 4: /* Warning */
- loglevel = DLT_LOG_WARN;
- break;
- case 5: /* Notice */
- case 6: /* Informational */
- loglevel = DLT_LOG_INFO;
- break;
- case 7: /* Debug */
- loglevel = DLT_LOG_DEBUG;
- break;
- default:
- loglevel = DLT_LOG_INFO;
- break;
- }
- }
- if(systemd_loglevel>=0 && systemd_loglevel<=7)
- snprintf(buffer_priority,DLT_SYSTEM_JOURNAL_BUFFER_SIZE,"%s:",systemd_log_levels[systemd_loglevel]);
- else
- snprintf(buffer_priority,DLT_SYSTEM_JOURNAL_BUFFER_SIZE,"prio_unknown:");
-
- /* write log entry */
+
+ if (r < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-journal failed to seek back 10 entries:"), DLT_STRING(strerror(-r)));
+ sd_journal_close(j);
+ return;
+
+ }
+ }
+
+ while (!threads.shutdown) {
+
+ r = sd_journal_next(j);
+
+ if (r < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-journal failed to get next entry:"), DLT_STRING(strerror(-r)));
+ sd_journal_close(j);
+ return;
+
+ }
+ else if (r > 0)
+ {
+ /* get all data from current journal entry */
+ dlt_system_journal_get_timestamp(j, &timestamp);
+
+ /* get data from journal entry, empty string if invalid fields */
+ dlt_system_journal_get(j, buffer_comm, "_COMM", sizeof(buffer_comm));
+ dlt_system_journal_get(j, buffer_pid, "_PID", sizeof(buffer_pid));
+ dlt_system_journal_get(j, buffer_priority, "PRIORITY", sizeof(buffer_priority));
+ dlt_system_journal_get(j, buffer_message, "MESSAGE", sizeof(buffer_message));
+ dlt_system_journal_get(j, buffer_transport, "_TRANSPORT", sizeof(buffer_transport));
+
+ /* prepare process string */
+ if (strcmp(buffer_transport, "kernel") == 0)
+ snprintf(buffer_process, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "kernel:");
+ else
+ snprintf(buffer_process, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "%s[%s]:", buffer_comm, buffer_pid);
+
+ /* map log level on demand */
+ loglevel = DLT_LOG_INFO;
+ systemd_loglevel = atoi(buffer_priority);
+
+ if (conf->Journal.MapLogLevels) {
+ /* Map log levels from journal to DLT */
+ switch (systemd_loglevel) {
+ case 0: /* Emergency */
+ case 1: /* Alert */
+ case 2: /* Critical */
+ loglevel = DLT_LOG_FATAL;
+ break;
+ case 3: /* Error */
+ loglevel = DLT_LOG_ERROR;
+ break;
+ case 4: /* Warning */
+ loglevel = DLT_LOG_WARN;
+ break;
+ case 5: /* Notice */
+ case 6: /* Informational */
+ loglevel = DLT_LOG_INFO;
+ break;
+ case 7: /* Debug */
+ loglevel = DLT_LOG_DEBUG;
+ break;
+ default:
+ loglevel = DLT_LOG_INFO;
+ break;
+ }
+ }
+
+ if ((systemd_loglevel >= 0) && (systemd_loglevel <= 7))
+ snprintf(buffer_priority, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "%s:", systemd_log_levels[systemd_loglevel]);
+ else
+ snprintf(buffer_priority, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "prio_unknown:");
+
+ /* write log entry */
DLT_LOG(journalContext, loglevel,
- DLT_STRING(timestamp.real),
- DLT_STRING(timestamp.monotonic),
- DLT_STRING(buffer_process),
- DLT_STRING(buffer_priority),
- DLT_STRING(buffer_message)
- );
- }
- else
- {
- r = sd_journal_wait(j,1000000);
- if(r<0)
- {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-journal failed to call sd_journal_get_realtime_usec(): "),DLT_STRING(strerror(-r)));
- sd_journal_close(j);
- return;
-
- }
- }
-
- if(journal_checkUserBufferForFreeSpace()==-1)
- {
- // buffer is nearly full
- // wait 500ms for writing next entry
- struct timespec t;
- t.tv_sec = 0;
- t.tv_nsec = 1000000ul*500;
- nanosleep(&t, NULL);
- }
-
- }
+ DLT_STRING(timestamp.real),
+ DLT_STRING(timestamp.monotonic),
+ DLT_STRING(buffer_process),
+ DLT_STRING(buffer_priority),
+ DLT_STRING(buffer_message)
+ );
+ }
+ else {
+ r = sd_journal_wait(j, 1000000);
+
+ if (r < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-journal failed to call sd_journal_get_realtime_usec(): "),
+ DLT_STRING(strerror(-r)));
+ sd_journal_close(j);
+ return;
+
+ }
+ }
+
+ if (journal_checkUserBufferForFreeSpace() == -1) {
+ /* buffer is nearly full */
+ /* wait 500ms for writing next entry */
+ struct timespec t;
+ t.tv_sec = 0;
+ t.tv_nsec = 1000000ul * 500;
+ nanosleep(&t, NULL);
+ }
+ }
sd_journal_close(j);
- DLT_UNREGISTER_CONTEXT(journalContext);
+ DLT_UNREGISTER_CONTEXT(journalContext);
}
void start_systemd_journal(DltSystemConfiguration *conf)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-journal, start journal"));
- static pthread_attr_t t_attr;
- static pthread_t pt;
- pthread_create(&pt, &t_attr, (void *)journal_thread, conf);
- threads.threads[threads.count++] = pt;
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-journal, start journal"));
+ static pthread_attr_t t_attr;
+ static pthread_t pt;
+ pthread_create(&pt, &t_attr, (void *)journal_thread, conf);
+ threads.threads[threads.count++] = pt;
}
#endif /* DLT_SYSTEMD_JOURNAL_ENABLE */
diff --git a/src/system/dlt-system-logfile.c b/src/system/dlt-system-logfile.c
index 687d739..dae557f 100644
--- a/src/system/dlt-system-logfile.c
+++ b/src/system/dlt-system-logfile.c
@@ -50,7 +50,7 @@
#include <unistd.h>
#include "dlt-system.h"
-// Modes of sending
+/* Modes of sending */
#define SEND_MODE_OFF 0
#define SEND_MODE_ONCE 1
#define SEND_MODE_ON 2
@@ -62,98 +62,96 @@ DltContext logfileContext[DLT_SYSTEM_LOG_FILE_MAX];
void send_file(LogFileOptions const *fileopt, int n)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-logfile, sending file."));
- FILE * pFile;
- DltContext context = logfileContext[n];
- char buffer[1024];
- int bytes;
- int seq = 1;
-
- pFile = fopen((*fileopt).Filename[n],"r");
-
- if(pFile != NULL)
- {
- while (!feof(pFile)) {
- bytes = fread(buffer,1,sizeof(buffer)-1,pFile);
- if(bytes>=0)
- buffer[bytes] = 0;
- else
- buffer[0] = 0;
-
- if(feof(pFile)) {
- DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq*-1), DLT_STRING(buffer));
- break;
- }
- else {
- DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq++), DLT_STRING(buffer));
- }
- }
- fclose(pFile);
- }
- else
- {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-logfile, failed to open file."),
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-logfile, sending file."));
+ FILE *pFile;
+ DltContext context = logfileContext[n];
+ char buffer[1024];
+ int bytes;
+ int seq = 1;
+
+ pFile = fopen((*fileopt).Filename[n], "r");
+
+ if (pFile != NULL) {
+ while (!feof(pFile)) {
+ bytes = fread(buffer, 1, sizeof(buffer) - 1, pFile);
+
+ if (bytes >= 0)
+ buffer[bytes] = 0;
+ else
+ buffer[0] = 0;
+
+ if (feof(pFile)) {
+ DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq * -1), DLT_STRING(buffer));
+ break;
+ }
+ else {
+ DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq++), DLT_STRING(buffer));
+ }
+ }
+
+ fclose(pFile);
+ }
+ else {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-logfile, failed to open file."),
DLT_STRING((*fileopt).Filename[n]));
- }
+ }
}
void register_contexts(LogFileOptions const *fileopts)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-logfile, registering file contexts."));
- int i;
- for(i = 0;i < (*fileopts).Count;i++)
- {
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-logfile, registering file contexts."));
+ int i;
+
+ for (i = 0; i < (*fileopts).Count; i++)
DLT_REGISTER_CONTEXT(logfileContext[i], (*fileopts).ContextId[i],
- (*fileopts).Filename[i]);
- }
+ (*fileopts).Filename[i]);
}
void logfile_thread(void *v_conf)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-logfile, in thread."));
- DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf;
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-logfile, in thread."));
+ DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf;
register_contexts(&(conf->LogFile));
- int logfile_delays[DLT_SYSTEM_LOG_FILE_MAX];
- int i;
- for(i = 0;i < conf->LogFile.Count;i++)
- logfile_delays[i] = conf->LogFile.TimeDelay[i];
-
- while(!threads.shutdown)
- {
- sleep(1);
- for(i = 0;i < conf->LogFile.Count;i++)
- {
- if(conf->LogFile.Mode[i] == SEND_MODE_OFF)
- continue;
-
- if(logfile_delays[i] <= 0)
- {
+ int logfile_delays[DLT_SYSTEM_LOG_FILE_MAX];
+ int i;
+
+ for (i = 0; i < conf->LogFile.Count; i++)
+ logfile_delays[i] = conf->LogFile.TimeDelay[i];
+
+ while (!threads.shutdown) {
+ sleep(1);
+
+ for (i = 0; i < conf->LogFile.Count; i++) {
+ if (conf->LogFile.Mode[i] == SEND_MODE_OFF)
+ continue;
+
+ if (logfile_delays[i] <= 0) {
send_file(&(conf->LogFile), i);
- logfile_delays[i] = conf->LogFile.TimeDelay[i];
- if(conf->LogFile.Mode[i] == SEND_MODE_ONCE)
- conf->LogFile.Mode[i] = SEND_MODE_OFF;
- }
- else
- {
- logfile_delays[i]--;
- }
- }
- }
+ logfile_delays[i] = conf->LogFile.TimeDelay[i];
+
+ if (conf->LogFile.Mode[i] == SEND_MODE_ONCE)
+ conf->LogFile.Mode[i] = SEND_MODE_OFF;
+ }
+ else {
+ logfile_delays[i]--;
+ }
+ }
+ }
}
void start_logfile(DltSystemConfiguration *conf)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-logfile, starting."));
- DLT_LOG(dltsystem,DLT_LOG_DEBUG,DLT_STRING("Starting thread for logfile"));
- static pthread_attr_t t_attr;
- static pthread_t pt;
- pthread_create(&pt, &t_attr, (void *)logfile_thread, conf);
- threads.threads[threads.count++] = pt;
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-logfile, starting."));
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Starting thread for logfile"));
+ static pthread_attr_t t_attr;
+ static pthread_t pt;
+ pthread_create(&pt, &t_attr, (void *)logfile_thread, conf);
+ threads.threads[threads.count++] = pt;
}
diff --git a/src/system/dlt-system-options.c b/src/system/dlt-system-options.c
index 01f2d65..63f2e37 100644
--- a/src/system/dlt-system-options.c
+++ b/src/system/dlt-system-options.c
@@ -65,17 +65,17 @@
*/
void usage(char *prog_name)
{
- char version[255];
- dlt_get_version(version,255);
-
- printf("Usage: %s [options]\n", prog_name);
- printf("Application to forward syslog messages to DLT, transfer system information, logs and files.\n");
- printf("%s\n", version);
- printf("Options:\n");
- printf(" -d Daemonize. Detach from terminal and run in background.\n");
- printf(" -c filename Use configuration file. \n");
- printf(" Default: %s\n", DEFAULT_CONF_FILE);
- printf(" -h This help message.\n");
+ char version[255];
+ dlt_get_version(version, 255);
+
+ printf("Usage: %s [options]\n", prog_name);
+ printf("Application to forward syslog messages to DLT, transfer system information, logs and files.\n");
+ printf("%s\n", version);
+ printf("Options:\n");
+ printf(" -d Daemonize. Detach from terminal and run in background.\n");
+ printf(" -c filename Use configuration file. \n");
+ printf(" Default: %s\n", DEFAULT_CONF_FILE);
+ printf(" -h This help message.\n");
}
/**
@@ -83,8 +83,8 @@ void usage(char *prog_name)
*/
void init_cli_options(DltSystemCliOptions *options)
{
- options->ConfigurationFileName = DEFAULT_CONF_FILE;
- options->Daemonize = 0;
+ options->ConfigurationFileName = DEFAULT_CONF_FILE;
+ options->Daemonize = 0;
}
/**
@@ -92,39 +92,38 @@ void init_cli_options(DltSystemCliOptions *options)
*/
int read_command_line(DltSystemCliOptions *options, int argc, char *argv[])
{
- init_cli_options(options);
- int opt;
-
- while((opt = getopt(argc, argv, "c:hd")) != -1)
- {
- switch(opt) {
- case 'd':
- {
- options->Daemonize = 1;
- break;
- }
- case 'c':
- {
- options->ConfigurationFileName = malloc(strlen(optarg)+1);
- MALLOC_ASSERT(options->ConfigurationFileName);
- strcpy(options->ConfigurationFileName, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */
- break;
- }
- case 'h':
- {
- usage(argv[0]);
- exit(0);
- return -1;//for parasoft
- }
- default:
- {
- fprintf(stderr, "Unknown option '%c'\n", optopt);
- usage(argv[0]);
- return -1;
- }
- }
- }
- return 0;
+ init_cli_options(options);
+ int opt;
+
+ while ((opt = getopt(argc, argv, "c:hd")) != -1)
+ switch (opt) {
+ case 'd':
+ {
+ options->Daemonize = 1;
+ break;
+ }
+ case 'c':
+ {
+ options->ConfigurationFileName = malloc(strlen(optarg) + 1);
+ MALLOC_ASSERT(options->ConfigurationFileName);
+ strcpy(options->ConfigurationFileName, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */
+ break;
+ }
+ case 'h':
+ {
+ usage(argv[0]);
+ exit(0);
+ return -1; /*for parasoft */
+ }
+ default:
+ {
+ fprintf(stderr, "Unknown option '%c'\n", optopt);
+ usage(argv[0]);
+ return -1;
+ }
+ }
+
+ return 0;
}
/**
@@ -132,62 +131,62 @@ int read_command_line(DltSystemCliOptions *options, int argc, char *argv[])
*/
void init_configuration(DltSystemConfiguration *config)
{
- int i = 0;
-
- // Common
- config->ApplicationId = "SYS";
-
- // Shell
- config->Shell.Enable = 0;
-
- // Syslog
- config->Syslog.Enable = 0;
- config->Syslog.ContextId = "SYSL";
- config->Syslog.Port = 47111;
-
- // Journal
- config->Journal.Enable = 0;
- config->Journal.ContextId = "JOUR";
- config->Journal.CurrentBoot = 1;
- config->Journal.Follow = 0;
- config->Journal.MapLogLevels = 1;
-
- // File transfer
- config->Filetransfer.Enable = 0;
- config->Filetransfer.ContextId = "FILE";
- config->Filetransfer.TimeDelay = 10;
- config->Filetransfer.TimeStartup = 30;
- config->Filetransfer.TimeoutBetweenLogs = 10;
- config->Filetransfer.Count = 0;
- for(i = 0;i < DLT_SYSTEM_LOG_DIRS_MAX;i++)
- {
- config->Filetransfer.Directory[i] = NULL;
- config->Filetransfer.Compression[i] = 0;
- config->Filetransfer.CompressionLevel[i] = 5;
- }
-
- // Log file
- config->LogFile.Enable = 0;
- config->LogFile.Count = 0;
- for(i = 0;i < DLT_SYSTEM_LOG_FILE_MAX;i++)
- {
- config->LogFile.ContextId[i] = NULL;
- config->LogFile.Filename[i] = NULL;
- config->LogFile.Mode[i] = 0;
- config->LogFile.TimeDelay[i] = 0;
- }
-
- // Log process
- config->LogProcesses.Enable = 0;
- config->LogProcesses.ContextId = "PROC";
- config->LogProcesses.Count = 0;
- for(i = 0;i < DLT_SYSTEM_LOG_PROCESSES_MAX;i++)
- {
- config->LogProcesses.Name[i] = NULL;
- config->LogProcesses.Filename[i] = NULL;
- config->LogProcesses.Mode[i] = 0;
- config->LogProcesses.TimeDelay[i] = 0;
- }
+ int i = 0;
+
+ /* Common */
+ config->ApplicationId = "SYS";
+
+ /* Shell */
+ config->Shell.Enable = 0;
+
+ /* Syslog */
+ config->Syslog.Enable = 0;
+ config->Syslog.ContextId = "SYSL";
+ config->Syslog.Port = 47111;
+
+ /* Journal */
+ config->Journal.Enable = 0;
+ config->Journal.ContextId = "JOUR";
+ config->Journal.CurrentBoot = 1;
+ config->Journal.Follow = 0;
+ config->Journal.MapLogLevels = 1;
+
+ /* File transfer */
+ config->Filetransfer.Enable = 0;
+ config->Filetransfer.ContextId = "FILE";
+ config->Filetransfer.TimeDelay = 10;
+ config->Filetransfer.TimeStartup = 30;
+ config->Filetransfer.TimeoutBetweenLogs = 10;
+ config->Filetransfer.Count = 0;
+
+ for (i = 0; i < DLT_SYSTEM_LOG_DIRS_MAX; i++) {
+ config->Filetransfer.Directory[i] = NULL;
+ config->Filetransfer.Compression[i] = 0;
+ config->Filetransfer.CompressionLevel[i] = 5;
+ }
+
+ /* Log file */
+ config->LogFile.Enable = 0;
+ config->LogFile.Count = 0;
+
+ for (i = 0; i < DLT_SYSTEM_LOG_FILE_MAX; i++) {
+ config->LogFile.ContextId[i] = NULL;
+ config->LogFile.Filename[i] = NULL;
+ config->LogFile.Mode[i] = 0;
+ config->LogFile.TimeDelay[i] = 0;
+ }
+
+ /* Log process */
+ config->LogProcesses.Enable = 0;
+ config->LogProcesses.ContextId = "PROC";
+ config->LogProcesses.Count = 0;
+
+ for (i = 0; i < DLT_SYSTEM_LOG_PROCESSES_MAX; i++) {
+ config->LogProcesses.Name[i] = NULL;
+ config->LogProcesses.Filename[i] = NULL;
+ config->LogProcesses.Mode[i] = 0;
+ config->LogProcesses.TimeDelay[i] = 0;
+ }
}
/**
@@ -195,254 +194,244 @@ void init_configuration(DltSystemConfiguration *config)
*/
int read_configuration_file(DltSystemConfiguration *config, char *file_name)
{
- FILE *file;
- char *line, *token, *value, *pch;
- int ret = 0;
-
- init_configuration(config);
-
- file = fopen(file_name, "r");
-
- if(file == NULL)
- {
- fprintf(stderr, "dlt-system-options, could not open configuration file.\n");
- return -1;
- }
-
- line = malloc(MAX_LINE);
- token = malloc(MAX_LINE);
- value = malloc(MAX_LINE);
-
- MALLOC_ASSERT(line);
- MALLOC_ASSERT(token);
- MALLOC_ASSERT(value);
-
- while(fgets(line, MAX_LINE, file) != NULL)
- {
- token[0] = 0;
- value[0] = 0;
-
- pch = strtok (line, " =\r\n");
- while(pch != NULL)
- {
- if(pch[0] == '#')
- break;
-
- if(token[0] == 0)
- {
- strncpy(token, pch, MAX_LINE-1);
- token[MAX_LINE-1]=0;
- }
- else
- {
- strncpy(value, pch, MAX_LINE);
- value[MAX_LINE-1]=0;
- break;
- }
-
- pch = strtok (NULL, " =\r\n");
- }
-
- if(token[0] && value[0])
- {
- // Common
- if(strcmp(token, "ApplicationId") == 0)
- {
- config->ApplicationId = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->ApplicationId);
- strcpy(config->ApplicationId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
-
- // Shell
- else if(strcmp(token, "ShellEnable") == 0)
- {
- config->Shell.Enable = atoi(value);
- }
-
- // Syslog
- else if(strcmp(token, "SyslogEnable") == 0)
- {
- config->Syslog.Enable = atoi(value);
- }
- else if(strcmp(token, "SyslogContextId") == 0)
- {
- config->Syslog.ContextId = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->Syslog.ContextId);
- strcpy(config->Syslog.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- else if(strcmp(token, "SyslogPort") == 0)
- {
- config->Syslog.Port = atoi(value);
- }
-
- // Journal
- else if(strcmp(token, "JournalEnable") == 0)
- {
- config->Journal.Enable = atoi(value);
- }
- else if(strcmp(token, "JournalContextId") == 0)
- {
- config->Journal.ContextId = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->Journal.ContextId);
- strcpy(config->Journal.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- else if(strcmp(token, "JournalCurrentBoot") == 0)
- {
- config->Journal.CurrentBoot = atoi(value);
- }
- else if(strcmp(token, "JournalFollow") == 0)
- {
- config->Journal.Follow = atoi(value);
- }
- else if(strcmp(token, "JournalMapLogLevels") == 0)
- {
- config->Journal.MapLogLevels = atoi(value);
- }
-
- // File transfer
- else if(strcmp(token, "FiletransferEnable") == 0)
- {
- config->Filetransfer.Enable = atoi(value);
- }
- else if(strcmp(token, "FiletransferContextId") == 0)
- {
- config->Filetransfer.ContextId = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->Filetransfer.ContextId);
- strcpy(config->Filetransfer.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- else if(strcmp(token, "FiletransferTimeStartup") == 0)
- {
- config->Filetransfer.TimeStartup = atoi(value);
- }
- else if(strcmp(token, "FiletransferTimeDelay") == 0)
- {
- config->Filetransfer.TimeDelay = atoi(value);
- }
- else if(strcmp(token, "FiletransferTimeoutBetweenLogs") == 0)
- {
- config->Filetransfer.TimeoutBetweenLogs = atoi(value);
- }
- else if(strcmp(token, "FiletransferTempDir") == 0)
- {
- config->Filetransfer.TempDir = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->Filetransfer.TempDir);
- strcpy(config->Filetransfer.TempDir, value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- else if(strcmp(token, "FiletransferDirectory") == 0)
- {
- config->Filetransfer.Directory[config->Filetransfer.Count] = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->Filetransfer.Directory[config->Filetransfer.Count]);
- strcpy(config->Filetransfer.Directory[config->Filetransfer.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- else if(strcmp(token, "FiletransferCompression") == 0)
- {
- config->Filetransfer.Compression[config->Filetransfer.Count] = atoi(value);
- }
- else if(strcmp(token, "FiletransferCompressionLevel") == 0)
- {
- config->Filetransfer.CompressionLevel[config->Filetransfer.Count] = atoi(value);
- if(config->Filetransfer.Count < (DLT_SYSTEM_LOG_DIRS_MAX - 1))
- {
- config->Filetransfer.Count++;
- }
- else
- {
- fprintf(stderr,
- "Too many file transfer directories configured. Maximum: %d\n",
- DLT_SYSTEM_LOG_DIRS_MAX);
- ret = -1;
- break;
- }
- }
-
- // Log files
- else if(strcmp(token, "LogFileEnable") == 0)
- {
- config->LogFile.Enable = atoi(value);
- }
- else if(strcmp(token, "LogFileFilename") == 0)
- {
- config->LogFile.Filename[config->LogFile.Count] = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->LogFile.Filename[config->LogFile.Count]);
- strcpy(config->LogFile.Filename[config->LogFile.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- else if(strcmp(token, "LogFileMode") == 0)
- {
- config->LogFile.Mode[config->LogFile.Count] = atoi(value);
- }
- else if(strcmp(token, "LogFileTimeDelay") == 0)
- {
- config->LogFile.TimeDelay[config->LogFile.Count] = atoi(value);
- }
- else if(strcmp(token, "LogFileContextId") == 0)
- {
- config->LogFile.ContextId[config->LogFile.Count] = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->LogFile.ContextId[config->LogFile.Count]);
- strcpy(config->LogFile.ContextId[config->LogFile.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */
- if(config->LogFile.Count < (DLT_SYSTEM_LOG_FILE_MAX - 1))
- {
- config->LogFile.Count++;
- }
- else
- {
- fprintf(stderr,
- "Too many log files configured. Maximum: %d\n",
- DLT_SYSTEM_LOG_FILE_MAX);
- ret = -1;
- break;
- }
-
- }
-
- // Log Processes
- else if(strcmp(token, "LogProcessesEnable") == 0)
- {
- config->LogProcesses.Enable = atoi(value);
- }
- else if(strcmp(token, "LogProcessesContextId") == 0)
- {
- config->LogProcesses.ContextId = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->LogProcesses.ContextId);
- strcpy(config->LogProcesses.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- else if(strcmp(token, "LogProcessName") == 0)
- {
- config->LogProcesses.Name[config->LogProcesses.Count] = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->LogProcesses.Name[config->LogProcesses.Count]);
- strcpy(config->LogProcesses.Name[config->LogProcesses.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- else if(strcmp(token, "LogProcessFilename") == 0)
- {
- config->LogProcesses.Filename[config->LogProcesses.Count] = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->LogProcesses.Filename[config->LogProcesses.Count]);
- strcpy(config->LogProcesses.Filename[config->LogProcesses.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- else if(strcmp(token, "LogProcessMode") == 0)
- {
- config->LogProcesses.Mode[config->LogProcesses.Count] = atoi(value);
- }
- else if(strcmp(token, "LogProcessTimeDelay") == 0)
- {
- config->LogProcesses.TimeDelay[config->LogProcesses.Count] = atoi(value);
- if(config->LogProcesses.Count < (DLT_SYSTEM_LOG_PROCESSES_MAX - 1))
- {
- config->LogProcesses.Count++;
- }
- else
- {
- fprintf(stderr,
- "Too many processes to log configured. Maximum: %d\n",
- DLT_SYSTEM_LOG_PROCESSES_MAX);
- ret = -1;
- break;
- }
-
- }
- }
- }
- fclose(file);
- free(value);
- free(token);
- free(line);
- return ret;
+ FILE *file;
+ char *line, *token, *value, *pch;
+ int ret = 0;
+
+ init_configuration(config);
+
+ file = fopen(file_name, "r");
+
+ if (file == NULL) {
+ fprintf(stderr, "dlt-system-options, could not open configuration file.\n");
+ return -1;
+ }
+
+ line = malloc(MAX_LINE);
+ token = malloc(MAX_LINE);
+ value = malloc(MAX_LINE);
+
+ MALLOC_ASSERT(line);
+ MALLOC_ASSERT(token);
+ MALLOC_ASSERT(value);
+
+ while (fgets(line, MAX_LINE, file) != NULL) {
+ token[0] = 0;
+ value[0] = 0;
+
+ pch = strtok (line, " =\r\n");
+
+ while (pch != NULL) {
+ if (pch[0] == '#')
+ break;
+
+ if (token[0] == 0) {
+ strncpy(token, pch, MAX_LINE - 1);
+ token[MAX_LINE - 1] = 0;
+ }
+ else {
+ strncpy(value, pch, MAX_LINE);
+ value[MAX_LINE - 1] = 0;
+ break;
+ }
+
+ pch = strtok (NULL, " =\r\n");
+ }
+
+ if (token[0] && value[0]) {
+ /* Common */
+ if (strcmp(token, "ApplicationId") == 0) {
+ config->ApplicationId = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->ApplicationId);
+ strcpy(config->ApplicationId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+
+ /* Shell */
+ else if (strcmp(token, "ShellEnable") == 0)
+ {
+ config->Shell.Enable = atoi(value);
+ }
+
+ /* Syslog */
+ else if (strcmp(token, "SyslogEnable") == 0)
+ {
+ config->Syslog.Enable = atoi(value);
+ }
+ else if (strcmp(token, "SyslogContextId") == 0)
+ {
+ config->Syslog.ContextId = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->Syslog.ContextId);
+ strcpy(config->Syslog.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ else if (strcmp(token, "SyslogPort") == 0)
+ {
+ config->Syslog.Port = atoi(value);
+ }
+
+ /* Journal */
+ else if (strcmp(token, "JournalEnable") == 0)
+ {
+ config->Journal.Enable = atoi(value);
+ }
+ else if (strcmp(token, "JournalContextId") == 0)
+ {
+ config->Journal.ContextId = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->Journal.ContextId);
+ strcpy(config->Journal.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ else if (strcmp(token, "JournalCurrentBoot") == 0)
+ {
+ config->Journal.CurrentBoot = atoi(value);
+ }
+ else if (strcmp(token, "JournalFollow") == 0)
+ {
+ config->Journal.Follow = atoi(value);
+ }
+ else if (strcmp(token, "JournalMapLogLevels") == 0)
+ {
+ config->Journal.MapLogLevels = atoi(value);
+ }
+
+ /* File transfer */
+ else if (strcmp(token, "FiletransferEnable") == 0)
+ {
+ config->Filetransfer.Enable = atoi(value);
+ }
+ else if (strcmp(token, "FiletransferContextId") == 0)
+ {
+ config->Filetransfer.ContextId = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->Filetransfer.ContextId);
+ strcpy(config->Filetransfer.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ else if (strcmp(token, "FiletransferTimeStartup") == 0)
+ {
+ config->Filetransfer.TimeStartup = atoi(value);
+ }
+ else if (strcmp(token, "FiletransferTimeDelay") == 0)
+ {
+ config->Filetransfer.TimeDelay = atoi(value);
+ }
+ else if (strcmp(token, "FiletransferTimeoutBetweenLogs") == 0)
+ {
+ config->Filetransfer.TimeoutBetweenLogs = atoi(value);
+ }
+ else if (strcmp(token, "FiletransferTempDir") == 0)
+ {
+ config->Filetransfer.TempDir = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->Filetransfer.TempDir);
+ strcpy(config->Filetransfer.TempDir, value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ else if (strcmp(token, "FiletransferDirectory") == 0)
+ {
+ config->Filetransfer.Directory[config->Filetransfer.Count] = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->Filetransfer.Directory[config->Filetransfer.Count]);
+ strcpy(config->Filetransfer.Directory[config->Filetransfer.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ else if (strcmp(token, "FiletransferCompression") == 0)
+ {
+ config->Filetransfer.Compression[config->Filetransfer.Count] = atoi(value);
+ }
+ else if (strcmp(token, "FiletransferCompressionLevel") == 0)
+ {
+ config->Filetransfer.CompressionLevel[config->Filetransfer.Count] = atoi(value);
+
+ if (config->Filetransfer.Count < (DLT_SYSTEM_LOG_DIRS_MAX - 1)) {
+ config->Filetransfer.Count++;
+ }
+ else {
+ fprintf(stderr,
+ "Too many file transfer directories configured. Maximum: %d\n",
+ DLT_SYSTEM_LOG_DIRS_MAX);
+ ret = -1;
+ break;
+ }
+ }
+
+ /* Log files */
+ else if (strcmp(token, "LogFileEnable") == 0)
+ {
+ config->LogFile.Enable = atoi(value);
+ }
+ else if (strcmp(token, "LogFileFilename") == 0)
+ {
+ config->LogFile.Filename[config->LogFile.Count] = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->LogFile.Filename[config->LogFile.Count]);
+ strcpy(config->LogFile.Filename[config->LogFile.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ else if (strcmp(token, "LogFileMode") == 0)
+ {
+ config->LogFile.Mode[config->LogFile.Count] = atoi(value);
+ }
+ else if (strcmp(token, "LogFileTimeDelay") == 0)
+ {
+ config->LogFile.TimeDelay[config->LogFile.Count] = atoi(value);
+ }
+ else if (strcmp(token, "LogFileContextId") == 0)
+ {
+ config->LogFile.ContextId[config->LogFile.Count] = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->LogFile.ContextId[config->LogFile.Count]);
+ strcpy(config->LogFile.ContextId[config->LogFile.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */
+
+ if (config->LogFile.Count < (DLT_SYSTEM_LOG_FILE_MAX - 1)) {
+ config->LogFile.Count++;
+ }
+ else {
+ fprintf(stderr,
+ "Too many log files configured. Maximum: %d\n",
+ DLT_SYSTEM_LOG_FILE_MAX);
+ ret = -1;
+ break;
+ }
+ }
+
+ /* Log Processes */
+ else if (strcmp(token, "LogProcessesEnable") == 0)
+ {
+ config->LogProcesses.Enable = atoi(value);
+ }
+ else if (strcmp(token, "LogProcessesContextId") == 0)
+ {
+ config->LogProcesses.ContextId = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->LogProcesses.ContextId);
+ strcpy(config->LogProcesses.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ else if (strcmp(token, "LogProcessName") == 0)
+ {
+ config->LogProcesses.Name[config->LogProcesses.Count] = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->LogProcesses.Name[config->LogProcesses.Count]);
+ strcpy(config->LogProcesses.Name[config->LogProcesses.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ else if (strcmp(token, "LogProcessFilename") == 0)
+ {
+ config->LogProcesses.Filename[config->LogProcesses.Count] = malloc(strlen(value) + 1);
+ MALLOC_ASSERT(config->LogProcesses.Filename[config->LogProcesses.Count]);
+ strcpy(config->LogProcesses.Filename[config->LogProcesses.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ else if (strcmp(token, "LogProcessMode") == 0)
+ {
+ config->LogProcesses.Mode[config->LogProcesses.Count] = atoi(value);
+ }
+ else if (strcmp(token, "LogProcessTimeDelay") == 0)
+ {
+ config->LogProcesses.TimeDelay[config->LogProcesses.Count] = atoi(value);
+
+ if (config->LogProcesses.Count < (DLT_SYSTEM_LOG_PROCESSES_MAX - 1)) {
+ config->LogProcesses.Count++;
+ }
+ else {
+ fprintf(stderr,
+ "Too many processes to log configured. Maximum: %d\n",
+ DLT_SYSTEM_LOG_PROCESSES_MAX);
+ ret = -1;
+ break;
+ }
+ }
+ }
+ }
+
+ fclose(file);
+ free(value);
+ free(token);
+ free(line);
+ return ret;
}
diff --git a/src/system/dlt-system-process-handling.c b/src/system/dlt-system-process-handling.c
index 21e2987..51c2547 100644
--- a/src/system/dlt-system-process-handling.c
+++ b/src/system/dlt-system-process-handling.c
@@ -61,88 +61,89 @@ DLT_IMPORT_CONTEXT(dltsystem)
int daemonize()
{
- DLT_LOG(dltsystem,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-process-handling, daemonize"));
-
- // Fork new process
- int f = fork();
-
- if(f < 0)
- return f;
- if(f > 0)
- exit(0);
-
- // Create a new process group
- if(setsid() < 0)
- return -1;
-
- /**
- * Close all file descriptors and point
- * stdin, stdout and stderr to /dev/null
- */
- int i;
- for(i = getdtablesize(); i >= 0; i--)
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-process-handling, daemonize"));
+
+ /* Fork new process */
+ int f = fork();
+
+ if (f < 0)
+ return f;
+
+ if (f > 0)
+ exit(0);
+
+ /* Create a new process group */
+ if (setsid() < 0)
+ return -1;
+
+ /**
+ * Close all file descriptors and point
+ * stdin, stdout and stderr to /dev/null
+ */
+ int i;
+
+ for (i = getdtablesize(); i >= 0; i--)
close(i);
- int fd = open("/dev/null",O_RDWR);
- if(fd < 0)
- {
+ int fd = open("/dev/null", O_RDWR);
+
+ if (fd < 0)
return -1;
- }
- if(dup(fd) < 0 || dup(fd) < 0)
- {
+ if ((dup(fd) < 0) || (dup(fd) < 0)) {
close(fd);
- return -1;
+ return -1;
}
- /**
- * Ignore signals related to child processes and
- * terminal handling.
- */
+ /**
+ * Ignore signals related to child processes and
+ * terminal handling.
+ */
signal(SIGCHLD, SIG_IGN);
signal(SIGTSTP, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
signal(SIGTTIN, SIG_IGN);
- //no close(fd); - we just intentionally pointed stdx to null! tbd: set ignore for coverity
- return 0;
+ /*no close(fd); - we just intentionally pointed stdx to null! tbd: set ignore for coverity */
+ return 0;
}
void start_threads(DltSystemConfiguration *config)
{
- DLT_LOG(dltsystem,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-process-handling, start threads"));
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-process-handling, start threads"));
- int i;
- threads.count = 0;
- threads.shutdown = 0;
- for(i = 0;i < MAX_THREADS; i++)
- {
- threads.threads[i] = 0;
- }
+ int i;
+ threads.count = 0;
+ threads.shutdown = 0;
+
+ for (i = 0; i < MAX_THREADS; i++)
+ threads.threads[i] = 0;
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE)
- start_systemd_watchdog(config);
+ start_systemd_watchdog(config);
#endif
- if(config->Shell.Enable)
- init_shell();
+ if (config->Shell.Enable)
+ init_shell();
- if(config->LogFile.Enable)
- start_logfile(config);
+ if (config->LogFile.Enable)
+ start_logfile(config);
- if(config->Filetransfer.Enable)
- start_filetransfer(config);
+ if (config->Filetransfer.Enable)
+ start_filetransfer(config);
- if(config->LogProcesses.Enable)
- start_logprocess(config);
+ if (config->LogProcesses.Enable)
+ start_logprocess(config);
- if(config->Syslog.Enable)
- start_syslog(config);
+ if (config->Syslog.Enable)
+ start_syslog(config);
#if defined(DLT_SYSTEMD_JOURNAL_ENABLE)
- if(config->Journal.Enable)
- start_systemd_journal(config);
+
+ if (config->Journal.Enable)
+ start_systemd_journal(config);
+
#endif
}
@@ -153,52 +154,48 @@ void start_threads(DltSystemConfiguration *config)
*/
void join_threads()
{
- int i;
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-process-handling, waiting for threads to exit."));
-
- if(threads.count < 1)
- {
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-process-handling, no threads, waiting for signal."));
- sleep(UINT_MAX);
- }
- else
- {
- DLT_LOG(dltsystem,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-process-handling, thread count: "),
- DLT_INT(threads.count));
-
- for (i = 0; i < threads.count; i++)
- {
- pthread_join(threads.threads[i], NULL);
- DLT_LOG(dltsystem,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-process-handling, thread exit: "),
- DLT_INT(threads.threads[i]));
- }
- }
+ int i;
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-process-handling, waiting for threads to exit."));
+
+ if (threads.count < 1) {
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-process-handling, no threads, waiting for signal."));
+ sleep(UINT_MAX);
+ }
+ else {
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-process-handling, thread count: "),
+ DLT_INT(threads.count));
+
+ for (i = 0; i < threads.count; i++) {
+ pthread_join(threads.threads[i], NULL);
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-process-handling, thread exit: "),
+ DLT_INT(threads.threads[i]));
+ }
+ }
}
void dlt_system_signal_handler(int sig)
{
- DLT_LOG(dltsystem,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-process-handling, signal handler"));
-
- switch (sig)
- {
- case SIGHUP:
- case SIGTERM:
- case SIGINT:
- case SIGQUIT:
- DLT_LOG(dltsystem,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-process-handling, exit, signal: "),
- DLT_INT(sig));
- exit(0);
- break;
- default:
- DLT_LOG(dltsystem,DLT_LOG_WARN,
- DLT_STRING("dlt-system-process-handling, unknown signal!"));
- break;
- }
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-process-handling, signal handler"));
+
+ switch (sig) {
+ case SIGHUP:
+ case SIGTERM:
+ case SIGINT:
+ case SIGQUIT:
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-process-handling, exit, signal: "),
+ DLT_INT(sig));
+ exit(0);
+ break;
+ default:
+ DLT_LOG(dltsystem, DLT_LOG_WARN,
+ DLT_STRING("dlt-system-process-handling, unknown signal!"));
+ break;
+ }
}
diff --git a/src/system/dlt-system-processes.c b/src/system/dlt-system-processes.c
index b92ff55..e9b8577 100644
--- a/src/system/dlt-system-processes.c
+++ b/src/system/dlt-system-processes.c
@@ -57,7 +57,7 @@
#include "dlt-system.h"
-// Modes of sending
+/* Modes of sending */
#define SEND_MODE_OFF 0
#define SEND_MODE_ONCE 1
#define SEND_MODE_ON 2
@@ -69,108 +69,105 @@ DLT_DECLARE_CONTEXT(procContext)
void send_process(LogProcessOptions const *popts, int n)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-processes, send process info."));
- FILE * pFile;
- struct dirent *dp;
- char filename[PATH_MAX];
- char buffer[1024];
- int bytes;
- int found = 0;
-
- /* go through all process files in directory */
- DIR *dir = opendir("/proc");
- if(dir != NULL)
- {
- while ((dp=readdir(dir)) != NULL)
- {
- if(isdigit(dp->d_name[0]))
- {
- buffer[0] = 0;
- snprintf(filename,PATH_MAX, "/proc/%s/cmdline",dp->d_name);
- pFile = fopen(filename, "r");
- if(pFile != NULL)
- {
- bytes = fread(buffer, 1, sizeof(buffer)-1, pFile);
- fclose(pFile);
- }
- if((strcmp((*popts).Name[n], "*")==0) ||
- (strcmp(buffer, (*popts).Name[n])==0))
- {
- found = 1;
- snprintf(filename,PATH_MAX, "/proc/%s/%s", dp->d_name,(*popts).Filename[n]);
- pFile = fopen(filename, "r");
- if(pFile != NULL)
- {
- 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);
- }
- else
- {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-processes, failed to open /proc."));
- }
-
- if(!found) {
- DLT_LOG(procContext, DLT_LOG_INFO, DLT_STRING("Process"), DLT_STRING((*popts).Name[n]),DLT_STRING("not running!"));
- }
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-processes, send process info."));
+ FILE *pFile;
+ struct dirent *dp;
+ char filename[PATH_MAX];
+ char buffer[1024];
+ int bytes;
+ int found = 0;
+
+ /* go through all process files in directory */
+ DIR *dir = opendir("/proc");
+
+ if (dir != NULL) {
+ while ((dp = readdir(dir)) != NULL)
+ if (isdigit(dp->d_name[0])) {
+ buffer[0] = 0;
+ snprintf(filename, PATH_MAX, "/proc/%s/cmdline", dp->d_name);
+ pFile = fopen(filename, "r");
+
+ if (pFile != NULL) {
+ bytes = fread(buffer, 1, sizeof(buffer) - 1, pFile);
+ fclose(pFile);
+ }
+
+ if ((strcmp((*popts).Name[n], "*") == 0) ||
+ (strcmp(buffer, (*popts).Name[n]) == 0)) {
+ found = 1;
+ snprintf(filename, PATH_MAX, "/proc/%s/%s", dp->d_name, (*popts).Filename[n]);
+ pFile = fopen(filename, "r");
+
+ if (pFile != NULL) {
+ 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);
+ }
+ else {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-processes, failed to open /proc."));
+ }
+
+ 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)
- {
+ 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]--;
- }
- }
- }
+ 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;
+ 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;
}
diff --git a/src/system/dlt-system-shell.c b/src/system/dlt-system-shell.c
index 8dce12e..6e24f3b 100644
--- a/src/system/dlt-system-shell.c
+++ b/src/system/dlt-system-shell.c
@@ -66,62 +66,58 @@ DLT_DECLARE_CONTEXT(shellContext)
int dlt_shell_injection_callback(uint32_t service_id, void *data, uint32_t length)
{
- (void) length;
+ (void)length;
- DLT_LOG(shellContext,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-shell, injection callback"));
- char text[DLT_SHELL_COMMAND_MAX_LENGTH];
+ DLT_LOG(shellContext, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-shell, injection callback"));
+ char text[DLT_SHELL_COMMAND_MAX_LENGTH];
int syserr = 0;
- if(length<=DLT_SHELL_COMMAND_MAX_LENGTH-1)
- {
- strncpy(text,data,length);
- text[length] = 0;
- }
- else
- {
- strncpy(text,data,DLT_SHELL_COMMAND_MAX_LENGTH-1);
- text[DLT_SHELL_COMMAND_MAX_LENGTH-1] = 0;
- }
+ if (length <= DLT_SHELL_COMMAND_MAX_LENGTH - 1) {
+ strncpy(text, data, length);
+ text[length] = 0;
+ }
+ else {
+ strncpy(text, data, DLT_SHELL_COMMAND_MAX_LENGTH - 1);
+ text[DLT_SHELL_COMMAND_MAX_LENGTH - 1] = 0;
+ }
- DLT_LOG(shellContext,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-shell, injection injection id:"),
- DLT_UINT32(service_id));
- DLT_LOG(shellContext,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-shell, injection data:"),
- DLT_STRING(text));
+ DLT_LOG(shellContext, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-shell, injection injection id:"),
+ DLT_UINT32(service_id));
+ DLT_LOG(shellContext, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-shell, injection data:"),
+ DLT_STRING(text));
+
+ switch (service_id) {
+ case 0x1001:
+
+ if ((syserr = system(text)) != 0)
+ DLT_LOG(shellContext, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-shell, abnormal exit status."),
+ DLT_STRING(text),
+ DLT_INT(syserr));
+ else
+ DLT_LOG(shellContext, DLT_LOG_INFO,
+ DLT_STRING("Shell command executed:"),
+ DLT_STRING(text));
+
+ break;
+ default:
+ DLT_LOG(shellContext, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-shell, unknown command received."),
+ DLT_UINT32(service_id),
+ DLT_STRING(text));
+ break;
+ }
- switch(service_id)
- {
- case 0x1001:
- if((syserr = system(text)) != 0)
- {
- DLT_LOG(shellContext,DLT_LOG_ERROR,
- DLT_STRING("dlt-system-shell, abnormal exit status."),
- DLT_STRING(text),
- DLT_INT(syserr));
- }
- else
- {
- DLT_LOG(shellContext,DLT_LOG_INFO,
- DLT_STRING("Shell command executed:"),
- DLT_STRING(text));
- }
- break;
- default:
- DLT_LOG(shellContext,DLT_LOG_ERROR,
- DLT_STRING("dlt-system-shell, unknown command received."),
- DLT_UINT32(service_id),
- DLT_STRING(text));
- break;
- }
return 0;
}
void init_shell()
{
- DLT_LOG(dltsystem,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-shell, register callback"));
- DLT_REGISTER_CONTEXT(shellContext,"CMD","Execute Shell commands");
- DLT_REGISTER_INJECTION_CALLBACK(shellContext, 0x1001, dlt_shell_injection_callback);
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-shell, register callback"));
+ DLT_REGISTER_CONTEXT(shellContext, "CMD", "Execute Shell commands");
+ DLT_REGISTER_INJECTION_CALLBACK(shellContext, 0x1001, dlt_shell_injection_callback);
}
diff --git a/src/system/dlt-system-syslog.c b/src/system/dlt-system-syslog.c
index 0f498b9..8fe9802 100644
--- a/src/system/dlt-system-syslog.c
+++ b/src/system/dlt-system-syslog.c
@@ -63,108 +63,103 @@ DLT_DECLARE_CONTEXT(syslogContext)
int init_socket(SyslogOptions opts)
{
- DLT_LOG(dltsystem,DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-syslog, init socket, port: "),
- DLT_INT(opts.Port));
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-syslog, init socket, port: "),
+ DLT_INT(opts.Port));
- int sock = -1;
- struct sockaddr_in syslog_addr;
+ int sock = -1;
+ struct sockaddr_in syslog_addr;
#ifdef DLT_USE_IPv6
- sock = socket(AF_INET6, SOCK_DGRAM, 0);
+ sock = socket(AF_INET6, SOCK_DGRAM, 0);
#else
- sock = socket(AF_INET, SOCK_DGRAM, 0);
+ sock = socket(AF_INET, SOCK_DGRAM, 0);
#endif
- if(sock < 0)
- {
- DLT_LOG(syslogContext, DLT_LOG_FATAL,
- DLT_STRING("Unable to create socket for SYSLOG."));
- return -1;
- }
+
+ if (sock < 0) {
+ DLT_LOG(syslogContext, DLT_LOG_FATAL,
+ DLT_STRING("Unable to create socket for SYSLOG."));
+ return -1;
+ }
#ifdef DLT_USE_IPv6
- syslog_addr.sin_family = AF_INET6;
+ syslog_addr.sin_family = AF_INET6;
#else
- syslog_addr.sin_family = AF_INET;
+ syslog_addr.sin_family = AF_INET;
#endif
- syslog_addr.sin_port = htons(opts.Port);
- syslog_addr.sin_addr.s_addr = INADDR_ANY;
- bzero(&(syslog_addr.sin_zero), 8);
-
- if (bind(sock, (struct sockaddr *)&syslog_addr,
- sizeof(struct sockaddr)) == -1)
- {
- DLT_LOG(syslogContext, DLT_LOG_FATAL,
- DLT_STRING("Unable to bind socket for SYSLOG."));
- close(sock);
- return -1;
- }
-
- return sock;
+ syslog_addr.sin_port = htons(opts.Port);
+ syslog_addr.sin_addr.s_addr = INADDR_ANY;
+ bzero(&(syslog_addr.sin_zero), 8);
+
+ if (bind(sock, (struct sockaddr *)&syslog_addr,
+ sizeof(struct sockaddr)) == -1) {
+ DLT_LOG(syslogContext, DLT_LOG_FATAL,
+ DLT_STRING("Unable to bind socket for SYSLOG."));
+ close(sock);
+ return -1;
+ }
+
+ return sock;
}
int read_socket(int sock)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-syslog, read socket"));
- char recv_data[RECV_BUF_SZ];
- struct sockaddr_in client_addr;
- socklen_t addr_len = sizeof(struct sockaddr_in);
-
- int bytes_read = recvfrom(sock, recv_data, RECV_BUF_SZ, 0,
- (struct sockaddr *) &client_addr, &addr_len);
- if(bytes_read == -1)
- {
- if(errno == EINTR)
- {
- return 0;
- }
- else
- {
- DLT_LOG(syslogContext, DLT_LOG_FATAL,
- DLT_STRING("Read from socket failed in SYSLOG."));
- return -1;
- }
- }
-
- recv_data[bytes_read] = '\0';
-
- if(bytes_read != 0)
- {
- DLT_LOG(syslogContext, DLT_LOG_INFO, DLT_STRING(recv_data));
- }
- return bytes_read;
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-syslog, read socket"));
+ char recv_data[RECV_BUF_SZ];
+ struct sockaddr_in client_addr;
+ socklen_t addr_len = sizeof(struct sockaddr_in);
+
+ int bytes_read = recvfrom(sock, recv_data, RECV_BUF_SZ, 0,
+ (struct sockaddr *)&client_addr, &addr_len);
+
+ if (bytes_read == -1) {
+ if (errno == EINTR) {
+ return 0;
+ }
+ else {
+ DLT_LOG(syslogContext, DLT_LOG_FATAL,
+ DLT_STRING("Read from socket failed in SYSLOG."));
+ return -1;
+ }
+ }
+
+ recv_data[bytes_read] = '\0';
+
+ if (bytes_read != 0)
+ DLT_LOG(syslogContext, DLT_LOG_INFO, DLT_STRING(recv_data));
+
+ return bytes_read;
}
void syslog_thread(void *v_conf)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-syslog, in thread."));
-
- DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf;
- DLT_REGISTER_CONTEXT(syslogContext, conf->Syslog.ContextId, "SYSLOG Adapter");
-
- int sock = init_socket(conf->Syslog);
- if(sock < 0)
- return;
-
- while(!threads.shutdown)
- {
- if(read_socket(sock) < 0)
- {
- close(sock);
- return;
- }
- }
- close (sock);
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-syslog, in thread."));
+
+ DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf;
+ DLT_REGISTER_CONTEXT(syslogContext, conf->Syslog.ContextId, "SYSLOG Adapter");
+
+ int sock = init_socket(conf->Syslog);
+
+ if (sock < 0)
+ return;
+
+ while (!threads.shutdown)
+ if (read_socket(sock) < 0) {
+ close(sock);
+ return;
+ }
+
+ close (sock);
}
void start_syslog(DltSystemConfiguration *conf)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-syslog, start syslog"));
- static pthread_attr_t t_attr;
- static pthread_t pt;
- pthread_create(&pt, &t_attr, (void *)syslog_thread, conf);
- threads.threads[threads.count++] = pt;
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-syslog, start syslog"));
+ static pthread_attr_t t_attr;
+ static pthread_t pt;
+ pthread_create(&pt, &t_attr, (void *)syslog_thread, conf);
+ threads.threads[threads.count++] = pt;
}
diff --git a/src/system/dlt-system-watchdog.c b/src/system/dlt-system-watchdog.c
index 8dae122..3905564 100644
--- a/src/system/dlt-system-watchdog.c
+++ b/src/system/dlt-system-watchdog.c
@@ -54,16 +54,12 @@ void wait_period (PeriodicData *info)
{
unsigned long long missed;
- if(read (info->timer_fd, &missed, sizeof (missed)) < 0)
- {
+ if (read (info->timer_fd, &missed, sizeof (missed)) < 0)
DLT_LOG(watchdogContext, DLT_LOG_ERROR,
DLT_STRING("Could not read from timer file descriptor in watchdog.\n"));
- }
if (missed > 0)
- {
info->wakeups_missed += (missed - 1);
- }
}
int make_periodic(unsigned int period, PeriodicData *info)
@@ -73,10 +69,9 @@ int make_periodic(unsigned int period, PeriodicData *info)
int fd;
struct itimerspec itval;
- if (info==0)
- {
- DLT_LOG(watchdogContext, DLT_LOG_ERROR,
- DLT_STRING("Invalid function parameters used for function make_periodic.\n"));
+ if (info == 0) {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR,
+ DLT_STRING("Invalid function parameters used for function make_periodic.\n"));
return -1;
}
@@ -86,15 +81,14 @@ int make_periodic(unsigned int period, PeriodicData *info)
info->wakeups_missed = 0;
info->timer_fd = fd;
- if (fd == -1)
- {
- DLT_LOG(watchdogContext, DLT_LOG_ERROR,
- DLT_STRING("Can't create timer filedescriptor.\n"));
+ if (fd == -1) {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR,
+ DLT_STRING("Can't create timer filedescriptor.\n"));
return -1;
}
/* Make the timer periodic */
- sec = period/1000000;
+ sec = period / 1000000;
ns = (period - (sec * 1000000)) * 1000;
itval.it_interval.tv_sec = sec;
itval.it_interval.tv_nsec = ns;
@@ -107,88 +101,78 @@ int make_periodic(unsigned int period, PeriodicData *info)
void watchdog_thread(void *v_conf)
{
- char str[512];
- char *watchdogUSec;
- unsigned int watchdogTimeoutSeconds;
- unsigned int notifiyPeriodNSec;
- PeriodicData info;
-
- DLT_REGISTER_CONTEXT(watchdogContext, "DOG","dlt system watchdog context.");
-
- sleep(1);
+ char str[512];
+ char *watchdogUSec;
+ unsigned int watchdogTimeoutSeconds;
+ unsigned int notifiyPeriodNSec;
+ PeriodicData info;
- DLT_LOG(watchdogContext, DLT_LOG_INFO,DLT_STRING("Watchdog thread started.\n"));
+ DLT_REGISTER_CONTEXT(watchdogContext, "DOG", "dlt system watchdog context.");
- if (v_conf==0)
- {
- DLT_LOG(watchdogContext, DLT_LOG_ERROR,
- DLT_STRING("Invalid function parameters used for function watchdog_thread.\n"));
- return;
- }
+ sleep(1);
+ DLT_LOG(watchdogContext, DLT_LOG_INFO, DLT_STRING("Watchdog thread started.\n"));
- watchdogUSec = getenv("WATCHDOG_USEC");
+ if (v_conf == 0) {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR,
+ DLT_STRING("Invalid function parameters used for function watchdog_thread.\n"));
+ return;
+ }
- if(watchdogUSec)
- {
- DLT_LOG(watchdogContext, DLT_LOG_DEBUG,DLT_STRING("watchdogusec: "),DLT_STRING(watchdogUSec));
+ watchdogUSec = getenv("WATCHDOG_USEC");
- watchdogTimeoutSeconds = atoi(watchdogUSec);
+ if (watchdogUSec) {
+ DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING("watchdogusec: "), DLT_STRING(watchdogUSec));
- if( watchdogTimeoutSeconds > 0 ){
+ watchdogTimeoutSeconds = atoi(watchdogUSec);
- // Calculate half of WATCHDOG_USEC in ns for timer tick
- notifiyPeriodNSec = watchdogTimeoutSeconds / 2 ;
+ if (watchdogTimeoutSeconds > 0) {
- snprintf(str,512,"systemd watchdog timeout: %u nsec - timer will be initialized: %u nsec\n", watchdogTimeoutSeconds, notifiyPeriodNSec );
- DLT_LOG(watchdogContext, DLT_LOG_DEBUG,DLT_STRING(str));
+ /* Calculate half of WATCHDOG_USEC in ns for timer tick */
+ notifiyPeriodNSec = watchdogTimeoutSeconds / 2;
- if (make_periodic (notifiyPeriodNSec, &info) < 0 )
- {
- DLT_LOG(watchdogContext, DLT_LOG_ERROR,DLT_STRING("Could not initialize systemd watchdog timer\n"));
- return;
- }
+ snprintf(str,
+ 512,
+ "systemd watchdog timeout: %u nsec - timer will be initialized: %u nsec\n",
+ watchdogTimeoutSeconds,
+ notifiyPeriodNSec);
+ DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING(str));
- while (1)
- {
- if(sd_notify(0, "WATCHDOG=1") < 0)
- {
- DLT_LOG(watchdogContext, DLT_LOG_ERROR,DLT_STRING("Could not reset systemd watchdog\n"));
- }
+ if (make_periodic (notifiyPeriodNSec, &info) < 0) {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("Could not initialize systemd watchdog timer\n"));
+ return;
+ }
- DLT_LOG(watchdogContext, DLT_LOG_DEBUG,DLT_STRING("systemd watchdog waited periodic\n"));
+ while (1) {
+ if (sd_notify(0, "WATCHDOG=1") < 0)
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("Could not reset systemd watchdog\n"));
- /* Wait for next period */
- wait_period(&info);
- }
- }
- else
- {
- snprintf(str,512,"systemd watchdog timeout incorrect: %u\n", watchdogTimeoutSeconds);
- DLT_LOG(watchdogContext, DLT_LOG_DEBUG,DLT_STRING(str));
- }
- }
- else
- {
- DLT_LOG(watchdogContext, DLT_LOG_ERROR,DLT_STRING("systemd watchdog timeout (WATCHDOG_USEC) is null\n"));
- }
+ DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING("systemd watchdog waited periodic\n"));
+ /* Wait for next period */
+ wait_period(&info);
+ }
+ }
+ else {
+ snprintf(str, 512, "systemd watchdog timeout incorrect: %u\n", watchdogTimeoutSeconds);
+ DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING(str));
+ }
+ }
+ else {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("systemd watchdog timeout (WATCHDOG_USEC) is null\n"));
+ }
}
void start_systemd_watchdog(DltSystemConfiguration *conf)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,DLT_STRING("Creating thread for systemd watchdog\n"));
-
- static pthread_attr_t t_attr;
- static pthread_t pt;
-
- if (pthread_create(&pt, &t_attr, (void *)watchdog_thread, conf) == 0)
- {
- threads.threads[threads.count++] = pt;
- }
- else
- {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,DLT_STRING("Could not create thread for systemd watchdog\n"));
- }
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Creating thread for systemd watchdog\n"));
+
+ static pthread_attr_t t_attr;
+ static pthread_t pt;
+
+ if (pthread_create(&pt, &t_attr, (void *)watchdog_thread, conf) == 0)
+ threads.threads[threads.count++] = pt;
+ else
+ DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not create thread for systemd watchdog\n"));
}
#endif
diff --git a/src/system/dlt-system.c b/src/system/dlt-system.c
index b826286..317337d 100644
--- a/src/system/dlt-system.c
+++ b/src/system/dlt-system.c
@@ -53,75 +53,73 @@
#include <signal.h>
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
-#include "sd-daemon.h"
+# include "sd-daemon.h"
#endif
DLT_DECLARE_CONTEXT(dltsystem)
-int main(int argc, char* argv[])
+int main(int argc, char *argv[])
{
- DltSystemCliOptions options;
- DltSystemConfiguration config;
+ DltSystemCliOptions options;
+ DltSystemConfiguration config;
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
- int ret;
+ int ret;
#endif
- if(read_command_line(&options, argc, argv) < 0)
- {
- fprintf(stderr, "Failed to read command line!\n");
- return -1;
- }
+ if (read_command_line(&options, argc, argv) < 0) {
+ fprintf(stderr, "Failed to read command line!\n");
+ return -1;
+ }
+
+ if (read_configuration_file(&config, options.ConfigurationFileName) < 0) {
+ fprintf(stderr, "Failed to read configuration file!\n");
+ return -1;
+ }
- if(read_configuration_file(&config, options.ConfigurationFileName) < 0)
- {
- fprintf(stderr, "Failed to read configuration file!\n");
- return -1;
- }
- DLT_REGISTER_APP(config.ApplicationId, "DLT System Manager");
- DLT_REGISTER_CONTEXT(dltsystem,"MGR", "Context of main dlt system manager");
+ DLT_REGISTER_APP(config.ApplicationId, "DLT System Manager");
+ DLT_REGISTER_CONTEXT(dltsystem, "MGR", "Context of main dlt system manager");
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
ret = sd_booted();
- if(ret == 0){
- DLT_LOG(dltsystem, DLT_LOG_INFO, DLT_STRING("system not booted with systemd!\n"));
+ if (ret == 0) {
+ DLT_LOG(dltsystem, DLT_LOG_INFO, DLT_STRING("system not booted with systemd!\n"));
}
- else if(ret < 0)
+ else if (ret < 0)
{
- DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("sd_booted failed!\n"));
- return -1;
+ DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("sd_booted failed!\n"));
+ return -1;
}
- else
- {
- DLT_LOG(dltsystem, DLT_LOG_INFO, DLT_STRING("system booted with systemd\n"));
+ else {
+ DLT_LOG(dltsystem, DLT_LOG_INFO, DLT_STRING("system booted with systemd\n"));
}
+
#endif
- DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Configuration loaded."));
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Configuration loaded."));
+
+ if (options.Daemonize > 0) {
+ if (daemonize() < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_FATAL, DLT_STRING("Daemonization failed!"));
+ return -1;
+ }
- if(options.Daemonize > 0)
- {
- if(daemonize() < 0)
- {
- DLT_LOG(dltsystem, DLT_LOG_FATAL, DLT_STRING("Daemonization failed!"));
- return -1;
- }
- DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system daemonized."));
- }
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system daemonized."));
+ }
- DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Setting signal handlers for abnormal exit"));
- signal(SIGTERM, dlt_system_signal_handler);
- signal(SIGHUP, dlt_system_signal_handler);
- signal(SIGQUIT, dlt_system_signal_handler);
- signal(SIGINT, dlt_system_signal_handler);
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Setting signal handlers for abnormal exit"));
+ signal(SIGTERM, dlt_system_signal_handler);
+ signal(SIGHUP, dlt_system_signal_handler);
+ signal(SIGQUIT, dlt_system_signal_handler);
+ signal(SIGINT, dlt_system_signal_handler);
- DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Launching threads."));
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Launching threads."));
- start_threads(&config);
- join_threads();
- return 0;
+ start_threads(&config);
+ join_threads();
+ return 0;
}
diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h
index c415ad7..6f068ec 100644
--- a/src/system/dlt-system.h
+++ b/src/system/dlt-system.h
@@ -56,12 +56,12 @@
#ifndef DLT_SYSTEM_H_
#define DLT_SYSTEM_H_
-// DLT related includes.
+/* DLT related includes. */
#include "dlt.h"
#include "dlt_common.h"
-// Constants
-#define DEFAULT_CONF_FILE ( CONFIGURATION_FILES_DIR "/dlt-system.conf")
+/* 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
@@ -74,113 +74,113 @@
#define MAX_THREADS 8
-// Macros
-#define MALLOC_ASSERT(x) if(x == NULL) {\
- fprintf(stderr, "Out of memory\n");\
- abort();}
+/* Macros */
+#define MALLOC_ASSERT(x) if (x == NULL) { \
+ fprintf(stderr, "Out of memory\n"); \
+ abort(); }
/**
* Configuration structures.
* Please see dlt-system.conf for explanation of all the options.
*/
-// Command line options
+/* Command line options */
typedef struct {
- char *ConfigurationFileName;
- int Daemonize;
+ char *ConfigurationFileName;
+ int Daemonize;
} DltSystemCliOptions;
-// Configuration shell options
+/* Configuration shell options */
typedef struct {
- int Enable;
+ int Enable;
} ShellOptions;
-// Configuration syslog options
+/* Configuration syslog options */
typedef struct {
- int Enable;
- char *ContextId;
- int Port;
+ int Enable;
+ char *ContextId;
+ int Port;
} SyslogOptions;
-// Configuration journal options
+/* Configuration journal options */
typedef struct {
- int Enable;
- char *ContextId;
- int CurrentBoot;
- int Follow;
- int MapLogLevels;
+ int Enable;
+ char *ContextId;
+ int CurrentBoot;
+ int Follow;
+ int MapLogLevels;
} JournalOptions;
typedef struct {
- int Enable;
- char *ContextId;
- int TimeStartup;
- int TimeDelay;
- 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];
+ int Enable;
+ char *ContextId;
+ int TimeStartup;
+ int TimeDelay;
+ 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 Enable;
-
- // Variable number of files to transfer
- int Count;
- char *ContextId[DLT_SYSTEM_LOG_FILE_MAX];
- char *Filename[DLT_SYSTEM_LOG_FILE_MAX];
- int Mode[DLT_SYSTEM_LOG_FILE_MAX];
- int TimeDelay[DLT_SYSTEM_LOG_FILE_MAX];
+ int Enable;
+
+ /* Variable number of files to transfer */
+ int Count;
+ char *ContextId[DLT_SYSTEM_LOG_FILE_MAX];
+ 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;
-
- // 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];
+ int Enable;
+ char *ContextId;
+
+ /* 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;
- ShellOptions Shell;
- SyslogOptions Syslog;
- JournalOptions Journal;
- FiletransferOptions Filetransfer;
- LogFileOptions LogFile;
- LogProcessOptions LogProcesses;
+ char *ApplicationId;
+ ShellOptions Shell;
+ SyslogOptions Syslog;
+ JournalOptions Journal;
+ FiletransferOptions Filetransfer;
+ LogFileOptions LogFile;
+ LogProcessOptions LogProcesses;
} DltSystemConfiguration;
typedef struct {
- pthread_t threads[MAX_THREADS];
- int count;
- int shutdown;
+ pthread_t threads[MAX_THREADS];
+ int count;
+ int shutdown;
} DltSystemThreads;
/**
* Forward declarations for the whole application
*/
-// In dlt-system-options.c
+/* In dlt-system-options.c */
int read_command_line(DltSystemCliOptions *options, int argc, char *argv[]);
int read_configuration_file(DltSystemConfiguration *config, char *file_name);
-// In dlt-process-handling.c
+/* In dlt-process-handling.c */
int daemonize();
void start_threads(DltSystemConfiguration *config);
void join_threads();
void dlt_system_signal_handler(int sig);
void register_with_dlt(DltSystemConfiguration *config);
-// Thread initiators:
+/* Thread initiators: */
void init_shell();
void start_syslog();
void start_filetransfer(DltSystemConfiguration *conf);