mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
daemon: make sure pa has its own session and process group, but is not its leader so that we cannot acquire a tty ever
This commit is contained in:
parent
2dc37e1214
commit
8e94f65348
3 changed files with 38 additions and 20 deletions
|
|
@ -657,7 +657,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
#ifdef HAVE_FORK
|
#ifdef HAVE_FORK
|
||||||
if (pipe(daemon_pipe) < 0) {
|
if (pipe(daemon_pipe) < 0) {
|
||||||
pa_log(_("pipe failed: %s"), pa_cstrerror(errno));
|
pa_log(_("pipe() failed: %s"), pa_cstrerror(errno));
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -708,22 +708,27 @@ int main(int argc, char *argv[]) {
|
||||||
pa_log_set_target(PA_LOG_SYSLOG);
|
pa_log_set_target(PA_LOG_SYSLOG);
|
||||||
|
|
||||||
#ifdef HAVE_SETSID
|
#ifdef HAVE_SETSID
|
||||||
setsid();
|
if (setsid() < 0) {
|
||||||
#endif
|
pa_log(_("setsid() failed: %s"), pa_cstrerror(errno));
|
||||||
#ifdef HAVE_SETPGID
|
goto finish;
|
||||||
setpgid(0,0);
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef OS_IS_WIN32
|
/* We now are a session and process group leader. Let's fork
|
||||||
pa_close(0);
|
* again and let the father die, so that we'll become a
|
||||||
pa_close(1);
|
* process that can never acquire a TTY again, in a session and
|
||||||
pa_close(2);
|
* process group without leader */
|
||||||
|
|
||||||
pa_assert_se(open("/dev/null", O_RDONLY) == 0);
|
#ifdef HAVE_FORK
|
||||||
pa_assert_se(open("/dev/null", O_WRONLY) == 1);
|
if ((child = fork()) < 0) {
|
||||||
pa_assert_se(open("/dev/null", O_WRONLY) == 2);
|
pa_log(_("fork() failed: %s"), pa_cstrerror(errno));
|
||||||
#else
|
goto finish;
|
||||||
FreeConsole();
|
}
|
||||||
|
|
||||||
|
if (child != 0) {
|
||||||
|
retval = 0;
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SIGTTOU
|
#ifdef SIGTTOU
|
||||||
|
|
@ -736,12 +741,7 @@ int main(int argc, char *argv[]) {
|
||||||
signal(SIGTSTP, SIG_IGN);
|
signal(SIGTSTP, SIG_IGN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TIOCNOTTY
|
pa_nullify_stdfds();
|
||||||
if ((tty_fd = open("/dev/tty", O_RDWR)) >= 0) {
|
|
||||||
ioctl(tty_fd, TIOCNOTTY, (char*) 0);
|
|
||||||
pa_assert_se(pa_close(tty_fd) == 0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_set_env_and_record("PULSE_INTERNAL", "1");
|
pa_set_env_and_record("PULSE_INTERNAL", "1");
|
||||||
|
|
|
||||||
|
|
@ -2999,3 +2999,19 @@ finish:
|
||||||
pa_make_fd_cloexec(fileno(f));
|
pa_make_fd_cloexec(fileno(f));
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pa_nullify_stdfds(void) {
|
||||||
|
|
||||||
|
#ifndef OS_IS_WIN32
|
||||||
|
pa_close(STDIN_FILENO);
|
||||||
|
pa_close(STDOUT_FILENO);
|
||||||
|
pa_close(STDERR_FILENO);
|
||||||
|
|
||||||
|
pa_assert_se(open("/dev/null", O_RDONLY) == STDIN_FILENO);
|
||||||
|
pa_assert_se(open("/dev/null", O_WRONLY) == STDOUT_FILENO);
|
||||||
|
pa_assert_se(open("/dev/null", O_WRONLY) == STDERR_FILENO);
|
||||||
|
#else
|
||||||
|
FreeConsole();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -265,4 +265,6 @@ int pa_pipe_cloexec(int pipefd[2]);
|
||||||
int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||||
FILE* pa_fopen_cloexec(const char *path, const char *mode);
|
FILE* pa_fopen_cloexec(const char *path, const char *mode);
|
||||||
|
|
||||||
|
void pa_nullify_stdfds(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue