Skip to content

Commit 570e189

Browse files
LUU QUANG MINHLUU QUANG MINH
LUU QUANG MINH
authored and
LUU QUANG MINH
committed
daemon: Prevent new daemon created on same machine
+ Only one daemon on the machine listening to fifo + fifo will not be unlinked by the new daemon init Signed-off-by: LUU QUANG MINH <Minh.LuuQuang@vn.bosch.com> Signed-off-by: andv <fixed-term.An.DuVan@vn.bosch.com>
1 parent 8fc4e8e commit 570e189

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ if(WITH_GIT_SUBMODULE)
380380
endif()
381381

382382
if(WITH_DLT_UNIT_TESTS)
383+
set(DLT_IPC "UNIX_SOCKET")
383384
find_package(GTest)
384385
if(GTEST_FOUND)
385386
find_package(PkgConfig REQUIRED)

src/daemon/dlt-daemon.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -1590,9 +1590,13 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local)
15901590
/* open named pipe(FIFO) to receive DLT messages from users */
15911591
umask(0);
15921592

1593-
/* Try to delete existing pipe, ignore result of unlink */
1593+
/* Valid fifo means there is a daemon running, stop init phase of the new */
15941594
const char *tmpFifo = daemon_local->flags.daemonFifoName;
1595-
unlink(tmpFifo);
1595+
if (access(tmpFifo, F_OK) == 0) {
1596+
dlt_vlog(LOG_WARNING, "FIFO user %s is in use (%s)!\n",
1597+
tmpFifo, strerror(errno));
1598+
return -1;
1599+
}
15961600

15971601
ret = mkfifo(tmpFifo, S_IRUSR | S_IWUSR | S_IWGRP);
15981602

@@ -1608,7 +1612,9 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local)
16081612
struct group *group_dlt = getgrnam(daemon_local->flags.daemonFifoGroup);
16091613

16101614
if (group_dlt) {
1611-
ret = chown(tmpFifo, -1, group_dlt->gr_gid);
1615+
if (access(tmpFifo, F_OK) == 0) {
1616+
ret = chown(tmpFifo, -1, group_dlt->gr_gid);
1617+
}
16121618

16131619
if (ret == -1)
16141620
dlt_vlog(LOG_ERR, "FIFO user %s cannot be chowned to group %s (%s)\n",

0 commit comments

Comments
 (0)