summaryrefslogtreecommitdiff
path: root/src/daemon
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/daemon
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/daemon')
-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
10 files changed, 272 insertions, 82 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 */