summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManikandanChockalingam <manikandan.chockalingam@in.bosch.com>2018-05-18 11:17:31 +0530
committerChristoph Lipka <clipka@users.noreply.github.com>2018-05-18 07:47:31 +0200
commitda6eefe5cac244421c5af413c54e420717e11c9e (patch)
treee7eb7745fbc5e0edd3e2bede4d008a05250f1a18 /src
parentf549f5527148b32a15489aae75c9e4557e19cbd4 (diff)
downloadDLT-daemon-da6eefe5cac244421c5af413c54e420717e11c9e.tar.gz
IPC: Unix socket added (#43)
* IPC: Unix socket added The user can select either FIFO or UNIX socket as IPC between user library and daemon through CMakelist option. Socket path configurable for both FIFO and Unix Socket now configurable in CMake Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com> Signed-off-by: ManikandanC <Manikandan.Chockalingam@in.bosch.com>
Diffstat (limited to 'src')
-rw-r--r--src/daemon/CMakeLists.txt1
-rw-r--r--src/daemon/dlt-daemon.c252
-rw-r--r--src/daemon/dlt-daemon.h11
-rw-r--r--src/daemon/dlt_daemon_common.c35
-rw-r--r--src/daemon/dlt_daemon_common.h3
-rw-r--r--src/daemon/dlt_daemon_common_cfg.h5
-rw-r--r--src/daemon/dlt_daemon_connection.c9
-rw-r--r--src/daemon/dlt_daemon_connection_types.h2
-rw-r--r--src/daemon/dlt_daemon_unix_socket.c31
-rw-r--r--src/daemon/dlt_daemon_unix_socket.h5
-rw-r--r--src/lib/dlt_user.c321
-rw-r--r--src/shared/dlt_common.c11
12 files changed, 491 insertions, 195 deletions
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index 83d4302..063913b 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -44,3 +44,4 @@ endif(WITH_DLT_UNIT_TESTS)
INSTALL(FILES dlt.conf
DESTINATION ${CONFIGURATION_FILES_DIR}
COMPONENT base)
+
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 064a008..6611015 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -132,7 +132,7 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[])
/* default values */
daemon_local->flags.port = DLT_DAEMON_TCP_PORT;
- strncpy(dltFifoBaseDir, "/tmp", NAME_MAX);
+ strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, sizeof(DLT_USER_IPC_PATH));
opterr = 0;
@@ -196,7 +196,9 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[])
} /* switch() */
}
+#ifndef DLT_USE_UNIX_SOCKET_IPC
snprintf(daemon_local->flags.userPipesDir, NAME_MAX + 1, "%s/dltpipes", dltFifoBaseDir);
+#endif
snprintf(daemon_local->flags.daemonFifoName, NAME_MAX + 1, "%s/dlt", dltFifoBaseDir);
return 0;
@@ -248,6 +250,14 @@ int option_file_parser(DltDaemonLocal *daemon_local)
strncpy(daemon_local->flags.ctrlSockPath,
DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH,
sizeof(daemon_local->flags.ctrlSockPath) - 1);
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ snprintf(daemon_local->flags.appSockPath, DLT_IPC_PATH_MAX, "%s/dlt", DLT_USER_IPC_PATH);
+ if (strlen(DLT_USER_IPC_PATH) > DLT_IPC_PATH_MAX)
+ {
+ fprintf(stderr,"Provided path too long...trimming it to path[%s]\n",
+ daemon_local->flags.appSockPath);
+ }
+#endif
daemon_local->flags.gatewayMode = 0;
strncpy(daemon_local->flags.gatewayConfigFile,
DLT_GATEWAY_CONFIG_PATH,
@@ -577,6 +587,49 @@ int option_file_parser(DltDaemonLocal *daemon_local)
return 0;
}
+#ifndef DLT_USE_UNIX_SOCKET_IPC
+static DltReturnValue dlt_daemon_create_pipes_dir(char *dir)
+{
+ int ret = DLT_RETURN_OK;
+
+ if (dir == NULL)
+ {
+ dlt_vlog(LOG_ERR, "%s: Invalid parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ /* create dlt pipes directory */
+ ret = mkdir(dir,
+ S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH|S_ISVTX);
+
+ if ((ret == -1) && (errno != EEXIST))
+ {
+ dlt_vlog(LOG_ERR,
+ "FIFO user dir %s cannot be created (%s)!\n",
+ dir,
+ strerror(errno));
+
+ return DLT_RETURN_ERROR;
+ }
+
+ // S_ISGID cannot be set by mkdir, let's reassign right bits
+ ret = chmod(dir,
+ 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)
+ {
+ dlt_vlog(LOG_ERR,
+ "FIFO user dir %s cannot be chmoded (%s)!\n",
+ dir,
+ strerror(errno));
+
+ return DLT_RETURN_ERROR;
+ }
+
+ return ret;
+}
+#endif
+
/**
* Main function of tool.
*/
@@ -621,6 +674,7 @@ int main(int argc, char* argv[])
PRINT_FUNCTION_VERBOSE(daemon_local.flags.vflag);
+#ifndef DLT_USE_UNIX_SOCKET_IPC
/* Make sure the parent user directory is created */
if (dlt_mkdir_recursive(dltFifoBaseDir) != 0)
{
@@ -628,6 +682,7 @@ int main(int argc, char* argv[])
dlt_log(LOG_ERR, str);
return -1;
}
+#endif
/* --- Daemon init phase 1 begin --- */
if (dlt_daemon_local_init_p1(&daemon, &daemon_local, daemon_local.flags.vflag)==-1)
@@ -747,9 +802,8 @@ int main(int argc, char* argv[])
int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
- int ret;
-
PRINT_FUNCTION_VERBOSE(verbose);
+ int ret = DLT_RETURN_OK;
if ((daemon==0) || (daemon_local==0))
{
@@ -760,9 +814,9 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
ret = sd_booted();
- if(ret == 0){
+ if (ret == 0)
+ {
dlt_log(LOG_CRIT, "System not booted with systemd!\n");
-// return -1;
}
else if(ret < 0)
{
@@ -775,25 +829,12 @@ 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(tmpFifo, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX );
- if (ret==-1 && errno != EEXIST)
+#ifndef DLT_USE_UNIX_SOCKET_IPC
+ if (dlt_daemon_create_pipes_dir(daemon_local->flags.userPipesDir) == DLT_RETURN_ERROR)
{
- 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(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", tmpFifo, strerror(errno));
- dlt_log(LOG_WARNING, str);
- return -1;
+ return DLT_RETURN_ERROR;
}
+#endif
/* Check for daemon mode */
if (daemon_local->flags.dflag)
@@ -802,12 +843,13 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
}
/* initialise structure to use DLT file */
- if (dlt_file_init(&(daemon_local->file),daemon_local->flags.vflag) == DLT_RETURN_ERROR)
+ ret = dlt_file_init(&(daemon_local->file),daemon_local->flags.vflag);
+ if (ret == DLT_RETURN_ERROR)
{
dlt_log(LOG_ERR,"Could not initialize file structure\n");
/* Return value ignored, dlt daemon will exit */
dlt_file_free(&(daemon_local->file),daemon_local->flags.vflag);
- return -1;
+ return ret;
}
signal(SIGPIPE,SIG_IGN);
@@ -817,7 +859,7 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
signal(SIGQUIT, dlt_daemon_signal_handler);
signal(SIGINT, dlt_daemon_signal_handler);
- return 0;
+ return DLT_RETURN_OK;
}
int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
@@ -993,6 +1035,7 @@ static int dlt_daemon_init_serial(DltDaemonLocal *daemon_local)
DLT_CONNECTION_CLIENT_MSG_SERIAL);
}
+#ifndef DLT_USE_UNIX_SOCKET_IPC
static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local)
{
int ret;
@@ -1063,6 +1106,7 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local)
EPOLLIN,
DLT_CONNECTION_APP_MSG);
}
+#endif
int dlt_daemon_local_connection_init(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
@@ -1070,6 +1114,8 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon,
{
char local_str[DLT_DAEMON_TEXTBUFSIZE];
int fd = -1;
+ int mask = 0;
+
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (daemon_local == NULL))
@@ -1083,43 +1129,88 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon,
return -1;
}
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ /* create and open socket to receive incoming connections from user application
+ * socket access permission set to srw-rw-rw- (666) */
+ mask = S_IXUSR | S_IXGRP | S_IXOTH;
+ if (dlt_daemon_unix_socket_open(&fd,
+ daemon_local->flags.appSockPath,
+ SOCK_STREAM,
+ mask) == DLT_RETURN_OK)
+ {
+ if (dlt_connection_create(daemon_local,
+ &daemon_local->pEvent,
+ fd,
+ EPOLLIN,
+ DLT_CONNECTION_APP_CONNECT))
+ {
+ dlt_log(LOG_CRIT, "Could not initialize app socket.\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
+ else
+ {
+ dlt_log(LOG_CRIT, "Could not initialize app socket.\n");
+ return DLT_RETURN_ERROR;
+ }
+#else
if (dlt_daemon_init_fifo(daemon_local))
{
dlt_log(LOG_ERR, "Unable to initialize fifo.\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
+#endif
/* create and open socket to receive incoming connections from client */
daemon_local->client_connections = 0;
- if(dlt_daemon_socket_open(&fd, daemon_local->flags.port) ||
- dlt_connection_create(daemon_local,
- &daemon_local->pEvent,
- fd,
- EPOLLIN,
- DLT_CONNECTION_CLIENT_CONNECT))
+ if (dlt_daemon_socket_open(&fd, daemon_local->flags.port) == DLT_RETURN_OK)
+ {
+ if (dlt_connection_create(daemon_local,
+ &daemon_local->pEvent,
+ fd,
+ EPOLLIN,
+ DLT_CONNECTION_CLIENT_CONNECT))
+ {
+ dlt_log(LOG_ERR,"Could not initialize main socket.\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
+ else
{
dlt_log(LOG_ERR,"Could not initialize main socket.\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
/* create and open unix socket to receive incoming connections from
- * control application */
- if (dlt_daemon_unix_socket_open(&fd, daemon_local->flags.ctrlSockPath) ||
- dlt_connection_create(daemon_local,
- &daemon_local->pEvent,
- fd,
- EPOLLIN,
- DLT_CONNECTION_CONTROL_CONNECT))
+ * control application
+ * socket access permission set to srw-rw---- (660) */
+ mask = S_IXUSR | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
+ if (dlt_daemon_unix_socket_open(&fd,
+ daemon_local->flags.ctrlSockPath,
+ SOCK_STREAM,
+ mask) == DLT_RETURN_OK)
+ {
+ if (dlt_connection_create(daemon_local,
+ &daemon_local->pEvent,
+ fd,
+ EPOLLIN,
+ DLT_CONNECTION_CONTROL_CONNECT))
+ {
+ dlt_log(LOG_ERR, "Could not initialize control socket.\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
+ else
{
dlt_log(LOG_ERR, "Could not initialize control socket.\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
/* Init serial */
if (dlt_daemon_init_serial(daemon_local) < 0)
{
dlt_log(LOG_ERR,"Could not initialize daemon data\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
return 0;
@@ -1813,7 +1904,62 @@ int dlt_daemon_process_control_connect(
return 0;
}
-// FIXME: More or less copy of dlt_daemon_process_control_messages
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+int dlt_daemon_process_app_connect(
+ DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
+ int verbose)
+{
+ socklen_t app_size;
+ struct sockaddr_un app;
+ int in_sock = -1;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL))
+ {
+ dlt_vlog(LOG_ERR,
+ "%s: Invalid parameters\n",
+ __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ /* event from UNIX server socket, new connection */
+ app_size = sizeof(app);
+ if ((in_sock = accept(receiver->fd, &app, &app_size)) < 0)
+ {
+ dlt_log(LOG_ERR, "accept() on UNIX socket failed!\n");
+ return -1 ;
+ }
+
+ /* check if file file descriptor was already used, and make it invalid if it
+ * is reused. This prevents sending messages to wrong file descriptor */
+ dlt_daemon_applications_invalidate_fd(daemon, in_sock, verbose);
+ dlt_daemon_contexts_invalidate_fd(daemon, in_sock, verbose);
+
+ if (dlt_connection_create(daemon_local,
+ &daemon_local->pEvent,
+ in_sock,
+ EPOLLIN,
+ DLT_CONNECTION_APP_MSG))
+ {
+ dlt_log(LOG_ERR, "Failed to register new application. \n");
+ close(in_sock);
+ return -1;
+ }
+
+ if (verbose)
+ {
+ snprintf(str,DLT_DAEMON_TEXTBUFSIZE,
+ "New connection to application established\n");
+ dlt_log(LOG_INFO, str);
+ }
+
+ return 0;
+}
+#endif
+
int dlt_daemon_process_control_messages(
DltDaemon *daemon,
DltDaemonLocal *daemon_local,
@@ -1954,6 +2100,7 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon,
int run_loop = 1;
int32_t min_size = (int32_t)sizeof(DltUserHeader);
DltUserHeader *userheader;
+ int recv;
PRINT_FUNCTION_VERBOSE(verbose);
@@ -1965,13 +2112,25 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon,
return -1;
}
- /* read data from FIFO */
- if (dlt_receiver_receive_fd(receiver) < 0)
+ recv = dlt_receiver_receive(receiver);
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ if (recv <= 0)
+ {
+ dlt_daemon_close_socket(receiver->fd,
+ daemon,
+ daemon_local,
+ verbose);
+ receiver->fd = -1;
+ return 0;
+ }
+#else
+ if (recv < 0)
{
dlt_log(LOG_WARNING,
"dlt_receiver_receive_fd() for user messages failed!\n");
return -1;
}
+#endif
/* look through buffer as long as data is in there */
while ((receiver->bytesRcvd >= min_size) && run_loop)
@@ -2177,6 +2336,7 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon,
userapp.apid,
userapp.pid,
description,
+ rec->fd,
verbose);
/* send log state to new application */
@@ -2258,8 +2418,8 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon,
if (len > DLT_DAEMON_DESCSIZE)
{
+ dlt_vlog(LOG_WARNING, "Context description exceeds limit: %d\n", len);
len = DLT_DAEMON_DESCSIZE;
- dlt_log(LOG_WARNING, "Context description exceeds limit\n");
}
/* adjust buffer pointer */
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index 03b062e..80b0760 100644
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -70,14 +70,14 @@
#define DLT_DAEMON_H
#include <limits.h> /* for NAME_MAX */
+#include <sys/time.h>
#include "dlt_daemon_common.h"
#include "dlt_user_shared.h"
#include "dlt_user_shared_cfg.h"
#include "dlt_daemon_event_handler_types.h"
#include "dlt_gateway_types.h"
-#include <dlt_offline_trace.h>
-#include <sys/time.h>
+#include "dlt_offline_trace.h"
#define DLT_DAEMON_FLAG_MAX 256
@@ -119,7 +119,11 @@ typedef struct
unsigned int offlineLogstorageMaxCounter; /**< (int) Maximum offline logstorage file counter index until wraparound */
unsigned int offlineLogstorageMaxCounterIdx; /**< (int) String len of offlineLogstorageMaxCounter*/
unsigned int offlineLogstorageCacheSize; /**< Max cache size offline logstorage cache */
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ char appSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to User socket */
+#else
char userPipesDir[NAME_MAX + 1]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */
+#endif
char daemonFifoName[NAME_MAX + 1]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */
unsigned int port; /**< port number */
char ctrlSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to Control socket */
@@ -191,6 +195,9 @@ int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_l
int dlt_daemon_process_systemd_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
int dlt_daemon_process_control_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+int dlt_daemon_process_app_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
+#endif
int dlt_daemon_process_control_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
typedef int (*dlt_daemon_process_user_message_func)(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose);
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 40d8d5c..f67a162 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -295,13 +295,16 @@ int dlt_daemon_applications_clear(DltDaemon *daemon, int verbose)
return 0;
}
-DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid, pid_t pid, char *description, int verbose)
+DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid, pid_t pid, char *description, int fd, int verbose)
{
DltDaemonApplication *application;
DltDaemonApplication *old;
int new_application;
int dlt_user_handle;
+#ifndef DLT_USE_UNIX_SOCKET_IPC
+ (void) fd; /* To avoid compiler warning : unused variable */
char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE];
+#endif
if ((daemon == NULL) || (apid == NULL) || (apid[0]=='\0'))
{
@@ -382,12 +385,13 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid,
{
if( application->pid != pid )
{
+#ifndef DLT_USE_UNIX_SOCKET_IPC
if ( close(application->user_handle) < 0 )
{
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);
}
-
+#endif
application->user_handle = DLT_FD_INIT;
application->pid = 0;
}
@@ -396,22 +400,29 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid,
/* 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/dltpipes/dlt%d",dltFifoBaseDir,pid);
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ dlt_user_handle = fd;
+#else
+ 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 )
+ if (dlt_user_handle < 0)
{
int prio = (errno == ENOENT) ? LOG_INFO : LOG_WARNING;
dlt_vlog(prio, "open() failed to %s, errno=%d (%s)!\n", filename, errno, strerror(errno));
} /* if */
-
- /* check if file file descriptor was already used, and make it invalid if it is reused */
- /* This prevents sending messages to wrong file descriptor */
+#endif
+ /* check if file descriptor was already used, and make it invalid if it
+ * is reused. This prevents sending messages to wrong file descriptor */
dlt_daemon_applications_invalidate_fd(daemon,dlt_user_handle,verbose);
dlt_daemon_contexts_invalidate_fd(daemon,dlt_user_handle,verbose);
- application->pid = pid;
application->user_handle = dlt_user_handle;
+ application->pid = pid;
}
/* Sort */
@@ -442,7 +453,9 @@ int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *applicat
/* Check if user handle is open; if yes, close it */
if (application->user_handle >= DLT_FD_MINIMUM)
{
+#ifndef DLT_USE_UNIX_SOCKET_IPC
close(application->user_handle);
+#endif
application->user_handle = DLT_FD_INIT;
}
@@ -556,7 +569,7 @@ int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int ve
{
/* pb contains now the description */
/* pid is unknown at loading time */
- if (dlt_daemon_application_add(daemon, apid, 0, pb, verbose) == 0)
+ if (dlt_daemon_application_add(daemon, apid, 0, pb, -1, verbose) == 0)
{
dlt_log(LOG_WARNING, "dlt_daemon_applications_load dlt_daemon_application_add failed\n");
fclose(fd);
@@ -1162,8 +1175,10 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context,
if (errno == EPIPE)
{
+#ifndef DLT_USE_UNIX_SOCKET_IPC
/* Close connection */
close(context->user_handle);
+#endif
context->user_handle = DLT_FD_INIT;
}
}
@@ -1196,8 +1211,10 @@ int dlt_daemon_user_send_log_state(DltDaemon *daemon, DltDaemonApplication *app,
{
if (errno==EPIPE)
{
+#ifndef DLT_USE_UNIX_SOCKET_IPC
/* Close connection */
close(app->user_handle);
+#endif
app->user_handle=DLT_FD_INIT;
}
}
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index d79febb..5df66ed 100644
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -196,10 +196,11 @@ int dlt_daemon_free(DltDaemon *daemon,int verbose);
* @param apid pointer to application id
* @param pid process id of user application
* @param description description of application
+ * @param fd file descriptor of application
* @param verbose if set to true verbose information is printed out.
* @return Pointer to added context, null pointer on error
*/
-DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pid_t pid,char *description, int verbose);
+DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid, pid_t pid, char *description, int fd, int verbose);
/**
* Delete application from internal application management
* @param daemon pointer to dlt daemon structure
diff --git a/src/daemon/dlt_daemon_common_cfg.h b/src/daemon/dlt_daemon_common_cfg.h
index 5df87fa..468ed41 100644
--- a/src/daemon/dlt_daemon_common_cfg.h
+++ b/src/daemon/dlt_daemon_common_cfg.h
@@ -88,6 +88,11 @@
#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \
"/dlt-ctrl.sock"
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+#define DLT_DAEMON_DEFAULT_APP_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \
+ "/dlt-app.sock"
+#endif
+
/* Size of text buffer */
#define DLT_DAEMON_COMMON_TEXTBUFSIZE 255
diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c
index 58b8a72..8a3913a 100644
--- a/src/daemon/dlt_daemon_connection.c
+++ b/src/daemon/dlt_daemon_connection.c
@@ -216,6 +216,10 @@ STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local,
dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZESERIAL);
}
break;
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ case DLT_CONNECTION_APP_CONNECT:
+ /* FALL THROUGH */
+#endif
case DLT_CONNECTION_APP_MSG:
/* FALL THROUGH */
case DLT_CONNECTION_ONE_S_TIMER:
@@ -275,6 +279,11 @@ void *dlt_connection_get_callback(DltConnection *con)
case DLT_CONNECTION_CLIENT_MSG_SERIAL:
ret = dlt_daemon_process_client_messages_serial;
break;
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ case DLT_CONNECTION_APP_CONNECT:
+ ret = dlt_daemon_process_app_connect;
+ break;
+#endif
case DLT_CONNECTION_APP_MSG:
ret = dlt_daemon_process_user_messages;
break;
diff --git a/src/daemon/dlt_daemon_connection_types.h b/src/daemon/dlt_daemon_connection_types.h
index 1887acc..bd89998 100644
--- a/src/daemon/dlt_daemon_connection_types.h
+++ b/src/daemon/dlt_daemon_connection_types.h
@@ -43,6 +43,7 @@ typedef enum {
DLT_CONNECTION_CLIENT_CONNECT = 0,
DLT_CONNECTION_CLIENT_MSG_TCP,
DLT_CONNECTION_CLIENT_MSG_SERIAL,
+ DLT_CONNECTION_APP_CONNECT,
DLT_CONNECTION_APP_MSG,
DLT_CONNECTION_ONE_S_TIMER,
DLT_CONNECTION_SIXTY_S_TIMER,
@@ -58,6 +59,7 @@ typedef enum {
#define DLT_CON_MASK_CLIENT_MSG_TCP (1 << DLT_CONNECTION_CLIENT_MSG_TCP)
#define DLT_CON_MASK_CLIENT_MSG_SERIAL (1 << DLT_CONNECTION_CLIENT_MSG_SERIAL)
#define DLT_CON_MASK_APP_MSG (1 << DLT_CONNECTION_APP_MSG)
+#define DLT_CON_MASK_APP_CONNECT (1 << DLT_CONNECTION_APP_CONNECT)
#define DLT_CON_MASK_ONE_S_TIMER (1 << DLT_CONNECTION_ONE_S_TIMER)
#define DLT_CON_MASK_SIXTY_S_TIMER (1 << DLT_CONNECTION_SIXTY_S_TIMER)
#define DLT_CON_MASK_SYSTEMD_TIMER (1 << DLT_CONNECTION_SYSTEMD_TIMER)
diff --git a/src/daemon/dlt_daemon_unix_socket.c b/src/daemon/dlt_daemon_unix_socket.c
index 05af5cb..0ed92ad 100644
--- a/src/daemon/dlt_daemon_unix_socket.c
+++ b/src/daemon/dlt_daemon_unix_socket.c
@@ -30,6 +30,8 @@
#include <stdlib.h>
#include <sys/un.h>
#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <syslog.h>
#include <errno.h>
#include "dlt-daemon.h"
@@ -40,9 +42,10 @@
char err_string[DLT_DAEMON_TEXTBUFSIZE];
-int dlt_daemon_unix_socket_open(int *sock, char *sock_path)
+int dlt_daemon_unix_socket_open(int *sock, char *sock_path, int type, int mask)
{
struct sockaddr_un addr;
+ int old_mask;
if (sock == NULL || sock_path == NULL)
{
@@ -50,7 +53,7 @@ int dlt_daemon_unix_socket_open(int *sock, char *sock_path)
return -1;
}
- if ((*sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ if ((*sock = socket(AF_UNIX, type, 0)) == -1)
{
dlt_log(LOG_WARNING, "unix socket: socket() error");
return -1;
@@ -62,6 +65,9 @@ int dlt_daemon_unix_socket_open(int *sock, char *sock_path)
unlink(sock_path);
+ /* set appropriate access permissions */
+ old_mask = umask(mask);
+
if (bind(*sock, (struct sockaddr *) &addr, sizeof(addr)) == -1)
{
dlt_log(LOG_WARNING, "unix socket: bind() error");
@@ -74,6 +80,9 @@ int dlt_daemon_unix_socket_open(int *sock, char *sock_path)
return -1;
}
+ /* restore permissions */
+ umask(old_mask);
+
return 0;
}
@@ -89,21 +98,3 @@ int dlt_daemon_unix_socket_close(int sock)
return ret;
}
-
-int dlt_daemon_unix_socket_send(
- int sock,
- void *data1,
- int size1,
- void *data2,
- int size2,
- char serialheader)
-{
- /* re-use socket send function */
- return dlt_daemon_socket_send(
- sock,
- data1,
- size1,
- data2,
- size2,
- serialheader);
-}
diff --git a/src/daemon/dlt_daemon_unix_socket.h b/src/daemon/dlt_daemon_unix_socket.h
index ec12eba..dec6b86 100644
--- a/src/daemon/dlt_daemon_unix_socket.h
+++ b/src/daemon/dlt_daemon_unix_socket.h
@@ -58,10 +58,7 @@
#ifndef DLT_DAEMON_UNIX_SOCKET_H
#define DLT_DAEMON_UNIX_SOCKET_H
-int dlt_daemon_unix_socket_open(int *sock, char *socket_path);
+int dlt_daemon_unix_socket_open(int *sock, char *socket_path, int type, int mask);
int dlt_daemon_unix_socket_close(int sock);
-int dlt_daemon_unix_socket_send(int sock,void* data1,int size1,void* data2,
- int size2,char serialheader);
-
#endif /* DLT_DAEMON_UNIX_SOCKET_H */
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 8d1aec1..70fb564 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -55,7 +55,10 @@
#include <unistd.h>
#include <stdbool.h>
-
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+#include <sys/un.h>
+#include <sys/socket.h>
+#endif
#include "dlt_user.h"
#include "dlt_common.h"
@@ -79,8 +82,10 @@ static DltUser dlt_user;
static bool dlt_user_initialised = false;
static int dlt_user_freeing = 0;
+#ifndef DLT_USE_UNIX_SOCKET_IPC
static char dlt_user_dir[NAME_MAX + 1];
static char dlt_daemon_fifo[NAME_MAX + 1];
+#endif
static char str[DLT_USER_BUFFER_LENGTH];
@@ -185,50 +190,79 @@ DltReturnValue dlt_user_check_library_version(const char *user_major_version,con
return DLT_RETURN_OK;
}
-DltReturnValue dlt_init(void)
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+static DltReturnValue dlt_initialize_socket_connection(void)
{
- char filename[DLT_USER_MAX_FILENAME_LENGTH];
- int ret;
+ struct sockaddr_un remote;
+ int status = 0;
+ char dltSockBaseDir[DLT_IPC_PATH_MAX];
- // process is exiting. Do not allocate new resources.
- if (dlt_user_freeing != 0)
+ DLT_SEM_LOCK();
+ int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+
+ if (sockfd == DLT_FD_INIT)
{
- // return negative value, to stop the current log
+ dlt_log(LOG_CRIT, "Failed to create socket\n");
+ DLT_SEM_FREE();
return DLT_RETURN_ERROR;
}
- // WARNING: multithread unsafe !
- // Another thread will check that dlt_user_initialised != 0, but the lib is not initialised !
- dlt_user_initialised = true;
-
- /* Initialize common part of dlt_init()/dlt_init_file() */
- if (dlt_init_common() == DLT_RETURN_ERROR)
+ status = fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0) | O_NONBLOCK);
+ if (status == -1)
{
- dlt_user_initialised = false;
+ dlt_vlog(LOG_INFO,
+ "Socket %s/dlt cannot be changed to NON BLOCK\n",
+ DLT_USER_IPC_PATH);
return DLT_RETURN_ERROR;
}
- /* check environment variables */
- dlt_check_envvar();
-
- snprintf(dlt_user_dir, NAME_MAX, "%s/dltpipes", dltFifoBaseDir);
- snprintf(dlt_daemon_fifo, NAME_MAX, "%s/dlt", dltFifoBaseDir);
+ remote.sun_family = AF_UNIX;
+ snprintf(dltSockBaseDir, DLT_IPC_PATH_MAX, "%s/dlt", DLT_USER_IPC_PATH);
+ strncpy(remote.sun_path, dltSockBaseDir, sizeof(dltSockBaseDir));
- dlt_user.dlt_is_file = 0;
- dlt_user.overflow = 0;
- dlt_user.overflow_counter = 0;
-#ifdef DLT_SHM_ENABLE
- memset(&(dlt_user.dlt_shm),0,sizeof(DltShm));
-#endif
+ if (strlen(DLT_USER_IPC_PATH) > DLT_IPC_PATH_MAX)
+ {
+ dlt_vlog(LOG_INFO,
+ "Provided path too long...trimming it to path[%s]\n",
+ dltSockBaseDir);
+ }
- /* create dlt pipes directory */
- /* Make sure the parent user directory is created */
- if (dlt_mkdir_recursive(dltFifoBaseDir) != 0)
+ if (connect(sockfd, (struct sockaddr*) &remote, sizeof(remote)) == -1)
+ {
+ if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT)
+ {
+ dlt_vlog(LOG_INFO,
+ "Socket %s cannot be opened. Retrying later...\n",
+ dltSockBaseDir);
+ dlt_user.connection_state = DLT_USER_RETRY_CONNECT;
+ }
+ }
+ else
{
- dlt_vnlog(LOG_ERR,DLT_USER_BUFFER_LENGTH, "Base dir %s cannot be created!\n", dltFifoBaseDir);
- return DLT_RETURN_ERROR;
+ dlt_user.dlt_log_handle = sockfd;
+ dlt_user.connection_state = DLT_USER_CONNECTED;
+
+ if (dlt_receiver_init(&(dlt_user.receiver),
+ sockfd,
+ DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR)
+ {
+ dlt_user_initialised = false;
+ DLT_SEM_FREE();
+ return DLT_RETURN_ERROR;
+ }
}
+ DLT_SEM_FREE();
+
+ return DLT_RETURN_OK;
+}
+#else /* setup fifo*/
+static DltReturnValue dlt_initialize_fifo_connection(void)
+{
+ char filename[DLT_USER_MAX_FILENAME_LENGTH];
+ int ret;
+ snprintf(dlt_user_dir, NAME_MAX, "%s/dltpipes", dltFifoBaseDir);
+ snprintf(dlt_daemon_fifo, NAME_MAX, "%s/dlt", dltFifoBaseDir);
ret=mkdir(dlt_user_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX );
if (ret==-1 && errno != EEXIST)
{
@@ -250,7 +284,7 @@ DltReturnValue dlt_init(void)
/* create and open DLT user FIFO */
snprintf(filename,DLT_USER_MAX_FILENAME_LENGTH,"%s/dlt%d",dlt_user_dir,getpid());
-
+
/* Try to delete existing pipe, ignore result of unlink */
unlink(filename);
@@ -281,33 +315,77 @@ DltReturnValue dlt_init(void)
dlt_user.dlt_log_handle = open(dlt_daemon_fifo, O_WRONLY | O_NONBLOCK | O_CLOEXEC );
if (dlt_user.dlt_log_handle==-1)
{
- /* This is a normal usecase. It is OK that the daemon (and thus the FIFO /tmp/dlt)
- starts later and some DLT users have already been started before.
- Thus it is OK if the FIFO can't be opened. */
- dlt_vnlog(LOG_INFO, DLT_USER_BUFFER_LENGTH, "FIFO %s cannot be opened. Retrying later...\n",dlt_daemon_fifo);
- //return DLT_RETURN_OK;
- }
- else
- {
-#ifdef DLT_SHM_ENABLE
- /* init shared memory */
- if (dlt_shm_init_client(&(dlt_user.dlt_shm),DLT_SHM_KEY) < 0)
+
+ if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT)
{
/* This is a normal usecase. It is OK that the daemon (and thus the FIFO /tmp/dlt)
starts later and some DLT users have already been started before.
Thus it is OK if the FIFO can't be opened. */
- dlt_vnlog(LOG_INFO, DLT_USER_BUFFER_LENGTH, "Shared memory %d cannot be created. Retrying later...\n", DLT_SHM_KEY);
- //return DLT_RETURN_OK;
+ dlt_vnlog(LOG_INFO, DLT_USER_BUFFER_LENGTH, "FIFO %s cannot be opened. Retrying later...\n",dlt_daemon_fifo);
+ dlt_user.connection_state = DLT_USER_RETRY_CONNECT;
}
+ //return DLT_RETURN_OK;
+ }
+
+ return DLT_RETURN_OK;
+}
#endif
+
+DltReturnValue dlt_init(void)
+{
+ // process is exiting. Do not allocate new resources.
+ if (dlt_user_freeing != 0)
+ {
+ // return negative value, to stop the current log
+ return DLT_RETURN_ERROR;
}
+ // WARNING: multithread unsafe !
+ // Another thread will check that dlt_user_initialised != 0, but the lib is not initialised !
+ dlt_user_initialised = true;
+
+ /* Initialize common part of dlt_init()/dlt_init_file() */
+ if (dlt_init_common() == DLT_RETURN_ERROR)
+ {
+ dlt_user_initialised = false;
+ return DLT_RETURN_ERROR;
+ }
+ strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, sizeof(DLT_USER_IPC_PATH));
+ /* check environment variables */
+ dlt_check_envvar();
+ dlt_user.dlt_is_file = 0;
+ dlt_user.overflow = 0;
+ dlt_user.overflow_counter = 0;
+#ifdef DLT_SHM_ENABLE
+ memset(&(dlt_user.dlt_shm),0,sizeof(DltShm));
+ /* init shared memory */
+ if (dlt_shm_init_client(&(dlt_user.dlt_shm),DLT_SHM_KEY) < 0)
+ {
+ snprintf(str,DLT_USER_BUFFER_LENGTH,"Logging disabled, Shared memory %d cannot be created!\n",DLT_SHM_KEY);
+ dlt_log(LOG_WARNING, str);
+ //return 0;
+ }
+#elif defined DLT_USE_UNIX_SOCKET_IPC
+ if (dlt_initialize_socket_connection() != DLT_RETURN_OK)
+ {
+ // We could connect to the pipe, but not to the socket, which is normally
+ // open before by the DLT daemon => bad failure => return error code
+ // in case application is started before daemon, it is expected behaviour
+ return DLT_RETURN_ERROR;
+ }
+#else /* FIFO connection */
+ if (dlt_initialize_fifo_connection() != DLT_RETURN_OK)
+ {
+ return DLT_RETURN_ERROR;
+ }
+ dlt_user.connection_state = DLT_USER_CONNECTED;
if (dlt_receiver_init(&(dlt_user.receiver),dlt_user.dlt_user_handle, DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR)
{
dlt_user_initialised = false;
return DLT_RETURN_ERROR;
}
+#endif
/* These will be lazy initialized only when needed */
dlt_user.dlt_segmented_queue_read_handle = -1;
@@ -676,7 +754,9 @@ int dlt_user_atexit_blow_out_user_buffer(void){
DltReturnValue dlt_free(void)
{
uint32_t i;
+#ifndef DLT_USE_UNIX_SOCKET_IPC
char filename[DLT_USER_MAX_FILENAME_LENGTH];
+#endif
if( dlt_user_freeing != 0 )
// resources are already being freed. Do nothing and return.
@@ -694,15 +774,15 @@ DltReturnValue dlt_free(void)
dlt_stop_threads();
+#ifndef DLT_USE_UNIX_SOCKET_IPC
if (dlt_user.dlt_user_handle!=DLT_FD_INIT)
{
- snprintf(filename,DLT_USER_MAX_FILENAME_LENGTH,"%s/dlt%d",dlt_user_dir,getpid());
-
close(dlt_user.dlt_user_handle);
dlt_user.dlt_user_handle=DLT_FD_INIT;
-
+ snprintf(filename,DLT_USER_MAX_FILENAME_LENGTH,"%s/dlt%d",dlt_user_dir,getpid());
unlink(filename);
}
+#endif
#ifdef DLT_SHM_ENABLE
/* free shared memory */
@@ -1347,7 +1427,6 @@ DltReturnValue dlt_forward_msg(void *msgdata,size_t size)
}
}
- /* log to FIFO */
ret = dlt_user_log_out3(dlt_user.dlt_log_handle,
&(userheader), sizeof(DltUserHeader),
msgdata, size, 0, 0);
@@ -3599,13 +3678,11 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype)
dlt_shm_push(&dlt_user.dlt_shm,msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader),
log->buffer, log->size, 0, 0);
- /* log to FIFO */
ret = dlt_user_log_out3(dlt_user.dlt_log_handle,
&(userheader), sizeof(DltUserHeader),
0, 0,
0, 0);
#else
- /* log to FIFO */
#ifdef DLT_TEST_ENABLE
if(dlt_user.corrupt_user_header) {
userheader.pattern[0]=0xff;
@@ -3669,6 +3746,7 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype)
/* handle not open or pipe error */
close(dlt_user.dlt_log_handle);
dlt_user.dlt_log_handle = -1;
+ dlt_user.connection_state = DLT_USER_RETRY_CONNECT;
#ifdef DLT_SHM_ENABLE
/* free shared memory */
@@ -3738,7 +3816,6 @@ DltReturnValue dlt_user_log_send_register_application(void)
return DLT_RETURN_OK;
}
- /* log to FIFO */
ret = dlt_user_log_out3(dlt_user.dlt_log_handle,
&(userheader), sizeof(DltUserHeader),
&(usercontext), sizeof(DltUserControlMsgRegisterApplication),
@@ -3795,10 +3872,10 @@ DltReturnValue dlt_user_log_send_unregister_application(void)
return DLT_RETURN_OK;
}
- /* log to FIFO */
return dlt_user_log_out2(dlt_user.dlt_log_handle,
- &(userheader), sizeof(DltUserHeader),
- &(usercontext), sizeof(DltUserControlMsgUnregisterApplication));
+ &(userheader), sizeof(DltUserHeader),
+ &(usercontext), sizeof(DltUserControlMsgUnregisterApplication));
+
}
DltReturnValue dlt_user_log_send_register_context(DltContextData *log)
@@ -3851,7 +3928,6 @@ DltReturnValue dlt_user_log_send_register_context(DltContextData *log)
return DLT_RETURN_OK;
}
- /* log to FIFO */
if (dlt_user.appID[0]!='\0')
{
ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterContext),log->context_description,usercontext.description_length);
@@ -3921,10 +3997,11 @@ DltReturnValue dlt_user_log_send_unregister_context(DltContextData *log)
return DLT_RETURN_OK;
}
- /* log to FIFO */
return dlt_user_log_out2(dlt_user.dlt_log_handle,
- &(userheader), sizeof(DltUserHeader),
- &(usercontext), sizeof(DltUserControlMsgUnregisterContext));
+ &(userheader),
+ sizeof(DltUserHeader),
+ &(usercontext),
+ sizeof(DltUserControlMsgUnregisterContext));
}
DltReturnValue dlt_send_app_ll_ts_limit(const char *appid, DltLogLevelType loglevel, DltTraceStatusType tracestatus)
@@ -3979,10 +4056,10 @@ DltReturnValue dlt_send_app_ll_ts_limit(const char *appid, DltLogLevelType logle
return DLT_RETURN_OK;
}
- /* log to FIFO */
return dlt_user_log_out2(dlt_user.dlt_log_handle,
- &(userheader), sizeof(DltUserHeader),
- &(usercontext), sizeof(DltUserControlMsgAppLogLevelTraceStatus));
+ &(userheader), sizeof(DltUserHeader),
+ &(usercontext), sizeof(DltUserControlMsgAppLogLevelTraceStatus));
+
}
DltReturnValue dlt_user_log_send_log_mode(DltUserLogMode mode)
@@ -4010,7 +4087,6 @@ DltReturnValue dlt_user_log_send_log_mode(DltUserLogMode mode)
return DLT_RETURN_OK;
}
- /* log to FIFO */
return dlt_user_log_out2(dlt_user.dlt_log_handle,
&(userheader), sizeof(DltUserHeader),
&(logmode), sizeof(DltUserControlMsgLogMode));
@@ -4083,6 +4159,7 @@ DltReturnValue dlt_user_log_check_user_message(void)
int leave_while=0;
uint32_t i;
+ int fd;
DltUserHeader *userheader;
DltReceiver *receiver = &(dlt_user.receiver);
@@ -4103,7 +4180,13 @@ DltReturnValue dlt_user_log_check_user_message(void)
delayed_injection_callback.service_id = 0;
delayed_log_level_changed_callback.log_level_changed_callback = 0;
- if (dlt_user.dlt_user_handle!=DLT_FD_INIT)
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ fd = dlt_user.dlt_log_handle;
+#else
+ fd = dlt_user.dlt_user_handle;
+#endif
+
+ if (fd != DLT_FD_INIT)
{
while (1)
{
@@ -4377,10 +4460,8 @@ DltReturnValue dlt_user_log_resend_buffer(void)
#ifdef DLT_SHM_ENABLE
dlt_shm_push(&dlt_user.dlt_shm, dlt_user.resend_buffer+sizeof(DltUserHeader), size-sizeof(DltUserHeader), 0, 0, 0, 0);
- /* log to FIFO */
ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer,sizeof(DltUserHeader), 0, 0, 0, 0);
#else
- /* log to FIFO */
ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer,size, 0, 0, 0, 0);
#endif
@@ -4413,72 +4494,87 @@ void dlt_user_log_reattach_to_daemon(void)
{
dlt_user.dlt_log_handle=-1;
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ /* try to open connection to dlt daemon */
+ dlt_initialize_socket_connection();
+ if (dlt_user.connection_state != DLT_USER_CONNECTED)
+ {
+ /* return if not connected */
+ return;
+ }
+
+#else
/* try to open pipe to dlt daemon */
- dlt_user.dlt_log_handle = open(dlt_daemon_fifo, O_WRONLY | O_NONBLOCK);
- if (dlt_user.dlt_log_handle > 0)
+ int fd = open(dlt_daemon_fifo, O_WRONLY | O_NONBLOCK);
+
+ if (fd < 0)
{
- if (dlt_user_log_init(&handle,&log_new) < DLT_RETURN_OK)
- {
- return;
- }
+ return;
+ }
+
+ dlt_user.dlt_log_handle = fd;
+#endif
+ if (dlt_user_log_init(&handle,&log_new) < DLT_RETURN_OK)
+ {
+ return;
+ }
#ifdef DLT_SHM_ENABLE
- /* init shared memory */
- if (dlt_shm_init_client(&dlt_user.dlt_shm,DLT_SHM_KEY) < 0)
- {
- dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "Loging disabled, Shared memory %d cannot be created!\n", DLT_SHM_KEY);
- //return DLT_RETURN_OK;
- }
+ /* init shared memory */
+ if (dlt_shm_init_client(&dlt_user.dlt_shm,DLT_SHM_KEY) < 0)
+ {
+ dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "Loging disabled, Shared memory %d cannot be created!\n", DLT_SHM_KEY);
+ //return DLT_RETURN_OK;
+ }
#endif
- dlt_log(LOG_NOTICE, "Logging (re-)enabled!\n");
+ dlt_log(LOG_NOTICE, "Logging (re-)enabled!\n");
- /* Re-register application */
- if (dlt_user_log_send_register_application() < DLT_RETURN_ERROR)
- {
- return;
- }
+ /* Re-register application */
+ if (dlt_user_log_send_register_application() < DLT_RETURN_ERROR)
+ {
+ return;
+ }
- DLT_SEM_LOCK();
+ DLT_SEM_LOCK();
- /* Re-register all stored contexts */
- for (num=0; num<dlt_user.dlt_ll_ts_num_entries; num++)
+ /* Re-register all stored contexts */
+ for (num=0; num<dlt_user.dlt_ll_ts_num_entries; num++)
+ {
+ /* Re-register stored context */
+ if ((dlt_user.appID[0]!='\0') && (dlt_user.dlt_ll_ts) && (dlt_user.dlt_ll_ts[num].contextID[0]!='\0'))
{
- /* Re-register stored context */
- if ((dlt_user.appID[0]!='\0') && (dlt_user.dlt_ll_ts) && (dlt_user.dlt_ll_ts[num].contextID[0]!='\0'))
- {
- //dlt_set_id(log_new.appID, dlt_user.appID);
- dlt_set_id(handle.contextID, dlt_user.dlt_ll_ts[num].contextID);
- handle.log_level_pos = num;
- log_new.context_description = dlt_user.dlt_ll_ts[num].context_description;
+ //dlt_set_id(log_new.appID, dlt_user.appID);
+ dlt_set_id(handle.contextID, dlt_user.dlt_ll_ts[num].contextID);
+ handle.log_level_pos = num;
+ log_new.context_description = dlt_user.dlt_ll_ts[num].context_description;
- // Release the mutex for sending context registration:
- // function dlt_user_log_send_register_context() can take the mutex to write to the DLT buffer. => dead lock
- DLT_SEM_FREE();
+ // Release the mutex for sending context registration:
+ // function dlt_user_log_send_register_context() can take the mutex to write to the DLT buffer. => dead lock
+ DLT_SEM_FREE();
- log_new.log_level = DLT_USER_LOG_LEVEL_NOT_SET;
- log_new.trace_status = DLT_USER_TRACE_STATUS_NOT_SET;
+ log_new.log_level = DLT_USER_LOG_LEVEL_NOT_SET;
+ log_new.trace_status = DLT_USER_TRACE_STATUS_NOT_SET;
- if (dlt_user_log_send_register_context(&log_new) < DLT_RETURN_ERROR)
- {
- return;
- }
+ if (dlt_user_log_send_register_context(&log_new) < DLT_RETURN_ERROR)
+ {
+ return;
+ }
- reregistered=1;
+ reregistered=1;
- // Lock again the mutex
- // it is necessary in the for(;;) test, in order to have coherent dlt_user data all over the critical section.
- DLT_SEM_LOCK();
+ // Lock again the mutex
+ // it is necessary in the for(;;) test, in order to have coherent dlt_user data all over the critical section.
+ DLT_SEM_LOCK();
- }
}
+ }
- DLT_SEM_FREE();
+ DLT_SEM_FREE();
- if (reregistered==1)
- {
- dlt_user_log_resend_buffer();
- }
+ if (reregistered==1)
+ {
+ dlt_user_log_resend_buffer();
}
}
}
@@ -4503,7 +4599,6 @@ DltReturnValue dlt_user_log_send_overflow(void)
userpayload.overflow_counter = dlt_user.overflow_counter;
dlt_set_id(userpayload.apid,dlt_user.appID);
- /* log to FIFO */
return dlt_user_log_out2(dlt_user.dlt_log_handle,
&(userheader), sizeof(DltUserHeader),
&(userpayload), sizeof(DltUserControlMsgBufferOverflow));
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index 818f3ef..17d0add 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -2229,6 +2229,15 @@ int dlt_receiver_receive_fd(DltReceiver *receiver)
return receiver->bytesRcvd;
}
+int dlt_receiver_receive(DltReceiver *receiver)
+{
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ return dlt_receiver_receive_socket(receiver);
+#else
+ return dlt_receiver_receive_fd(receiver);
+#endif
+}
+
DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size)
{
if (receiver == NULL)
@@ -3902,6 +3911,7 @@ void dlt_check_envvar()
}
}
+#ifndef DLT_USE_UNIX_SOCKET_IPC
int dlt_mkdir_recursive(const char *dir)
{
int ret = 0;
@@ -3940,3 +3950,4 @@ int dlt_mkdir_recursive(const char *dir)
return ret;
}
+#endif