summaryrefslogtreecommitdiffstats
path: root/src/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/.gitignore1
-rw-r--r--src/daemon/cpulimit.c4
-rw-r--r--src/daemon/daemon-conf.c4
-rw-r--r--src/daemon/main.c63
4 files changed, 37 insertions, 35 deletions
diff --git a/src/daemon/.gitignore b/src/daemon/.gitignore
index 0efa55ba..54e4299b 100644
--- a/src/daemon/.gitignore
+++ b/src/daemon/.gitignore
@@ -1,2 +1,3 @@
org.pulseaudio.policy
pulseaudio.desktop
+pulseaudio-kde.desktop
diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c
index c2877ecf..f5042a75 100644
--- a/src/daemon/cpulimit.c
+++ b/src/daemon/cpulimit.c
@@ -188,15 +188,13 @@ int pa_cpu_limit_init(pa_mainloop_api *m) {
last_time = pa_rtclock_now();
/* Prepare the main loop pipe */
- if (pipe(the_pipe) < 0) {
+ if (pa_pipe_cloexec(the_pipe) < 0) {
pa_log("pipe() failed: %s", pa_cstrerror(errno));
return -1;
}
pa_make_fd_nonblock(the_pipe[0]);
pa_make_fd_nonblock(the_pipe[1]);
- pa_make_fd_cloexec(the_pipe[0]);
- pa_make_fd_cloexec(the_pipe[1]);
api = m;
io_event = api->io_new(m, the_pipe[0], PA_IO_EVENT_INPUT, callback, NULL);
diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c
index 571faae4..bfd5c118 100644
--- a/src/daemon/daemon-conf.c
+++ b/src/daemon/daemon-conf.c
@@ -577,7 +577,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
c->config_file = NULL;
f = filename ?
- fopen(c->config_file = pa_xstrdup(filename), "r") :
+ pa_fopen_cloexec(c->config_file = pa_xstrdup(filename), "r") :
pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file);
if (!f && errno != ENOENT) {
@@ -652,7 +652,7 @@ FILE *pa_daemon_conf_open_default_script_file(pa_daemon_conf *c) {
else
f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file);
} else
- f = fopen(c->default_script_file, "r");
+ f = pa_fopen_cloexec(c->default_script_file, "r");
return f;
}
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 9e5647a8..cc6f24bd 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -425,21 +425,24 @@ int main(int argc, char *argv[]) {
pa_set_env("LD_BIND_NOW", "1");
- canonical_rp = pa_realpath(PA_BINARY);
+ if ((canonical_rp = pa_realpath(PA_BINARY))) {
- if ((rp = pa_readlink("/proc/self/exe"))) {
+ if ((rp = pa_readlink("/proc/self/exe"))) {
- if (pa_streq(rp, canonical_rp))
- pa_assert_se(execv(rp, argv) == 0);
- else
- pa_log_warn("/proc/self/exe does not point to %s, cannot self execute. Are you playing games?", canonical_rp);
+ if (pa_streq(rp, canonical_rp))
+ pa_assert_se(execv(rp, argv) == 0);
+ else
+ pa_log_warn("/proc/self/exe does not point to %s, cannot self execute. Are you playing games?", canonical_rp);
- pa_xfree(rp);
+ pa_xfree(rp);
- } else
- pa_log_warn("Couldn't read /proc/self/exe, cannot self execute. Running in a chroot()?");
+ } else
+ pa_log_warn("Couldn't read /proc/self/exe, cannot self execute. Running in a chroot()?");
+
+ pa_xfree(canonical_rp);
- pa_xfree(canonical_rp);
+ } else
+ pa_log_warn("Couldn't canonicalize binary path, cannot self execute.");
}
#endif
@@ -654,7 +657,7 @@ int main(int argc, char *argv[]) {
#ifdef HAVE_FORK
if (pipe(daemon_pipe) < 0) {
- pa_log(_("pipe failed: %s"), pa_cstrerror(errno));
+ pa_log(_("pipe() failed: %s"), pa_cstrerror(errno));
goto finish;
}
@@ -705,22 +708,27 @@ int main(int argc, char *argv[]) {
pa_log_set_target(PA_LOG_SYSLOG);
#ifdef HAVE_SETSID
- setsid();
-#endif
-#ifdef HAVE_SETPGID
- setpgid(0,0);
+ if (setsid() < 0) {
+ pa_log(_("setsid() failed: %s"), pa_cstrerror(errno));
+ goto finish;
+ }
#endif
-#ifndef OS_IS_WIN32
- pa_close(0);
- pa_close(1);
- pa_close(2);
+ /* We now are a session and process group leader. Let's fork
+ * again and let the father die, so that we'll become a
+ * process that can never acquire a TTY again, in a session and
+ * process group without leader */
- pa_assert_se(open("/dev/null", O_RDONLY) == 0);
- pa_assert_se(open("/dev/null", O_WRONLY) == 1);
- pa_assert_se(open("/dev/null", O_WRONLY) == 2);
-#else
- FreeConsole();
+#ifdef HAVE_FORK
+ if ((child = fork()) < 0) {
+ pa_log(_("fork() failed: %s"), pa_cstrerror(errno));
+ goto finish;
+ }
+
+ if (child != 0) {
+ retval = 0;
+ goto finish;
+ }
#endif
#ifdef SIGTTOU
@@ -733,12 +741,7 @@ int main(int argc, char *argv[]) {
signal(SIGTSTP, SIG_IGN);
#endif
-#ifdef TIOCNOTTY
- 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_nullify_stdfds();
}
pa_set_env_and_record("PULSE_INTERNAL", "1");