diff options
author | LUONG HONG DUY KHANH(RBVH/ENG42) <KHANH.LUONGHONGDUY@vn.bosch.com> | 2020-05-12 20:27:21 +0700 |
---|---|---|
committer | Saya Sugiura <39760799+ssugiura@users.noreply.github.com> | 2020-07-06 10:04:07 +0900 |
commit | 54768d5f559aa9b35ab61c20f4f56e1e9409f17a (patch) | |
tree | 3ebf52c5e1a536421c907d282589ea1e31104aba | |
parent | 9b3ba69399a92ee3c999959fa75a582879550ad4 (diff) | |
download | DLT-daemon-54768d5f559aa9b35ab61c20f4f56e1e9409f17a.tar.gz |
common: Isolate FIFO/Unix socket
dlt_common
- Add preprocessor DLT_USE_UNIX_SOCKET_IPC for dlt_log_set_fifo_basedir() and
dltFifoBaseDir variable
- Rename input parameter of dlt_log_set_fifo_basedir()
dlt-daemon
- Replace setting dltFifoBaseDir by dlt_log_set_fifo_basedir() and add preproc
DLT_USE_UNIX_SOCKET_IPC
- Update -h opt and flags.loggingFilename based on IPC type
Signed-off-by: LUONG HONG DUY KHANH(RBVH/ENG42) <KHANH.LUONGHONGDUY@vn.bosch.com>
-rw-r--r-- | include/dlt/dlt_common.h | 9 | ||||
-rw-r--r-- | src/daemon/dlt-daemon.c | 26 | ||||
-rw-r--r-- | src/shared/dlt_common.c | 12 |
3 files changed, 40 insertions, 7 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index be033db..9f4096b 100644 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -415,10 +415,12 @@ extern const char dltSerialHeader[DLT_ID_SIZE]; */ extern char dltSerialHeaderChar[DLT_ID_SIZE]; +#ifndef DLT_USE_UNIX_SOCKET_IPC /** * The common base-path of the dlt-daemon-fifo and application-generated fifos */ extern char dltFifoBaseDir[DLT_PATH_MAX]; +#endif #ifdef DLT_SHM_ENABLE /** @@ -1135,6 +1137,13 @@ DltReturnValue dlt_file_free(DltFile *file, int verbose); * @param filename the filename */ void dlt_log_set_filename(const char *filename); +#ifndef DLT_USE_UNIX_SOCKET_IPC +/** + * Set FIFO base direction + * @param pipe_dir the pipe direction + */ +void dlt_log_set_fifo_basedir(const char *pipe_dir); +#endif /** * Set internal logging level * @param level the level diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 4b686de..7abd4d5 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -105,10 +105,14 @@ void usage() printf(" -d Daemonize\n"); printf(" -h Usage\n"); printf(" -c filename DLT daemon configuration file (Default: " CONFIGURATION_FILES_DIR "/dlt.conf)\n"); + +#ifndef DLT_USE_UNIX_SOCKET_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"); printf(" variable DLT_PIPE_DIR set appropriately)\n"); +#endif + #ifdef DLT_SHM_ENABLE printf(" -s filename The file name to create the share memory (Default: /dlt-shm)\n"); printf(" (Applications wanting to connect to a daemon using a\n"); @@ -138,8 +142,10 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[]) /* default values */ daemon_local->flags.port = DLT_DAEMON_TCP_PORT; - strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, DLT_PATH_MAX); - dltFifoBaseDir[DLT_PATH_MAX - 1] = 0; + +#ifndef DLT_USE_UNIX_SOCKET_IPC + dlt_log_set_fifo_basedir(DLT_USER_IPC_PATH); +#endif #ifdef DLT_SHM_ENABLE strncpy(dltShmName, "/dlt-shm", NAME_MAX); @@ -165,12 +171,14 @@ 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 case 't': { - strncpy(dltFifoBaseDir, optarg, DLT_PATH_MAX); - dltFifoBaseDir[DLT_PATH_MAX - 1] = 0; + dlt_log_set_fifo_basedir(optarg); break; } +#endif + #ifdef DLT_SHM_ENABLE case 's': { @@ -255,9 +263,16 @@ 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 + n = snprintf(daemon_local->flags.loggingFilename, + sizeof(daemon_local->flags.loggingFilename), + "%s/dlt.log", DLT_USER_IPC_PATH); +#else n = snprintf(daemon_local->flags.loggingFilename, sizeof(daemon_local->flags.loggingFilename), "%s/dlt.log", dltFifoBaseDir); +#endif + if (n < 0 || (size_t)n > sizeof(daemon_local->flags.loggingFilename)) { dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%d) %s\n", __func__, n, daemon_local->flags.loggingFilename); @@ -1500,6 +1515,8 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i void dlt_daemon_exit_trigger() { + +#ifndef DLT_USE_UNIX_SOCKET_IPC char tmp[DLT_PATH_MAX] = { 0 }; ssize_t n; @@ -1510,6 +1527,7 @@ void dlt_daemon_exit_trigger() } (void)unlink(tmp); +#endif /* stop event loop */ g_exit = -1; diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index cd71044..eb620f5 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -65,7 +65,10 @@ 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 char dltFifoBaseDir[DLT_PATH_MAX] = "/tmp"; +#endif #ifdef DLT_SHM_ENABLE char dltShmName[NAME_MAX + 1] = "/dlt-shm"; @@ -1726,11 +1729,13 @@ void dlt_log_set_filename(const char *filename) logging_filename[NAME_MAX] = 0; } -void dlt_log_set_fifo_basedir(const char *env_pipe_dir) +#ifndef DLT_USE_UNIX_SOCKET_IPC +void dlt_log_set_fifo_basedir(const char *pipe_dir) { - strncpy(dltFifoBaseDir, env_pipe_dir, DLT_PATH_MAX); + strncpy(dltFifoBaseDir, pipe_dir, DLT_PATH_MAX); dltFifoBaseDir[DLT_PATH_MAX - 1] = 0; } +#endif #ifdef DLT_SHM_ENABLE void dlt_log_set_shm_name(const char * env_shm_name) @@ -3795,13 +3800,14 @@ void dlt_check_envvar() dlt_log_init(mode); } +#ifndef DLT_USE_UNIX_SOCKET_IPC char *env_pipe_dir = getenv("DLT_PIPE_DIR"); if (env_pipe_dir != NULL) dlt_log_set_fifo_basedir(env_pipe_dir); else dlt_log_set_fifo_basedir(DLT_USER_IPC_PATH); - +#endif #ifdef DLT_SHM_ENABLE char* env_shm_name = getenv("DLT_SHM_NAME"); |