diff options
author | Vo Trung Chi <chi.votrung@vn.bosch.com> | 2019-08-01 07:38:42 +0700 |
---|---|---|
committer | Saya Sugiura <39760799+ssugiura@users.noreply.github.com> | 2019-08-01 09:38:42 +0900 |
commit | 3f7dc3fd80e7fe548f89b96ab4228135dca688db (patch) | |
tree | efa1473fbd73b559fc6340c35479d060d2349553 /src/daemon/dlt-daemon.c | |
parent | 8673795b845e461e42920e44cdf70a5361457e8b (diff) | |
download | DLT-daemon-3f7dc3fd80e7fe548f89b96ab4228135dca688db.tar.gz |
using POSIX shared memory APIs (#90) (#151)
Replace all Linux specific shared memory APIs with POSIX alternatives.
Signed-off-by: Vo Trung Chi <Chi.VoTrung@vn.bosch.com>
Diffstat (limited to 'src/daemon/dlt-daemon.c')
-rw-r--r-- | src/daemon/dlt-daemon.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 3c80434..2f18ca8 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -106,6 +106,12 @@ void usage() 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"); +#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"); + printf(" custom shm name need to be started with the environment \n"); + printf(" variable DLT_SHM_NAME set appropriately)\n"); +#endif printf(" -p port port to monitor for incoming requests (Default: 3490)\n"); printf(" (Applications wanting to connect to a daemon using a custom\n"); printf(" port need to be started with the environment variable\n"); @@ -132,9 +138,17 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[]) strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, DLT_PATH_MAX); dltFifoBaseDir[DLT_PATH_MAX - 1] = 0; +#ifdef DLT_SHM_ENABLE + strncpy(dltShmName, "/dlt-shm", NAME_MAX); +#endif + opterr = 0; +#ifdef DLT_SHM_ENABLE + while ((c = getopt (argc, argv, "hdc:t:s:p:")) != -1) +#else while ((c = getopt (argc, argv, "hdc:t:p:")) != -1) +#endif switch (c) { case 'd': { @@ -152,6 +166,13 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[]) dltFifoBaseDir[DLT_PATH_MAX - 1] = 0; break; } +#ifdef DLT_SHM_ENABLE + case 's': + { + strncpy(dltShmName, optarg, NAME_MAX); + break; + } +#endif case 'p': { daemon_local->flags.port = atoi(optarg); @@ -192,9 +213,13 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[]) #ifndef DLT_USE_UNIX_SOCKET_IPC snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX, "%s/dltpipes", dltFifoBaseDir); -#endif snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir); +#endif + +#ifdef DLT_SHM_ENABLE + strncpy(daemon_local->flags.dltShmName, dltShmName, NAME_MAX); +#endif return 0; @@ -930,7 +955,9 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in #ifdef DLT_SHM_ENABLE /* init shared memory */ - if (dlt_shm_init_server(&(daemon_local->dlt_shm), DLT_SHM_KEY, daemon_local->flags.sharedMemorySize) == -1) { + if (dlt_shm_init_server(&(daemon_local->dlt_shm), daemon_local->flags.dltShmName, + daemon_local->flags.sharedMemorySize) == DLT_RETURN_ERROR) + { dlt_log(LOG_ERR, "Could not initialize shared memory\n"); return -1; } @@ -1312,7 +1339,7 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i #ifdef DLT_SHM_ENABLE /* free shared memory */ - dlt_shm_free_server(&(daemon_local->dlt_shm)); + dlt_shm_free_server(&(daemon_local->dlt_shm), daemon_local->flags.dltShmName); #endif if (daemon_local->flags.offlineLogstorageMaxDevices > 0) { |