summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLassi Marttala <lassi.lm.marttala@partner.bmw.com>2012-03-12 11:14:04 +0100
committerChristian Muck <christian.muck@bmw.de>2012-04-04 14:28:55 +0200
commiteef19a29d6d6926c2143fda94ec3b3d7dc894b77 (patch)
tree18df77056bba5b8059ee54f7b1d65d2be99032f7
parentd7ddd0ff6684c5b22d1405cd6e3b85b339c4db6a (diff)
downloadDLT-daemon-eef19a29d6d6926c2143fda94ec3b3d7dc894b77.tar.gz
GDLT-2, First test for filetransfer change
Signed-off-by: Christian Muck <christian.muck@bmw.de>
-rw-r--r--src/system/dlt-system-log.c42
-rw-r--r--src/system/dlt-system-log.h2
-rwxr-xr-xsrc/system/dlt-system.c9
3 files changed, 51 insertions, 2 deletions
diff --git a/src/system/dlt-system-log.c b/src/system/dlt-system-log.c
index 4f3e014..2ff2809 100644
--- a/src/system/dlt-system-log.c
+++ b/src/system/dlt-system-log.c
@@ -63,6 +63,7 @@
#include <time.h>
#include <dirent.h>
#include <zlib.h>
+#include <sys/inotify.h>
#include "dlt_common.h"
#include "dlt_user.h"
@@ -151,10 +152,30 @@ int dlt_system_compress_file(char *src_name, int level)
}
void dlt_system_filetransfer_init(DltSystemOptions *options,DltSystemRuntime *runtime)
+=======
+int dlt_system_inotify_handle;
+#define INOTIFY_SZ (sizeof(struct inotify_event))
+#define INOTIFY_LEN (INOTIFY_SZ + 1024)
+
+int dlt_system_filetransfer_init(DltSystemOptions *options,DltSystemRuntime *runtime)
+>>>>>>> 228b6d6... First test for filetransfer change
{
runtime->filetransferFile[0] = 0;
runtime->filetransferRunning = 0;
runtime->filetransferCountPackages = 0;
+
+ // Initialize watch for filetransfer directories.
+ dlt_system_inotify_handle = inotify_init1(IN_NONBLOCK);
+ if(dlt_system_inotify_handle < 0) {
+ return -1;
+ }
+
+ // We can discard the descriptors.
+ // They will be closed automatically on program exit.
+ if(inotify_add_watch(dlt_system_inotify_handle, options->FiletransferDirectory1, IN_CLOSE_WRITE|IN_MOVED_TO) < 0)
+ return -1;
+ if(inotify_add_watch(dlt_system_inotify_handle, options->FiletransferDirectory2, IN_CLOSE_WRITE|IN_MOVED_TO) < 0)
+ return -1;
}
void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *runtime,DltContext *context)
@@ -166,6 +187,7 @@ void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *run
int transferResult;
int total_size, used_size;
DIR *dir;
+ static char inotify_buf[INOTIFY_LEN];
if(runtime->filetransferRunning == 0) {
/* delete last transmitted file */
@@ -184,6 +206,26 @@ void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *run
runtime->filetransferFile[0]=0;
}
+ /* Check inotify watches */
+ int len = read(dlt_system_inotify_handle, inotify_buf, INOTIFY_LEN);
+ if(len < 0)
+ {
+ fprintf(stderr, "dlt_system_filetransfer_run:\n%s", strerror(errno));
+ return;
+ }
+
+ int i = 0;
+ while(i < len)
+ {
+ struct inotify_event *event = (struct inotify_event *) &inotify_buf[i];
+ printf("inotify: %s \n", event->name);
+ if(event->mask | IN_CLOSE_WRITE)
+ printf("IN_CLOSE_WRITE\n");
+ if(event->mask | IN_MOVED_TO)
+ printf("IN_MOVED_TO\n");
+ i += INOTIFY_SZ + event->len;
+ }
+
/* filetransfer not running, check directory */
filename[0] = 0;
dir = opendir(options->FiletransferDirectory1);
diff --git a/src/system/dlt-system-log.h b/src/system/dlt-system-log.h
index d79ce8e..a9940ba 100644
--- a/src/system/dlt-system-log.h
+++ b/src/system/dlt-system-log.h
@@ -57,7 +57,7 @@
#ifndef DLT_SYSTEM_LOG_H
#define DLT_SYSTEM_LOG_H
-extern void dlt_system_filetransfer_init(DltSystemOptions *options,DltSystemRuntime *runtime);
+extern int dlt_system_filetransfer_init(DltSystemOptions *options,DltSystemRuntime *runtime);
extern void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *runtime,DltContext *context);
extern void dlt_system_log_file(DltSystemOptions *options,DltContext *context,int num);
diff --git a/src/system/dlt-system.c b/src/system/dlt-system.c
index 7ad10fb..13bc0bc 100755
--- a/src/system/dlt-system.c
+++ b/src/system/dlt-system.c
@@ -637,7 +637,14 @@ int main(int argc, char* argv[])
/* initialise filetransfer manager */
if(options.FiletransferEnable)
- dlt_system_filetransfer_init(&options,&runtime);
+ {
+ if(dlt_system_filetransfer_init(&options,&runtime) < 0)
+ {
+ dprintf("Error initializing filetransfer:\n%s", strerror(errno));
+ return -1;
+ }
+ }
+
while (1)
{