diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/dlt-daemon.c | 159 | ||||
-rw-r--r-- | src/daemon/dlt-daemon.h | 6 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_common.c | 118 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_common.h | 1 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_common_cfg.h | 2 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_connection.c | 32 | ||||
-rw-r--r-- | src/examples/dlt-example-multicast-clientmsg-view.c | 4 | ||||
-rw-r--r-- | src/gateway/dlt_gateway.c | 2 | ||||
-rw-r--r-- | src/lib/dlt_client.c | 14 | ||||
-rw-r--r-- | src/lib/dlt_user.c | 162 | ||||
-rw-r--r-- | src/shared/dlt_common.c | 58 |
11 files changed, 366 insertions, 192 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; diff --git a/src/examples/dlt-example-multicast-clientmsg-view.c b/src/examples/dlt-example-multicast-clientmsg-view.c index c9bd743..f68473c 100644 --- a/src/examples/dlt-example-multicast-clientmsg-view.c +++ b/src/examples/dlt-example-multicast-clientmsg-view.c @@ -164,7 +164,9 @@ int main() if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - if (dlt_receiver_init(&(clientinfo.receiver), clientinfo.fd, + if (dlt_receiver_init(&(clientinfo.receiver), + clientinfo.fd, + DLT_RECEIVE_UDP_SOCKET, DLT_RECEIVE_BUFSIZE) != DLT_RETURN_OK) return DLT_RETURN_ERROR; diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c index 9c6578f..9d0041d 100644 --- a/src/gateway/dlt_gateway.c +++ b/src/gateway/dlt_gateway.c @@ -1321,7 +1321,7 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, } /* nearly copy and paste of dlt_client_main_loop function */ - if (dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET) <= 0) { + if (dlt_receiver_receive(receiver) <= 0) { /* No more data to be received */ if (dlt_message_free(&msg, verbose) < 0) { dlt_log(LOG_ERR, "Cannot free DLT message\n"); diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c index ad7a66b..736fd70 100644 --- a/src/lib/dlt_client.c +++ b/src/lib/dlt_client.c @@ -166,6 +166,8 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) struct sockaddr_un addr; int rv; struct ip_mreq mreq; + DltReceiverType receiver_type = DLT_RECEIVE_FD; + memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; @@ -206,6 +208,8 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) if (verbose) printf("Connected to DLT daemon (%s)\n", client->servIP); + receiver_type = DLT_RECEIVE_SOCKET; + break; case DLT_CLIENT_MODE_SERIAL: /* open serial connection */ @@ -242,6 +246,8 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) if (verbose) printf("Connected to %s\n", client->serialDevice); + receiver_type = DLT_RECEIVE_FD; + break; case DLT_CLIENT_MODE_UNIX: @@ -267,6 +273,8 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) return DLT_RETURN_ERROR; } + receiver_type = DLT_RECEIVE_SOCKET; + break; case DLT_CLIENT_MODE_UDP_MULTICAST: @@ -319,6 +327,8 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) return DLT_RETURN_ERROR; } + receiver_type = DLT_RECEIVE_UDP_SOCKET; + break; default: @@ -328,7 +338,7 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) return DLT_RETURN_ERROR; } - if (dlt_receiver_init(&(client->receiver), client->sock, DLT_RECEIVE_BUFSIZE) != DLT_RETURN_OK) { + if (dlt_receiver_init(&(client->receiver), client->sock, receiver_type, DLT_RECEIVE_BUFSIZE) != DLT_RETURN_OK) { fprintf(stderr, "ERROR initializing receiver\n"); return DLT_RETURN_ERROR; } @@ -389,7 +399,7 @@ DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose) while (1) { /* wait for data from socket or serial connection */ - ret = dlt_receiver_receive(&(client->receiver), client->mode); + ret = dlt_receiver_receive(&(client->receiver)); if (ret <= 0) { /* No more data to be received */ diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index ae076ca..ccebd4f 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -54,10 +54,21 @@ #include <unistd.h> #include <stdbool.h> -#ifdef DLT_USE_UNIX_SOCKET_IPC -# include <sys/un.h> + +#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC # include <sys/socket.h> #endif +#ifdef DLT_LIB_USE_UNIX_SOCKET_IPC +# include <sys/un.h> +#endif +#ifdef DLT_LIB_USE_VSOCK_IPC +# ifdef linux +# include <linux/vm_sockets.h> +# endif +# ifdef __QNX__ +# include <vm_sockets.h> +# endif +#endif #include "dlt_user.h" #include "dlt_common.h" @@ -81,7 +92,7 @@ static DltUser dlt_user; static bool dlt_user_initialised = false; static int dlt_user_freeing = 0; -#ifndef DLT_USE_UNIX_SOCKET_IPC +#ifdef DLT_LIB_USE_FIFO_IPC static char dlt_user_dir[DLT_PATH_MAX]; static char dlt_daemon_fifo[DLT_PATH_MAX]; #endif @@ -209,13 +220,33 @@ DltReturnValue dlt_user_check_library_version(const char *user_major_version, co return DLT_RETURN_OK; } -#ifdef DLT_USE_UNIX_SOCKET_IPC +#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC +static DltReturnValue dlt_socket_set_nonblock_and_linger(int sockfd) +{ + int status; + struct linger l_opt; + + status = fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0) | O_NONBLOCK); + if (status == -1) { + dlt_log(LOG_INFO, "Socket cannot be changed to NON BLOCK\n"); + return DLT_RETURN_ERROR; + } + + l_opt.l_onoff = 1; + l_opt.l_linger = 10; + + if (setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &l_opt, sizeof l_opt) < 0) + dlt_log(LOG_WARNING, "Failed to set socket linger option\n"); + + return DLT_RETURN_OK; +} +#endif + +#ifdef DLT_LIB_USE_UNIX_SOCKET_IPC static DltReturnValue dlt_initialize_socket_connection(void) { struct sockaddr_un remote; - int status = 0; char dltSockBaseDir[DLT_IPC_PATH_MAX]; - struct linger l_opt; DLT_SEM_LOCK(); int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); @@ -226,22 +257,12 @@ static DltReturnValue dlt_initialize_socket_connection(void) return DLT_RETURN_ERROR; } - status = fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0) | O_NONBLOCK); - - if (status == -1) { - dlt_vlog(LOG_INFO, - "Socket %s/dlt cannot be changed to NON BLOCK\n", - DLT_USER_IPC_PATH); + if (dlt_socket_set_nonblock_and_linger(sockfd) != DLT_RETURN_OK) { + close(sockfd); + DLT_SEM_FREE(); return DLT_RETURN_ERROR; } - /* Set SO_LINGER opt for the new client socket. */ - l_opt.l_onoff = 1; - l_opt.l_linger = 10; - - if (setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &l_opt, sizeof l_opt) < 0) - dlt_log(LOG_WARNING, "Failed to set linger option\n"); - remote.sun_family = AF_UNIX; snprintf(dltSockBaseDir, DLT_IPC_PATH_MAX, "%s/dlt", DLT_USER_IPC_PATH); strncpy(remote.sun_path, dltSockBaseDir, sizeof(remote.sun_path)); @@ -268,8 +289,10 @@ static DltReturnValue dlt_initialize_socket_connection(void) if (dlt_receiver_init(&(dlt_user.receiver), sockfd, + DLT_RECEIVE_SOCKET, DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { dlt_user_initialised = false; + close(sockfd); DLT_SEM_FREE(); return DLT_RETURN_ERROR; } @@ -279,7 +302,62 @@ static DltReturnValue dlt_initialize_socket_connection(void) return DLT_RETURN_OK; } -#else /* setup fifo*/ +#elif defined DLT_LIB_USE_VSOCK_IPC +static DltReturnValue dlt_initialize_vsock_connection() +{ + struct sockaddr_vm remote; + + DLT_SEM_LOCK(); + int sockfd = socket(AF_VSOCK, SOCK_STREAM, 0); + + if (sockfd == DLT_FD_INIT) { + dlt_log(LOG_CRIT, "Failed to create VSOCK socket\n"); + DLT_SEM_FREE(); + return DLT_RETURN_ERROR; + } + + memset(&remote, 0, sizeof(remote)); + remote.svm_family = AF_VSOCK; + remote.svm_port = DLT_VSOCK_PORT; + remote.svm_cid = VMADDR_CID_HOST; + + if (connect(sockfd, (struct sockaddr *)&remote, sizeof(remote)) == -1) { + if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT) { + dlt_vlog(LOG_INFO, "VSOCK socket cannot be opened. Retrying later...\n"); + dlt_user.connection_state = DLT_USER_RETRY_CONNECT; + } + + close(sockfd); + dlt_user.dlt_log_handle = -1; + } + else { + /* Set to non-blocking after connect() to avoid EINPROGRESS. DltUserConntextionState + needs "connecting" state if connect() should be non-blocking. */ + if (dlt_socket_set_nonblock_and_linger(sockfd) != DLT_RETURN_OK) { + close(sockfd); + DLT_SEM_FREE(); + 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_RECEIVE_SOCKET, + DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { + dlt_user_initialised = false; + close(sockfd); + DLT_SEM_FREE(); + return DLT_RETURN_ERROR; + } + } + + DLT_SEM_FREE(); + + return DLT_RETURN_OK; +} +#else /* DLT_LIB_USE_FIFO_IPC */ static DltReturnValue dlt_initialize_fifo_connection(void) { char filename[DLT_PATH_MAX]; @@ -383,7 +461,7 @@ DltReturnValue dlt_init(void) #endif -#ifdef DLT_USE_UNIX_SOCKET_IPC +#ifdef DLT_LIB_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 */ @@ -391,12 +469,19 @@ DltReturnValue dlt_init(void) /* in case application is started before daemon, it is expected behaviour */ return DLT_RETURN_ERROR; -#else /* FIFO connection */ +#elif defined DLT_LIB_USE_VSOCK_IPC + + if (dlt_initialize_vsock_connection() != DLT_RETURN_OK) + return DLT_RETURN_ERROR; + +#else /* DLT_LIB_USE_FIFO_IPC */ if (dlt_initialize_fifo_connection() != DLT_RETURN_OK) return DLT_RETURN_ERROR; - if (dlt_receiver_init(&(dlt_user.receiver), dlt_user.dlt_user_handle, + if (dlt_receiver_init(&(dlt_user.receiver), + dlt_user.dlt_user_handle, + DLT_RECEIVE_FD, DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { dlt_user_initialised = false; return DLT_RETURN_ERROR; @@ -821,7 +906,7 @@ DltReturnValue dlt_free(void) { uint32_t i; int ret = 0; -#ifndef DLT_USE_UNIX_SOCKET_IPC +#ifdef DLT_LIB_USE_FIFO_IPC char filename[DLT_PATH_MAX]; #endif @@ -841,7 +926,7 @@ DltReturnValue dlt_free(void) dlt_stop_threads(); -#ifndef DLT_USE_UNIX_SOCKET_IPC +#ifdef DLT_LIB_USE_FIFO_IPC if (dlt_user.dlt_user_handle != DLT_FD_INIT) { close(dlt_user.dlt_user_handle); @@ -859,7 +944,7 @@ DltReturnValue dlt_free(void) if (dlt_user.dlt_log_handle != -1) { /* close log file/output fifo to daemon */ -#ifdef DLT_USE_UNIX_SOCKET_IPC +#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC ret = shutdown(dlt_user.dlt_log_handle, SHUT_WR); if (ret < 0) { @@ -3752,7 +3837,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; -#ifdef DLT_USE_UNIX_SOCKET_IPC +#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC dlt_user.connection_state = DLT_USER_RETRY_CONNECT; #endif @@ -4126,7 +4211,6 @@ DltReturnValue dlt_user_log_check_user_message(void) uint32_t i; int fd; - DltReceiverType from_src_type = DLT_RECEIVE_FD; struct pollfd nfd[1]; DltUserHeader *userheader; @@ -4150,20 +4234,18 @@ DltReturnValue dlt_user_log_check_user_message(void) delayed_log_level_changed_callback.log_level_changed_callback = 0; delayed_injection_callback.data = 0; -#ifdef DLT_USE_UNIX_SOCKET_IPC +#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC fd = dlt_user.dlt_log_handle; - from_src_type = DLT_RECEIVE_SOCKET; -#else +#else /* DLT_LIB_USE_FIFO_IPC */ fd = dlt_user.dlt_user_handle; - from_src_type = DLT_RECEIVE_FD; #endif nfd[0].events = POLLIN; nfd[0].fd = fd; -#ifdef DLT_USE_UNIX_SOCKET_IPC +#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC if (fd != DLT_FD_INIT) { ret = poll(nfd, 1, -1); -#else +#else /* DLT_LIB_USE_FIFO_IPC */ if (fd != DLT_FD_INIT && dlt_user.dlt_log_handle > 0) { ret = poll(nfd, 1, DLT_USER_RECEIVE_NDELAY); #endif @@ -4173,7 +4255,7 @@ DltReturnValue dlt_user_log_check_user_message(void) return DLT_RETURN_ERROR; } - if (dlt_receiver_receive(receiver, from_src_type) <= 0) + if (dlt_receiver_receive(receiver) <= 0) /* No new message available */ return DLT_RETURN_OK; @@ -4502,7 +4584,7 @@ void dlt_user_log_reattach_to_daemon(void) if (dlt_user.dlt_log_handle < 0) { dlt_user.dlt_log_handle = DLT_FD_INIT; -#ifdef DLT_USE_UNIX_SOCKET_IPC +#ifdef DLT_LIB_USE_UNIX_SOCKET_IPC /* try to open connection to dlt daemon */ dlt_initialize_socket_connection(); @@ -4510,7 +4592,13 @@ void dlt_user_log_reattach_to_daemon(void) /* return if not connected */ return; -#else +#elif defined DLT_LIB_USE_VSOCK_IPC + dlt_initialize_vsock_connection(); + + if (dlt_user.connection_state != DLT_USER_CONNECTED) + return; + +#else /* DLT_LIB_USE_FIFO_IPC */ /* try to open pipe to dlt daemon */ int fd = open(dlt_daemon_fifo, O_WRONLY | O_NONBLOCK); diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 615665c..d545fe0 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -66,7 +66,7 @@ const char dltSerialHeader[DLT_ID_SIZE] = { 'D', 'L', 'S', 1 }; char dltSerialHeaderChar[DLT_ID_SIZE] = { 'D', 'L', 'S', 1 }; -#ifndef DLT_USE_UNIX_SOCKET_IPC +#if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC char dltFifoBaseDir[DLT_PATH_MAX] = "/tmp"; #endif @@ -1736,7 +1736,7 @@ void dlt_log_set_filename(const char *filename) logging_filename[NAME_MAX] = 0; } -#ifndef DLT_USE_UNIX_SOCKET_IPC +#if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC void dlt_log_set_fifo_basedir(const char *pipe_dir) { strncpy(dltFifoBaseDir, pipe_dir, DLT_PATH_MAX); @@ -1921,12 +1921,13 @@ DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...) return DLT_RETURN_OK; } -DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize) +DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, DltReceiverType type, int buffersize) { if (NULL == receiver) return DLT_RETURN_WRONG_PARAMETER; receiver->fd = fd; + receiver->type = type; /** Reuse the receiver buffer if it exists and the buffer size * is not changed. If not, free the old one and allocate a new buffer. @@ -1957,7 +1958,7 @@ DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize) return DLT_RETURN_OK; } -DltReturnValue dlt_receiver_init_unix_socket(DltReceiver *receiver, int fd, char **buffer) +DltReturnValue dlt_receiver_init_global_buffer(DltReceiver *receiver, int fd, DltReceiverType type, char **buffer) { if (receiver == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -1977,6 +1978,7 @@ DltReturnValue dlt_receiver_init_unix_socket(DltReceiver *receiver, int fd, char receiver->totalBytesRcvd = 0; receiver->buffersize = DLT_RECEIVE_BUFSIZE; receiver->fd = fd; + receiver->type = type; receiver->buffer = *buffer; receiver->backup_buf = NULL; receiver->buf = receiver->buffer; @@ -2003,7 +2005,7 @@ DltReturnValue dlt_receiver_free(DltReceiver *receiver) return DLT_RETURN_OK; } -DltReturnValue dlt_receiver_free_unix_socket(DltReceiver *receiver) +DltReturnValue dlt_receiver_free_global_buffer(DltReceiver *receiver) { if (receiver == NULL) @@ -2019,7 +2021,7 @@ DltReturnValue dlt_receiver_free_unix_socket(DltReceiver *receiver) return DLT_RETURN_OK; } -int dlt_receiver_receive(DltReceiver *receiver, DltReceiverType from_src) +int dlt_receiver_receive(DltReceiver *receiver) { socklen_t addrlen; @@ -2038,19 +2040,19 @@ int dlt_receiver_receive(DltReceiver *receiver, DltReceiverType from_src) receiver->backup_buf = NULL; } - if (from_src == DLT_RECEIVE_SOCKET) + if (receiver->type == DLT_RECEIVE_SOCKET) /* wait for data from socket */ receiver->bytesRcvd = recv(receiver->fd, receiver->buf + receiver->lastBytesRcvd, receiver->buffersize - receiver->lastBytesRcvd, 0); - else if (from_src == DLT_RECEIVE_FD) + else if (receiver->type == DLT_RECEIVE_FD) /* wait for data from fd */ receiver->bytesRcvd = read(receiver->fd, receiver->buf + receiver->lastBytesRcvd, receiver->buffersize - receiver->lastBytesRcvd); - else { + else { /* receiver->type == DLT_RECEIVE_UDP_SOCKET */ /* wait for data from UDP socket */ addrlen = sizeof(receiver->addr); receiver->bytesRcvd = recvfrom(receiver->fd, @@ -3834,7 +3836,7 @@ void dlt_check_envvar() dlt_log_init(mode); } -#ifndef DLT_USE_UNIX_SOCKET_IPC +#if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC char *env_pipe_dir = getenv("DLT_PIPE_DIR"); if (env_pipe_dir != NULL) @@ -3993,42 +3995,6 @@ void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size) } } -#ifndef DLT_USE_UNIX_SOCKET_IPC -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 - DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename, int type, int verbose) { |