-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
daemon: refactor IPC usage #664
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1414,6 +1414,7 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in | |
signal(SIGHUP, dlt_daemon_signal_handler); /* hangup signal */ | ||
signal(SIGQUIT, dlt_daemon_signal_handler); | ||
signal(SIGINT, dlt_daemon_signal_handler); | ||
signal(SIGSEGV, dlt_daemon_signal_handler); | ||
#ifdef __QNX__ | ||
signal(SIGUSR1, dlt_daemon_signal_handler); /* for timer threads */ | ||
#endif | ||
|
@@ -1585,14 +1586,19 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local) | |
{ | ||
int ret; | ||
int fd = -1; | ||
int dir_fd = -1; | ||
int fifo_size; | ||
|
||
/* 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); | ||
|
||
|
@@ -1602,13 +1608,27 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local) | |
return -1; | ||
} /* if */ | ||
|
||
dir_fd = open(dltFifoBaseDir, O_RDONLY); | ||
if (dir_fd == -1) { | ||
dlt_vlog(LOG_WARNING, "Directory %s of fifo cannot be opened (%s)!\n", | ||
dltFifoBaseDir, strerror(errno)); | ||
return -1; | ||
} | ||
|
||
fd = openat(dir_fd, tmpFifo, O_RDWR); | ||
if (fd == -1) { | ||
dlt_vlog(LOG_WARNING, "FIFO user %s cannot be opened (%s)!\n", | ||
tmpFifo, strerror(errno)); | ||
return -1; | ||
} /* if */ | ||
|
||
/* Set group of daemon FIFO */ | ||
if (daemon_local->flags.daemonFifoGroup[0] != 0) { | ||
errno = 0; | ||
struct group *group_dlt = getgrnam(daemon_local->flags.daemonFifoGroup); | ||
|
||
if (group_dlt) { | ||
ret = chown(tmpFifo, -1, group_dlt->gr_gid); | ||
ret = fchown(fd, -1, group_dlt->gr_gid); | ||
|
||
if (ret == -1) | ||
dlt_vlog(LOG_ERR, "FIFO user %s cannot be chowned to group %s (%s)\n", | ||
|
@@ -1628,14 +1648,6 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local) | |
} | ||
} | ||
|
||
fd = open(tmpFifo, O_RDWR); | ||
|
||
if (fd == -1) { | ||
dlt_vlog(LOG_WARNING, "FIFO user %s cannot be opened (%s)!\n", | ||
tmpFifo, strerror(errno)); | ||
return -1; | ||
} /* if */ | ||
|
||
#ifdef __linux__ | ||
/* F_SETPIPE_SZ and F_GETPIPE_SZ are only supported for Linux. | ||
* For other OSes it depends on its system e.g. pipe manager. | ||
|
@@ -2150,6 +2162,7 @@ void dlt_daemon_signal_handler(int sig) | |
case SIGTERM: | ||
case SIGINT: | ||
case SIGQUIT: | ||
case SIGSEGV: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SIGSEGV needs to be handled separately. For example, after calling dlt_daemon_exit_trigger() set the SIG_DFL for SIGSEGV and raise() the same signal (or just let it hit SIGSEGV on its own again). I really don't advise calling dlt_daemon_exit_trigger() since it calls async-unsafe functions in a signal handler, but since you already break that rule I wont complain. |
||
{ | ||
/* finalize the server */ | ||
dlt_vlog(LOG_NOTICE, "Exiting DLT daemon due to signal: %s\n", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handler for SIGSEGV should not be added here. This will cause the application to hang in an endless loop in case a segmentation fault occurs as it will re-execute the same instruction again which caused the segmentation fault (and signal is triggered again)