summaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/dlt-daemon.c159
-rw-r--r--src/daemon/dlt-daemon.h6
-rw-r--r--src/daemon/dlt_daemon_common.c118
-rw-r--r--src/daemon/dlt_daemon_common.h1
-rw-r--r--src/daemon/dlt_daemon_common_cfg.h2
-rw-r--r--src/daemon/dlt_daemon_connection.c32
6 files changed, 213 insertions, 105 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index cd6e5d9..d4a5e90 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -50,6 +50,15 @@
# include <linux/stat.h>
#endif
+#ifdef DLT_DAEMON_VSOCK_IPC_ENABLE
+# ifdef linux
+# include <linux/vm_sockets.h>
+# endif
+# ifdef __QNX__
+# include <vm_sockets.h>
+# endif
+#endif
+
#include "dlt_types.h"
#include "dlt-daemon.h"
#include "dlt-daemon_cfg.h"
@@ -106,7 +115,7 @@ void usage()
printf(" -h Usage\n");
printf(" -c filename DLT daemon configuration file (Default: " CONFIGURATION_FILES_DIR "/dlt.conf)\n");
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
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");
@@ -143,7 +152,7 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
/* default values */
daemon_local->flags.port = DLT_DAEMON_TCP_PORT;
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
dlt_log_set_fifo_basedir(DLT_USER_IPC_PATH);
#endif
@@ -171,7 +180,7 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
strncpy(daemon_local->flags.cvalue, optarg, NAME_MAX);
break;
}
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
case 't':
{
dlt_log_set_fifo_basedir(optarg);
@@ -224,7 +233,7 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
/* switch() */
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX,
"%s/dltpipes", dltFifoBaseDir);
snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX,
@@ -263,11 +272,11 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.loggingMode = DLT_LOG_TO_CONSOLE;
daemon_local->flags.loggingLevel = LOG_INFO;
-#ifdef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC
n = snprintf(daemon_local->flags.loggingFilename,
sizeof(daemon_local->flags.loggingFilename),
"%s/dlt.log", DLT_USER_IPC_PATH);
-#else
+#else /* DLT_DAEMON_USE_FIFO_IPC */
n = snprintf(daemon_local->flags.loggingFilename,
sizeof(daemon_local->flags.loggingFilename),
"%s/dlt.log", dltFifoBaseDir);
@@ -298,14 +307,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
+#ifdef DLT_DAEMON_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);
-#else
+#else /* DLT_DAEMON_USE_FIFO_IPC */
memset(daemon_local->flags.daemonFifoGroup, 0, sizeof(daemon_local->flags.daemonFifoGroup));
#endif
daemon_local->flags.gatewayMode = 0;
@@ -626,7 +635,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
}
}
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
else if (strcmp(token, "DaemonFifoGroup") == 0)
{
strncpy(daemon_local->flags.daemonFifoGroup, value, NAME_MAX);
@@ -728,7 +737,43 @@ int option_file_parser(DltDaemonLocal *daemon_local)
return 0;
}
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
+static 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;
+}
+#endif
+
+#ifdef DLT_DAEMON_USE_FIFO_IPC
static DltReturnValue dlt_daemon_create_pipes_dir(char *dir)
{
int ret = DLT_RETURN_OK;
@@ -811,7 +856,7 @@ int main(int argc, char *argv[])
PRINT_FUNCTION_VERBOSE(daemon_local.flags.vflag);
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
/* Make sure the parent user directory is created */
if (dlt_mkdir_recursive(dltFifoBaseDir) != 0) {
@@ -979,7 +1024,7 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
#endif
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
if (dlt_daemon_create_pipes_dir(daemon_local->flags.userPipesDir) == DLT_RETURN_ERROR)
return DLT_RETURN_ERROR;
@@ -1174,7 +1219,7 @@ static int dlt_daemon_init_serial(DltDaemonLocal *daemon_local)
DLT_CONNECTION_CLIENT_MSG_SERIAL);
}
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local)
{
int ret;
@@ -1254,6 +1299,43 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local)
}
#endif
+#ifdef DLT_DAEMON_VSOCK_IPC_ENABLE
+static int dlt_daemon_init_vsock(DltDaemonLocal *daemon_local)
+{
+ int fd;
+ struct sockaddr_vm addr;
+
+ fd = socket(AF_VSOCK, SOCK_STREAM, 0);
+ if (fd == -1) {
+ dlt_vlog(LOG_ERR, "Failed to create VSOCK socket: %s\n", strerror(errno));
+ return -1;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.svm_family = AF_VSOCK;
+ addr.svm_port = DLT_VSOCK_PORT;
+ addr.svm_cid = VMADDR_CID_ANY;
+
+ if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) != 0) {
+ dlt_vlog(LOG_ERR, "Failed to bind VSOCK socket: %s\n", strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ if (listen(fd, 1) != 0) {
+ dlt_vlog(LOG_ERR, "Failed to listen on VSOCK socket: %s\n", strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ return dlt_connection_create(daemon_local,
+ &daemon_local->pEvent,
+ fd,
+ POLLIN,
+ DLT_CONNECTION_APP_CONNECT);
+}
+#endif
+
int dlt_daemon_local_connection_init(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
int verbose)
@@ -1269,7 +1351,7 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon,
return -1;
}
-#ifdef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_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;
@@ -1292,7 +1374,7 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon,
return DLT_RETURN_ERROR;
}
-#else
+#else /* DLT_DAEMON_USE_FIFO_IPC */
if (dlt_daemon_init_fifo(daemon_local)) {
dlt_log(LOG_ERR, "Unable to initialize fifo.\n");
@@ -1301,6 +1383,13 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon,
#endif
+#ifdef DLT_DAEMON_VSOCK_IPC_ENABLE
+ if (dlt_daemon_init_vsock(daemon_local) != 0) {
+ dlt_log(LOG_ERR, "Unable to initialize app VSOCK socket.\n");
+ return DLT_RETURN_ERROR;
+ }
+#endif
+
/* create and open socket to receive incoming connections from client */
daemon_local->client_connections = 0;
@@ -1484,10 +1573,10 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i
/* Ignore result */
dlt_file_free(&(daemon_local->file), daemon_local->flags.vflag);
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
/* Try to delete existing pipe, ignore result of unlink() */
unlink(daemon_local->flags.daemonFifoName);
-#else
+#else /* DLT_DAEMON_USE_UNIX_SOCKET_IPC */
/* Try to delete existing pipe, ignore result of unlink() */
unlink(daemon_local->flags.appSockPath);
#endif
@@ -1520,7 +1609,7 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i
void dlt_daemon_exit_trigger()
{
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
char tmp[DLT_PATH_MAX] = { 0 };
ssize_t n;
@@ -1832,7 +1921,7 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon,
return -1;
}
- must_close_socket = dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET);
+ must_close_socket = dlt_receiver_receive(receiver);
if (must_close_socket < 0) {
dlt_daemon_close_socket(receiver->fd,
@@ -1908,7 +1997,7 @@ int dlt_daemon_process_client_messages_serial(DltDaemon *daemon,
return -1;
}
- if (dlt_receiver_receive(receiver, DLT_RECEIVE_FD) <= 0) {
+ if (dlt_receiver_receive(receiver) <= 0) {
dlt_log(LOG_WARNING,
"dlt_receiver_receive_fd() for messages from serial interface "
"failed!\n");
@@ -2010,15 +2099,13 @@ int dlt_daemon_process_control_connect(
return 0;
}
-#ifdef DLT_USE_UNIX_SOCKET_IPC
+#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE
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);
@@ -2030,10 +2117,9 @@ int dlt_daemon_process_app_connect(
return DLT_RETURN_WRONG_PARAMETER;
}
- /* event from UNIX server socket, new connection */
- app_size = sizeof(app);
+ /* event from server socket, new connection */
- if ((in_sock = accept(receiver->fd, (struct sockaddr *)&app, &app_size)) < 0) {
+ if ((in_sock = accept(receiver->fd, NULL, NULL)) < 0) {
dlt_vlog(LOG_ERR, "accept() on UNIX socket %d failed: %s\n", receiver->fd, strerror(errno));
return -1;
}
@@ -2077,7 +2163,7 @@ int dlt_daemon_process_control_messages(
return -1;
}
- if (dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET) <= 0) {
+ if (dlt_receiver_receive(receiver) <= 0) {
dlt_daemon_close_socket(receiver->fd,
daemon,
daemon_local,
@@ -2189,28 +2275,21 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon,
return -1;
}
-#ifdef DLT_USE_UNIX_SOCKET_IPC
- recv = dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET);
+ recv = dlt_receiver_receive(receiver);
- if (recv <= 0) {
+ if (recv <= 0 && receiver->type == DLT_RECEIVE_SOCKET) {
dlt_daemon_close_socket(receiver->fd,
daemon,
daemon_local,
verbose);
return 0;
}
-
-#else
- recv = dlt_receiver_receive(receiver, DLT_RECEIVE_FD);
-
- if (recv < 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) {
dlt_daemon_process_user_message_func func = NULL;
@@ -2327,6 +2406,7 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon,
char description[DLT_DAEMON_DESCSIZE + 1] = { '\0' };
DltUserControlMsgRegisterApplication userapp;
char *origin;
+ int fd = -1;
PRINT_FUNCTION_VERBOSE(verbose);
@@ -2386,11 +2466,14 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon,
if (old_application != NULL)
old_pid = old_application->pid;
+ if (rec->type == DLT_RECEIVE_SOCKET)
+ fd = rec->fd; /* For sockets, an app specific fd has already been created with accept(). */
+
application = dlt_daemon_application_add(daemon,
userapp.apid,
userapp.pid,
description,
- rec->fd,
+ fd,
daemon->ecuid,
verbose);
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index 31598bb..4095cf3 100644
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -117,9 +117,9 @@ 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
+#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC
char appSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to User socket */
-#else
+#else /* DLT_DAEMON_USE_FIFO_IPC */
char userPipesDir[DLT_PATH_MAX]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */
char daemonFifoName[DLT_PATH_MAX]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */
char daemonFifoGroup[DLT_PATH_MAX]; /**< (String: Group name) Owner group of local fifo (Default: Primary Group) */
@@ -209,7 +209,7 @@ 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
+#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE
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,
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index f628cd5..4349753 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -65,6 +65,7 @@
* aw 13.01.2010 initial
*/
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -384,6 +385,33 @@ int dlt_daemon_applications_clear(DltDaemon *daemon, char *ecu, int verbose)
return 0;
}
+static void dlt_daemon_application_reset_user_handle(DltDaemon *daemon,
+ DltDaemonApplication *application,
+ int verbose)
+{
+ DltDaemonRegisteredUsers *user_list;
+ DltDaemonContext *context;
+ int i;
+
+ if (application->user_handle == DLT_FD_INIT)
+ return;
+
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list != NULL) {
+ for (i = 0; i < user_list->num_contexts; i++) {
+ context = &user_list->contexts[i];
+ if (context->user_handle == application->user_handle)
+ context->user_handle = DLT_FD_INIT;
+ }
+ }
+
+ if (application->owns_user_handle)
+ close(application->user_handle);
+
+ application->user_handle = DLT_FD_INIT;
+ application->owns_user_handle = false;
+}
+
DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
char *apid,
pid_t pid,
@@ -396,8 +424,9 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
DltDaemonApplication *old;
int new_application;
int dlt_user_handle;
+ bool owns_user_handle;
DltDaemonRegisteredUsers *user_list = NULL;
-#ifndef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_FIFO_IPC
(void)fd; /* To avoid compiler warning : unused variable */
char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE];
#endif
@@ -455,6 +484,7 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
application->application_description = NULL;
application->num_contexts = 0;
application->user_handle = DLT_FD_INIT;
+ application->owns_user_handle = false;
new_application = 1;
@@ -487,42 +517,39 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
}
}
- if (application->user_handle != DLT_FD_INIT) {
- if (application->pid != pid) {
-#ifndef DLT_USE_UNIX_SOCKET_IPC
-
- if (close(application->user_handle) < 0)
- dlt_vlog(LOG_WARNING,
- "close() failed to %s/dltpipes/dlt%d, errno=%d (%s)!\n",
- dltFifoBaseDir,
- pid,
- errno,
- strerror(errno)); /* errno 2: ENOENT - No such file or directory */
-
-#endif
- application->user_handle = DLT_FD_INIT;
- application->pid = 0;
- }
+ if (application->pid != pid) {
+ dlt_daemon_application_reset_user_handle(daemon, application, verbose);
+ application->pid = 0;
}
/* open user pipe only if it is not yet opened */
if ((application->user_handle == DLT_FD_INIT) && (pid != 0)) {
-#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) {
- int prio = (errno == ENOENT) ? LOG_INFO : LOG_WARNING;
- dlt_vlog(prio, "open() failed to %s, errno=%d (%s)!\n", filename, errno, strerror(errno));
- } /* if */
+ dlt_user_handle = DLT_FD_INIT;
+ owns_user_handle = false;
+#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE
+ if (fd >= DLT_FD_MINIMUM) {
+ dlt_user_handle = fd;
+ owns_user_handle = false;
+ }
+#endif
+#ifdef DLT_DAEMON_USE_FIFO_IPC
+ if (dlt_user_handle < DLT_FD_MINIMUM) {
+ 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) {
+ int prio = (errno == ENOENT) ? LOG_INFO : LOG_WARNING;
+ dlt_vlog(prio, "open() failed to %s, errno=%d (%s)!\n", filename, errno, strerror(errno));
+ } else {
+ owns_user_handle = true;
+ }
+ }
#endif
/* check if file descriptor was already used, and make it invalid if it
* is reused. This prevents sending messages to wrong file descriptor */
@@ -530,6 +557,7 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
dlt_daemon_contexts_invalidate_fd(daemon, ecu, dlt_user_handle, verbose);
application->user_handle = dlt_user_handle;
+ application->owns_user_handle = owns_user_handle;
application->pid = pid;
}
@@ -566,13 +594,7 @@ int dlt_daemon_application_del(DltDaemon *daemon,
return -1;
if (user_list->num_applications > 0) {
- /* 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;
- }
+ dlt_daemon_application_reset_user_handle(daemon, application, verbose);
/* Free description of application to be deleted */
if (application->application_description) {
@@ -1325,6 +1347,7 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context,
DltUserHeader userheader;
DltUserControlMsgLogLevel usercontext;
DltReturnValue ret;
+ DltDaemonApplication *app;
PRINT_FUNCTION_VERBOSE(verbose);
@@ -1370,11 +1393,9 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context,
errno != 0 ? strerror(errno) : "Unknown error");
if (errno == EPIPE) {
-#ifndef DLT_USE_UNIX_SOCKET_IPC
- /* Close connection */
- close(context->user_handle);
-#endif
- context->user_handle = DLT_FD_INIT;
+ app = dlt_daemon_application_find(daemon, context->apid, daemon->ecuid, verbose);
+ if (app != NULL)
+ dlt_daemon_application_reset_user_handle(daemon, app, verbose);
}
}
@@ -1403,13 +1424,8 @@ int dlt_daemon_user_send_log_state(DltDaemon *daemon, DltDaemonApplication *app,
&(logstate), sizeof(DltUserControlMsgLogState));
if (ret < DLT_RETURN_OK) {
- if (errno == EPIPE) {
-#ifndef DLT_USE_UNIX_SOCKET_IPC
- /* Close connection */
- close(app->user_handle);
-#endif
- app->user_handle = DLT_FD_INIT;
- }
+ if (errno == EPIPE)
+ dlt_daemon_application_reset_user_handle(daemon, app, verbose);
}
return (ret == DLT_RETURN_OK) ? DLT_RETURN_OK : DLT_RETURN_ERROR;
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index 5e1bb1b..c6a4594 100644
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -133,6 +133,7 @@ typedef struct
char apid[DLT_ID_SIZE]; /**< application id */
pid_t pid; /**< process id of user application */
int user_handle; /**< connection handle for connection to user application */
+ bool owns_user_handle; /**< user_handle should be closed when reset */
char *application_description; /**< context description */
int num_contexts; /**< number of contexts for this application */
} DltDaemonApplication;
diff --git a/src/daemon/dlt_daemon_common_cfg.h b/src/daemon/dlt_daemon_common_cfg.h
index 926befd..8fbd9b0 100644
--- a/src/daemon/dlt_daemon_common_cfg.h
+++ b/src/daemon/dlt_daemon_common_cfg.h
@@ -86,7 +86,7 @@
#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \
"/dlt-ctrl.sock"
-#ifdef DLT_USE_UNIX_SOCKET_IPC
+#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC
# define DLT_DAEMON_DEFAULT_APP_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \
"/dlt-app.sock"
#endif
diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c
index 43a202b..a438c03 100644
--- a/src/daemon/dlt_daemon_connection.c
+++ b/src/daemon/dlt_daemon_connection.c
@@ -33,6 +33,7 @@
#include <sys/socket.h>
#include <syslog.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include "dlt_daemon_connection_types.h"
@@ -162,7 +163,7 @@ DLT_STATIC void dlt_connection_destroy_receiver(DltConnection *con)
/* We rely on the gateway for clean-up */
break;
case DLT_CONNECTION_APP_MSG:
- dlt_receiver_free_unix_socket(con->receiver);
+ dlt_receiver_free_global_buffer(con->receiver);
free(con->receiver);
con->receiver = NULL;
break;
@@ -193,6 +194,8 @@ DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local
int fd)
{
DltReceiver *ret = NULL;
+ DltReceiverType receiver_type = DLT_RECEIVE_FD;
+ struct stat statbuf;
switch (type) {
case DLT_CONNECTION_CONTROL_CONNECT:
@@ -205,29 +208,34 @@ DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local
ret = calloc(1, sizeof(DltReceiver));
if (ret)
- dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZESOCK);
+ dlt_receiver_init(ret, fd, DLT_RECEIVE_SOCKET, DLT_DAEMON_RCVBUFSIZESOCK);
break;
case DLT_CONNECTION_CLIENT_MSG_SERIAL:
ret = calloc(1, sizeof(DltReceiver));
if (ret)
- dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZESERIAL);
+ dlt_receiver_init(ret, fd, DLT_RECEIVE_FD, DLT_DAEMON_RCVBUFSIZESERIAL);
break;
case DLT_CONNECTION_APP_MSG:
ret = calloc(1, sizeof(DltReceiver));
- if (ret) {
- #ifdef DLT_USE_UNIX_SOCKET_IPC
- dlt_receiver_init_unix_socket(ret, fd, &app_recv_buffer);
- #else
- dlt_receiver_init(ret, fd, DLT_RECEIVE_BUFSIZE);
- #endif
+ receiver_type = DLT_RECEIVE_FD;
+
+ if (fstat(fd, &statbuf) == 0) {
+ if (S_ISSOCK(statbuf.st_mode))
+ receiver_type = DLT_RECEIVE_SOCKET;
+ } else {
+ dlt_vlog(LOG_WARNING,
+ "Failed to determine receive type for DLT_CONNECTION_APP_MSG, using \"FD\"\n");
}
+ if (ret)
+ dlt_receiver_init_global_buffer(ret, fd, receiver_type, &app_recv_buffer);
+
break;
-#ifdef DLT_USE_UNIX_SOCKET_IPC
+#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE
case DLT_CONNECTION_APP_CONNECT:
/* FALL THROUGH */
#endif
@@ -243,7 +251,7 @@ DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local
ret = calloc(1, sizeof(DltReceiver));
if (ret)
- dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZE);
+ dlt_receiver_init(ret, fd, DLT_RECEIVE_FD, DLT_DAEMON_RCVBUFSIZE);
break;
case DLT_CONNECTION_GATEWAY:
@@ -286,7 +294,7 @@ 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
+#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE
case DLT_CONNECTION_APP_CONNECT:
ret = dlt_daemon_process_app_connect;
break;