Skip to content

Commit

Permalink
daemon: Prevent new daemon created on same machine
Browse files Browse the repository at this point in the history
+ 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 <[email protected]>
Signed-off-by: andv <[email protected]>
  • Loading branch information
LUU QUANG MINH authored and LUU QUANG MINH committed Jun 27, 2024
1 parent 8fc4e8e commit 570e189
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ if(WITH_GIT_SUBMODULE)
endif()

if(WITH_DLT_UNIT_TESTS)
set(DLT_IPC "UNIX_SOCKET")
find_package(GTest)
if(GTEST_FOUND)
find_package(PkgConfig REQUIRED)
Expand Down
12 changes: 9 additions & 3 deletions src/daemon/dlt-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,9 +1590,13 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local)
/* open named pipe(FIFO) to receive DLT messages from users */
umask(0);

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

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

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

if (group_dlt) {
ret = chown(tmpFifo, -1, group_dlt->gr_gid);
if (access(tmpFifo, F_OK) == 0) {
ret = chown(tmpFifo, -1, group_dlt->gr_gid);

Check failure

Code scanning / CodeQL

Time-of-check time-of-use filesystem race condition High

The
filename
being operated upon was previously
checked
, but the underlying file may have been changed since then.
The
filename
being operated upon was previously
checked
, but the underlying file may have been changed since then.
}

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

0 comments on commit 570e189

Please sign in to comment.