- pa_module_unload_request(u->module);
- }
-}
-
-static int start_client(const char *n, pid_t *pid) {
- pid_t child;
- int pipe_fds[2] = { -1, -1 };
-
- if (pipe(pipe_fds) < 0) {
- pa_log("pipe() failed: %s", pa_cstrerror(errno));
- goto fail;
- }
-
- if ((child = fork()) == (pid_t) -1) {
- pa_log("fork() failed: %s", pa_cstrerror(errno));
- goto fail;
- } else if (child != 0) {
-
- /* Parent */
- close(pipe_fds[1]);
-
- if (pid)
- *pid = child;
-
- return pipe_fds[0];
- } else {
- int max_fd, i;
-
- /* child */
-
- close(pipe_fds[0]);
- dup2(pipe_fds[1], 1);
-
- if (pipe_fds[1] != 1)
- close(pipe_fds[1]);
-
- close(0);
- open("/dev/null", O_RDONLY);
-
- close(2);
- open("/dev/null", O_WRONLY);
-
- max_fd = 1024;
-
-#ifdef HAVE_SYS_RESOURCE_H
- {
- struct rlimit r;
- if (getrlimit(RLIMIT_NOFILE, &r) == 0)
- max_fd = r.rlim_max;
- }
-#endif
-
- for (i = 3; i < max_fd; i++)
- close(i);
-
-#ifdef PR_SET_PDEATHSIG
- /* On Linux we can use PR_SET_PDEATHSIG to have the helper
- process killed when the daemon dies abnormally. On non-Linux
- machines the client will die as soon as it writes data to
- stdout again (SIGPIPE) */
-
- prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
-#endif
-
-#ifdef SIGPIPE
- /* Make sure that SIGPIPE kills the child process */
- signal(SIGPIPE, SIG_DFL);
-#endif
-
- execl(n, n, NULL);
- _exit(1);