diff options
author | Lassi Marttala <lassi.lm.marttala@partner.bmw.de> | 2012-05-30 11:56:22 +0200 |
---|---|---|
committer | Christian Muck <christian.muck@bmw.de> | 2012-06-13 23:52:40 +0200 |
commit | bea4e475456745f444e2451415366d0e283f835c (patch) | |
tree | b9a84d2fbf19784f1b33f5c59f5d664b3d8b8dc4 /src/system | |
parent | f8f80a07afd45d60c2975bfd7e4b859fb8c10a96 (diff) | |
download | DLT-daemon-bea4e475456745f444e2451415366d0e283f835c.tar.gz |
dlt-system: Logging of error conditions. Assert memory allocations.
dlt-system: logfile module would sometimes deadlock in the end of a
file because of feof() reset in the end of the file.
Signed-off-by: Christian Muck <christian.muck@bmw.de>
Diffstat (limited to 'src/system')
-rw-r--r-- | src/system/dlt-system-filetransfer.c | 35 | ||||
-rw-r--r-- | src/system/dlt-system-logfile.c | 7 | ||||
-rw-r--r-- | src/system/dlt-system-options.c | 31 | ||||
-rw-r--r-- | src/system/dlt-system-process-handling.c | 4 | ||||
-rw-r--r-- | src/system/dlt-system-processes.c | 5 | ||||
-rw-r--r-- | src/system/dlt-system.h | 5 |
6 files changed, 74 insertions, 13 deletions
diff --git a/src/system/dlt-system-filetransfer.c b/src/system/dlt-system-filetransfer.c index b05fc39..275818e 100644 --- a/src/system/dlt-system-filetransfer.c +++ b/src/system/dlt-system-filetransfer.c @@ -82,6 +82,7 @@ char *unique_name(const char *src) unsigned long l = getFileSerialNumber(src) ^ t; // Length of ULONG_MAX + 1 char *ret = malloc(11); + MALLOC_ASSERT(ret); snprintf(ret, 11, "%lu", l); return ret; } @@ -92,6 +93,7 @@ char *compress_file(char *src, int level) DLT_STRING("dlt-system-filetransfer, compressing file.")); char *buf; char *dst = malloc(strlen(src)+4); + MALLOC_ASSERT(dst); char dst_mode[8]; sprintf(dst, "%s.gz", src); sprintf(dst_mode, "wb%d", level); @@ -116,6 +118,7 @@ char *compress_file(char *src, int level) } buf = malloc(Z_CHUNK_SZ); + MALLOC_ASSERT(buf); while(!feof(src_file)) { @@ -130,7 +133,8 @@ char *compress_file(char *src, int level) gzwrite(dst_file, buf, read); } - remove(src); + 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); @@ -147,8 +151,21 @@ int send_one(char *src, FiletransferOptions opts, int which) char *fn = basename(src); char *rn = unique_name(src); char *dst = malloc(strlen(opts.TempDir)+strlen(rn)+2); + MALLOC_ASSERT(fn); + MALLOC_ASSERT(rn); + MALLOC_ASSERT(dst); + sprintf(dst, "%s/%s", opts.TempDir, rn); - rename(src, dst); + if(rename(src, dst) < 0) + { + DLT_LOG(dltsystem, DLT_LOG_ERROR, + DLT_STRING("Could not move file"), + DLT_STRING(src), + DLT_STRING(dst)); + free(rn); + free(dst); + return -1; + } // Compress if needed if(opts.Compression[which] > 0) @@ -156,6 +173,7 @@ int send_one(char *src, FiletransferOptions opts, int which) dst = compress_file(dst, opts.CompressionLevel[which]); char *old_fn = fn; fn = malloc(strlen(old_fn)+4); + MALLOC_ASSERT(fn); sprintf(fn, "%s.gz", old_fn); } @@ -208,11 +226,19 @@ int flush_dir(FiletransferOptions opts, int which) DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, old file found in directory.")); fn = malloc(strlen(sdir)+dp->d_reclen+2); + MALLOC_ASSERT(fn); sprintf(fn, "%s/%s", sdir, dp->d_name); if(send_one(fn, opts, which) < 0) return -1; } } + else + { + DLT_LOG(dltsystem, DLT_LOG_ERROR, + DLT_STRING("Could not open directory"), + DLT_STRING(sdir)); + return -1; + } closedir(dir); return 0; } @@ -251,7 +277,7 @@ int init_filetransfer_dirs(FiletransferOptions opts) int wait_for_files(FiletransferOptions opts) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, waiting for files.")); - char buf[INOTIFY_LEN]; + static char buf[INOTIFY_LEN]; int len = read(ino.handle, buf, INOTIFY_LEN); if(len < 0) { @@ -302,7 +328,10 @@ void filetransfer_thread(void *v_conf) 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-logfile.c b/src/system/dlt-system-logfile.c index 8872d20..63c81b5 100644 --- a/src/system/dlt-system-logfile.c +++ b/src/system/dlt-system-logfile.c @@ -79,6 +79,7 @@ void send_file(LogFileOptions fileopt, int n) 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)); @@ -86,6 +87,12 @@ void send_file(LogFileOptions fileopt, int n) } 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 fileopts) diff --git a/src/system/dlt-system-options.c b/src/system/dlt-system-options.c index 67ae2d4..98de12d 100644 --- a/src/system/dlt-system-options.c +++ b/src/system/dlt-system-options.c @@ -102,6 +102,7 @@ int read_command_line(DltSystemCliOptions *options, int argc, char *argv[]) case 'c': { options->ConfigurationFileName = malloc(strlen(optarg)+1); + MALLOC_ASSERT(options->ConfigurationFileName); strcpy(options->ConfigurationFileName, optarg); break; } @@ -134,14 +135,14 @@ void init_configuration(DltSystemConfiguration *config) // Syslog config->Syslog.Enable = 0; config->Syslog.ContextId = "SYSL"; - config->Syslog.Port = 47111; + config->Syslog.Port = 47111; // File transfer - config->Filetransfer.Enable = 0; + config->Filetransfer.Enable = 0; config->Filetransfer.ContextId = "FILE"; config->Filetransfer.TimeDelay = 10; config->Filetransfer.TimeStartup = 30; - config->Filetransfer.TimeoutBetweenLogs = 10; + config->Filetransfer.TimeoutBetweenLogs = 10; config->Filetransfer.Count = 0; for(i = 0;i < DLT_SYSTEM_LOG_DIRS_MAX;i++) { @@ -157,19 +158,19 @@ void init_configuration(DltSystemConfiguration *config) { config->LogFile.ContextId[i] = NULL; config->LogFile.Filename[i] = NULL; - config->LogFile.Mode[i] = 0; + config->LogFile.Mode[i] = 0; config->LogFile.TimeDelay[i] = 0; } // Log process - config->LogProcesses.Enable = 0; + 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.Name[i] = NULL; + config->LogProcesses.Filename[i] = NULL; + config->LogProcesses.Mode[i] = 0; config->LogProcesses.TimeDelay[i] = 0; } } @@ -197,6 +198,10 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) 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; @@ -227,6 +232,7 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) if(strcmp(token, "ApplicationId") == 0) { config->ApplicationId = malloc(strlen(value)+1); + MALLOC_ASSERT(config->ApplicationId); strcpy(config->ApplicationId, value); } @@ -238,6 +244,7 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) else if(strcmp(token, "SyslogContextId") == 0) { config->Syslog.ContextId = malloc(strlen(value)+1); + MALLOC_ASSERT(config->Syslog.ContextId); strcpy(config->Syslog.ContextId, value); } else if(strcmp(token, "SyslogPort") == 0) @@ -253,6 +260,7 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) else if(strcmp(token, "FiletransferContextId") == 0) { config->Filetransfer.ContextId = malloc(strlen(value)+1); + MALLOC_ASSERT(config->Filetransfer.ContextId); strcpy(config->Filetransfer.ContextId, value); } else if(strcmp(token, "FiletransferTimeStartup") == 0) @@ -270,11 +278,13 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) else if(strcmp(token, "FiletransferTempDir") == 0) { config->Filetransfer.TempDir = malloc(strlen(value)+1); + MALLOC_ASSERT(config->Filetransfer.TempDir); strcpy(config->Filetransfer.TempDir, value); } 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); } else if(strcmp(token, "FiletransferCompression") == 0) @@ -306,6 +316,7 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) 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); } else if(strcmp(token, "LogFileMode") == 0) @@ -319,6 +330,7 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) 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); if(config->LogFile.Count < (DLT_SYSTEM_LOG_FILE_MAX - 1)) { @@ -343,16 +355,19 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) else if(strcmp(token, "LogProcessesContextId") == 0) { config->LogProcesses.ContextId = malloc(strlen(value)+1); + MALLOC_ASSERT(config->LogProcesses.ContextId); strcpy(config->LogProcesses.ContextId, value); } 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); } 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); } else if(strcmp(token, "LogProcessMode") == 0) diff --git a/src/system/dlt-system-process-handling.c b/src/system/dlt-system-process-handling.c index 30568f1..3837d35 100644 --- a/src/system/dlt-system-process-handling.c +++ b/src/system/dlt-system-process-handling.c @@ -80,9 +80,9 @@ int daemonize() for(i = getdtablesize(); i >= 0; i--) close(i); - int fd = i=open("/dev/null",O_RDWR); + int fd = open("/dev/null",O_RDWR); - if(fd < 0 || dup(i) < 0 || dup(i) < 0) + if(fd < 0 || dup(fd) < 0 || dup(fd) < 0) return -1; /** diff --git a/src/system/dlt-system-processes.c b/src/system/dlt-system-processes.c index fd475b8..fc46c97 100644 --- a/src/system/dlt-system-processes.c +++ b/src/system/dlt-system-processes.c @@ -114,6 +114,11 @@ void send_process(LogProcessOptions popts, int n) } 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!")); diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h index d603dcf..fd741dc 100644 --- a/src/system/dlt-system.h +++ b/src/system/dlt-system.h @@ -70,6 +70,11 @@ #define MAX_THREADS 8 +// 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. |