diff options
Diffstat (limited to 'src/daemon/dlt_daemon_common.c')
-rw-r--r-- | src/daemon/dlt_daemon_common.c | 35 |
1 files changed, 26 insertions, 9 deletions
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; } } |