summaryrefslogtreecommitdiff
path: root/src/shared/dlt_common.c
diff options
context:
space:
mode:
authorStefan Vacek <stefan.vacek@intel.com>2015-08-31 10:13:07 +0200
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2015-10-07 10:38:03 +0200
commited412acac8e9f8a5745e55adeed9652b34b9ee4f (patch)
treedd2dbde29e126c679218b7cf93455601bbeca9bd /src/shared/dlt_common.c
parent4c8d43322e89b87288fb5ba12e523237e620481b (diff)
downloadDLT-daemon-ed412acac8e9f8a5745e55adeed9652b34b9ee4f.tar.gz
Allow multiple instances of dlt-daemon
- Make dlt-daemon configurable to specify directory of fifos and port of dlt-daemon, this allows to run multiple instances of dlt-daemon at one node at the same time. This is useful in testing environment where simultanous tests should not interfere due to the same instance of dlt-daemon - dlt-daemon: add option -t <dir> to specify a directory where all fifos will be created - dlt-daemon: add option -p <port> to specify the port under which dlt-daemon can be connected - client-library: add environment variable DLT_PIPE_DIR to specify a non-default directory of fifos for logging applications - client-library: add environment variable DLT_DAEMON_TCP_PORT to specify the port under which dlt-daemon can be reached (especially when using dlt-receive) Signed-off-by: Stefan Vacek <stefan.vacek@intel.com> Signed-off-by: Lutz Helwing <lutz_helwing@mentor.com>
Diffstat (limited to 'src/shared/dlt_common.c')
-rw-r--r--src/shared/dlt_common.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index 98852fd..b0123b6 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -34,6 +34,9 @@
#include <limits.h> /* for NAME_MAX */
#include <inttypes.h> /* for PRI formatting macro */
+#include <errno.h>
+#include <sys/stat.h> /* for mkdir() */
+
#include "dlt_common.h"
#include "dlt_common_cfg.h"
@@ -64,6 +67,7 @@ static char str[DLT_COMMON_BUFFER_LENGTH];
const char dltSerialHeader[DLT_ID_SIZE] = { 'D','L','S',1 };
char dltSerialHeaderChar[DLT_ID_SIZE] = { 'D','L','S',1 };
+char dltFifoBaseDir[PATH_MAX + 1] = "/tmp";
/* internal logging parameters */
static int logging_mode = DLT_LOG_TO_CONSOLE;
@@ -1983,6 +1987,12 @@ void dlt_log_set_filename(const char *filename)
}
+void dlt_log_set_fifo_basedir(const char * env_pipe_dir)
+{
+ strncpy(dltFifoBaseDir, env_pipe_dir, PATH_MAX);
+ dltFifoBaseDir[PATH_MAX] = 0;
+}
+
void dlt_log_init(int mode)
{
logging_mode = mode;
@@ -3723,5 +3733,48 @@ void dlt_check_envvar()
}
}
+ char* env_pipe_dir = getenv("DLT_PIPE_DIR");
+ if( env_pipe_dir != NULL )
+ {
+ dlt_log_set_fifo_basedir(env_pipe_dir);
+ }
+}
+
+int dlt_mkdir_recursive(const char *dir)
+{
+ int ret = 0;
+ char tmp[PATH_MAX+1];
+ char *p = NULL;
+ char *end = NULL;
+ size_t len;
+
+ strncpy(tmp, dir, PATH_MAX);
+ len = strlen(tmp);
+ if(tmp[len - 1] == '/')
+ {
+ tmp[len - 1] = 0;
+ }
+ end = tmp + len;
+
+ for(p = tmp + 1; ((*p) && (ret == 0)) || ((ret == -1 && errno == EEXIST) && (p != end)); p++)
+ {
+ if(*p == '/')
+ {
+ *p = 0;
+ ret = mkdir(tmp, S_IRWXU);
+ *p = '/';
+ }
+ }
+
+ if (ret == 0 || (ret == -1 && errno == EEXIST))
+ {
+ ret = mkdir(tmp, S_IRWXU);
+ }
+
+ if (ret == -1 && errno == EEXIST)
+ {
+ ret = 0;
+ }
+ return ret;
}