2 This file is part of PulseAudio.
4 Copyright 2007 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <sys/types.h>
34 #ifdef HAVE_SYS_PRCTL_H
35 #include <sys/prctl.h>
37 #ifdef HAVE_SYS_RESOURCE_H
38 #include <sys/resource.h>
41 #include <pulsecore/core-util.h>
42 #include <pulsecore/core-error.h>
44 #include "start-child.h"
46 int pa_start_child_for_read(const char *name, const char *argv1, pid_t *pid) {
48 int pipe_fds[2] = { -1, -1 };
50 if (pipe(pipe_fds) < 0) {
51 pa_log("pipe() failed: %s", pa_cstrerror(errno));
55 if ((child = fork()) == (pid_t) -1) {
56 pa_log("fork() failed: %s", pa_cstrerror(errno));
59 } else if (child != 0) {
62 pa_assert_se(pa_close(pipe_fds[1]) == 0);
73 pa_assert_se(pa_close(pipe_fds[0]) == 0);
74 pa_assert_se(dup2(pipe_fds[1], 1) == 1);
77 pa_assert_se(pa_close(pipe_fds[1]) == 0);
80 pa_assert_se(open("/dev/null", O_RDONLY) == 0);
83 pa_assert_se(open("/dev/null", O_WRONLY) == 2);
89 #ifdef PR_SET_PDEATHSIG
90 /* On Linux we can use PR_SET_PDEATHSIG to have the helper
91 process killed when the daemon dies abnormally. On non-Linux
92 machines the client will die as soon as it writes data to
93 stdout again (SIGPIPE) */
95 prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
98 execl(name, name, argv1, NULL);
103 pa_close_pipe(pipe_fds);