summaryrefslogtreecommitdiff
path: root/src/daemon
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/daemon
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/daemon')
-rw-r--r--src/daemon/dlt-daemon.c95
-rw-r--r--src/daemon/dlt-daemon.h3
-rw-r--r--src/daemon/dlt_daemon_common.c4
-rw-r--r--src/daemon/dlt_daemon_socket.c6
-rw-r--r--src/daemon/dlt_daemon_socket.h2
5 files changed, 84 insertions, 26 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 0c70cde..5022da4 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -96,6 +96,14 @@ void usage()
printf(" -d Daemonize\n");
printf(" -h Usage\n");
printf(" -c filename DLT daemon configuration file (Default: " CONFIGURATION_FILES_DIR "/dlt.conf)\n");
+ printf(" -t directory Directory for local fifo and user-pipes (Default: /tmp)\n");
+ printf(" (Applications wanting to connect to a daemon using a\n");
+ printf(" custom directory need to be started with the environment \n");
+ printf(" variable DLT_PIPE_DIR set appropriately)\n");
+ printf(" -p port port to monitor for incoming requests (Default: 3490)\n");
+ printf(" (Applications wanting to connect to a daemon using a custom\n");
+ printf(" port need to be started with the environment variable\n");
+ printf(" DLT_DAEMON_TCP_PORT set appropriately)\n");
} /* usage() */
/**
@@ -114,9 +122,13 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[])
/* Initialize flags */
memset(daemon_local,0,sizeof(DltDaemonLocal));
+ /* default values */
+ daemon_local->flags.port = DLT_DAEMON_TCP_PORT;
+ strncpy(dltFifoBaseDir, "/tmp", NAME_MAX);
+
opterr = 0;
- while ((c = getopt (argc, argv, "hdc:")) != -1)
+ while ((c = getopt (argc, argv, "hdc:t:p:")) != -1)
{
switch (c)
{
@@ -130,6 +142,21 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[])
strncpy(daemon_local->flags.cvalue,optarg,NAME_MAX);
break;
}
+ case 't':
+ {
+ strncpy(dltFifoBaseDir, optarg, NAME_MAX);
+ break;
+ }
+ case 'p':
+ {
+ daemon_local->flags.port = atoi(optarg);
+ if (daemon_local->flags.port == 0)
+ {
+ fprintf (stderr, "Invalid port `%s' specified.\n", optarg);
+ return -1;
+ }
+ break;
+ }
case 'h':
{
usage();
@@ -137,7 +164,7 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[])
}
case '?':
{
- if (optopt == 'c')
+ if (optopt == 'c' || optopt == 't' || optopt == 'p')
{
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
}
@@ -161,6 +188,9 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[])
} /* switch() */
}
+ snprintf(daemon_local->flags.userPipesDir, NAME_MAX + 1, "%s/dltpipes", dltFifoBaseDir);
+ snprintf(daemon_local->flags.daemonFifoName, NAME_MAX + 1, "%s/dlt", dltFifoBaseDir);
+
return 0;
} /* option_handling() */
@@ -186,7 +216,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.offlineTraceMaxSize = 0;
daemon_local->flags.loggingMode = DLT_LOG_TO_CONSOLE;
daemon_local->flags.loggingLevel = LOG_INFO;
- strncpy(daemon_local->flags.loggingFilename, DLT_USER_DIR "/dlt.log",sizeof(daemon_local->flags.loggingFilename)-1);
+ snprintf(daemon_local->flags.loggingFilename, sizeof(daemon_local->flags.loggingFilename)-1, "%s/dlt.log", dltFifoBaseDir);
daemon_local->flags.loggingFilename[sizeof(daemon_local->flags.loggingFilename)-1]=0;
daemon_local->timeoutOnSend = 4;
daemon_local->RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE;
@@ -444,6 +474,14 @@ int main(int argc, char* argv[])
PRINT_FUNCTION_VERBOSE(daemon_local.flags.vflag);
+ /* Make sure the parent user directory is created */
+ if (dlt_mkdir_recursive(dltFifoBaseDir) != 0)
+ {
+ snprintf(str,DLT_DAEMON_TEXTBUFSIZE, "Base dir %s cannot be created!\n", dltFifoBaseDir);
+ dlt_log(LOG_ERR, str);
+ return -1;
+ }
+
/* --- Daemon init phase 1 begin --- */
if (dlt_daemon_local_init_p1(&daemon, &daemon_local, daemon_local.flags.vflag)==-1)
{
@@ -671,20 +709,22 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
}
#endif
+ const char *tmpFifo = daemon_local->flags.userPipesDir;
+
/* create dlt pipes directory */
- ret=mkdir(DLT_USER_DIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX );
+ ret=mkdir(tmpFifo, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX );
if (ret==-1 && errno != EEXIST)
{
- snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"FIFO user dir %s cannot be created (%s)!\n", DLT_USER_DIR, strerror(errno));
+ snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"FIFO user dir %s cannot be created (%s)!\n", tmpFifo, strerror(errno));
dlt_log(LOG_WARNING, str);
return -1;
}
// S_ISGID cannot be set by mkdir, let's reassign right bits
- ret=chmod(DLT_USER_DIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH | S_ISGID | S_ISVTX );
+ ret=chmod(tmpFifo, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH | S_ISGID | S_ISVTX );
if (ret==-1)
{
- snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"FIFO user dir %s cannot be chmoded (%s)!\n", DLT_USER_DIR, strerror(errno));
+ snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"FIFO user dir %s cannot be chmoded (%s)!\n", tmpFifo, strerror(errno));
dlt_log(LOG_WARNING, str);
return -1;
}
@@ -846,27 +886,30 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon, DltDaemonLocal *daemon_l
umask(0);
/* Try to delete existing pipe, ignore result of unlink */
- unlink(DLT_USER_FIFO);
+ const char *tmpFifo = daemon_local->flags.daemonFifoName;
+ unlink(tmpFifo);
- ret=mkfifo(DLT_USER_FIFO, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
+ ret=mkfifo(tmpFifo, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
if (ret==-1)
{
- snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"FIFO user %s cannot be created (%s)!\n",DLT_USER_FIFO, strerror(errno));
+ snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"FIFO user %s cannot be created (%s)!\n",tmpFifo, strerror(errno));
dlt_log(LOG_WARNING, str);
return -1;
} /* if */
- daemon_local->fp = open(DLT_USER_FIFO, O_RDWR);
+ daemon_local->fp = open(tmpFifo, O_RDWR);
if (daemon_local->fp==-1)
{
- snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"FIFO user %s cannot be opened (%s)!\n",DLT_USER_FIFO, strerror(errno));
+ snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"FIFO user %s cannot be opened (%s)!\n",tmpFifo, strerror(errno));
dlt_log(LOG_WARNING, str);
return -1;
} /* if */
/* create and open socket to receive incoming connections from client */
- if(dlt_daemon_socket_open(&(daemon_local->sock)))
+ if(dlt_daemon_socket_open(&(daemon_local->sock), daemon_local->flags.port))
+ {
return -1;
+ }
/* prepare usage of select(), add FIFO and receiving socket */
FD_ZERO(&(daemon_local->master));
@@ -1044,7 +1087,7 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i
dlt_file_free(&(daemon_local->file),daemon_local->flags.vflag);
/* Try to delete existing pipe, ignore result of unlink() */
- unlink(DLT_USER_FIFO);
+ unlink(daemon_local->flags.daemonFifoName);
#ifdef DLT_SHM_ENABLE
/* free shared memory */
@@ -1069,10 +1112,16 @@ void dlt_daemon_signal_handler(int sig)
dlt_log(LOG_NOTICE, str);
/* Try to delete existing pipe, ignore result of unlink() */
- unlink(DLT_USER_FIFO);
+ char tmp[PATH_MAX + 1];
+ snprintf(tmp, PATH_MAX, "%s/dlt", dltFifoBaseDir);
+ tmp[PATH_MAX] = 0;
+ unlink(tmp);
/* Try to delete lock file, ignore result of unlink() */
- unlink(DLT_DAEMON_LOCK_FILE);
+ snprintf(tmp, PATH_MAX, "%s/%s", dltFifoBaseDir, DLT_DAEMON_LOCK_FILE);
+ tmp[PATH_MAX] = 0;
+ unlink(tmp);
+
/* Terminate program */
exit(0);
@@ -1138,12 +1187,18 @@ void dlt_daemon_daemonize(int verbose)
umask(DLT_DAEMON_UMASK);
/* Change to known directory */
- if(chdir(DLT_USER_DIR) < 0)
- dlt_log(LOG_WARNING, "Failed to chdir to DLT_USER_DIR.\n");;
+ if(chdir(dltFifoBaseDir) < 0)
+ {
+ snprintf(str, DLT_DAEMON_TEXTBUFSIZE, "Failed to chdir to fifo-dir %s\n", dltFifoBaseDir);
+ dlt_log(LOG_WARNING, str);
+ }
- /* Ensure single copy of daemon;
+ /* Ensure single copy of daemon; if started with same directory
run only one instance at a time */
- lfp=open(DLT_DAEMON_LOCK_FILE,O_RDWR|O_CREAT,DLT_DAEMON_LOCK_FILE_PERM);
+ char dlt_daemon_lock_file[PATH_MAX + 1];
+ snprintf(dlt_daemon_lock_file, PATH_MAX, "%s/%s", dltFifoBaseDir, DLT_DAEMON_LOCK_FILE);
+ dlt_daemon_lock_file[PATH_MAX] = 0;
+ lfp=open(dlt_daemon_lock_file,O_RDWR|O_CREAT,DLT_DAEMON_LOCK_FILE_PERM);
if (lfp<0)
{
dlt_log(LOG_CRIT, "Can't open lock file, exiting DLT daemon\n");
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index fee6767..8edeead 100644
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -112,6 +112,9 @@ typedef struct
char pathToECUSoftwareVersion[256]; /**< (String: Filename) The file from which to read the ECU version from. */
int sendTimezone; /**< (Boolean) Send Timezone perdiodically */
int offlineLogstorageMaxDevices; /**< (int) Maximum devices to be used as offline logstorage devices */
+ char userPipesDir[NAME_MAX + 1]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */
+ char daemonFifoName[NAME_MAX + 1]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */
+ unsigned int port; /**< port number */
} DltDaemonFlags;
/**
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 2064e94..af97b16 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -390,7 +390,7 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pi
{
if ( close(application->user_handle) < 0 )
{
- snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "close() failed to %s, errno=%d (%s)!\n",filename,errno,strerror(errno)); /* errno 2: ENOENT - No such file or directory */
+ snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "close() failed to %s/dltpipes/dlt%d, errno=%d (%s)!\n",dltFifoBaseDir,pid,errno,strerror(errno)); /* errno 2: ENOENT - No such file or directory */
dlt_log(LOG_WARNING, str);
}
@@ -402,7 +402,7 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pi
/* open user pipe only if it is not yet opened */
if (application->user_handle==DLT_FD_INIT && pid!=0)
{
- snprintf(filename,DLT_DAEMON_COMMON_TEXTBUFSIZE,"%s/dlt%d",DLT_USER_DIR,pid);
+ snprintf(filename,DLT_DAEMON_COMMON_TEXTBUFSIZE,"%s/dltpipes/dlt%d",dltFifoBaseDir,pid);
dlt_user_handle = open(filename, O_WRONLY|O_NONBLOCK);
if ( dlt_user_handle < 0 )
diff --git a/src/daemon/dlt_daemon_socket.c b/src/daemon/dlt_daemon_socket.c
index 709868f..fa91485 100644
--- a/src/daemon/dlt_daemon_socket.c
+++ b/src/daemon/dlt_daemon_socket.c
@@ -63,7 +63,7 @@
/** Global text output buffer, mainly used for creation of error/warning strings */
static char str[DLT_DAEMON_TEXTBUFSIZE];
-int dlt_daemon_socket_open(int *sock)
+int dlt_daemon_socket_open(int *sock, unsigned int servPort)
{
int yes = 1;
char portnumbuffer[33];
@@ -75,7 +75,7 @@ int dlt_daemon_socket_open(int *sock)
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE; // use my IP address
- sprintf(portnumbuffer, "%d", DLT_DAEMON_TCP_PORT);
+ snprintf(portnumbuffer, 32, "%d", servPort);
if ((rv = getaddrinfo(NULL, portnumbuffer, &hints, &servinfo)) != 0) {
snprintf(str, DLT_DAEMON_TEXTBUFSIZE, "getaddrinfo: %s\n", gai_strerror(rv));
dlt_log(LOG_WARNING, str);
@@ -115,7 +115,7 @@ int dlt_daemon_socket_open(int *sock)
freeaddrinfo(servinfo);
- snprintf(str, DLT_DAEMON_TEXTBUFSIZE, "%s: Listening on port: %u\n", __FUNCTION__, DLT_DAEMON_TCP_PORT);
+ snprintf(str, DLT_DAEMON_TEXTBUFSIZE, "%s: Listening on port: %u\n", __FUNCTION__, servPort);
dlt_log(LOG_INFO, str);
// get socket buffer size
diff --git a/src/daemon/dlt_daemon_socket.h b/src/daemon/dlt_daemon_socket.h
index 5d4718c..cc8dfb5 100644
--- a/src/daemon/dlt_daemon_socket.h
+++ b/src/daemon/dlt_daemon_socket.h
@@ -62,7 +62,7 @@
#include "dlt_common.h"
#include "dlt_user.h"
-int dlt_daemon_socket_open(int *sock);
+int dlt_daemon_socket_open(int *sock, unsigned int servPort);
int dlt_daemon_socket_close(int sock);
int dlt_daemon_socket_get_send_qeue_max_size(int sock);