mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
dmeventd: use standard reopening mechanism
Apply same code for reopening /dev/null for 0,1,2 when daemonizing.
This commit is contained in:
parent
d194fb8513
commit
7c4be946cb
@ -1943,7 +1943,7 @@ static void _remove_files_on_exit(void)
|
|||||||
|
|
||||||
static void _daemonize(void)
|
static void _daemonize(void)
|
||||||
{
|
{
|
||||||
int child_status;
|
int child_status, null_fd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
struct timeval tval;
|
struct timeval tval;
|
||||||
sigset_t my_sigset;
|
sigset_t my_sigset;
|
||||||
@ -1998,13 +1998,20 @@ static void _daemonize(void)
|
|||||||
|
|
||||||
daemon_close_stray_fds("dmeventd", 0, -1, &custom_fds);
|
daemon_close_stray_fds("dmeventd", 0, -1, &custom_fds);
|
||||||
|
|
||||||
/* coverity[leaked_handle] dont't care */
|
if ((null_fd = open("/dev/null", O_RDWR)) < 0)
|
||||||
if ((open("/dev/null", O_RDONLY) < 0) ||
|
|
||||||
(open("/dev/null", O_WRONLY) < 0) ||
|
|
||||||
(open("/dev/null", O_WRONLY) < 0))
|
|
||||||
exit(EXIT_DESC_OPEN_FAILURE);
|
exit(EXIT_DESC_OPEN_FAILURE);
|
||||||
|
|
||||||
|
if ((dup2(null_fd, STDIN_FILENO) == -1) ||
|
||||||
|
(dup2(null_fd, STDOUT_FILENO) == -1) ||
|
||||||
|
(dup2(null_fd, STDERR_FILENO) == -1))
|
||||||
|
exit(EXIT_DESC_OPEN_FAILURE);
|
||||||
|
|
||||||
|
if ((null_fd > STDERR_FILENO) && close(null_fd))
|
||||||
|
exit(EXIT_DESC_CLOSE_FAILURE);
|
||||||
|
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
|
/* coverity[leaked_handle] 'null_fd' handle is not leaking */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _reinstate_registrations(struct dm_event_fifos *fifos)
|
static int _reinstate_registrations(struct dm_event_fifos *fifos)
|
||||||
|
Loading…
Reference in New Issue
Block a user