]>
code.delx.au - pulseaudio/blob - src/pulsecore/start-child.c
4 This file is part of PulseAudio.
6 Copyright 2007 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation; either version 2.1 of the
11 License, or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <sys/types.h>
36 #ifdef HAVE_SYS_PRCTL_H
37 #include <sys/prctl.h>
39 #ifdef HAVE_SYS_RESOURCE_H
40 #include <sys/resource.h>
43 #include <pulsecore/core-util.h>
44 #include <pulsecore/core-error.h>
46 #include "start-child.h"
48 int pa_start_child_for_read(const char *name
, const char *argv1
, pid_t
*pid
) {
50 int pipe_fds
[2] = { -1, -1 };
52 if (pipe(pipe_fds
) < 0) {
53 pa_log("pipe() failed: %s", pa_cstrerror(errno
));
57 if ((child
= fork()) == (pid_t
) -1) {
58 pa_log("fork() failed: %s", pa_cstrerror(errno
));
61 } else if (child
!= 0) {
64 pa_assert_se(pa_close(pipe_fds
[1]) == 0);
80 pa_assert_se(pa_close(pipe_fds
[0]) == 0);
81 pa_assert_se(dup2(pipe_fds
[1], 1) == 1);
84 pa_assert_se(pa_close(pipe_fds
[1]) == 0);
87 pa_assert_se(open("/dev/null", O_RDONLY
) == 0);
90 pa_assert_se(open("/dev/null", O_WRONLY
) == 2);
94 if ((d
= opendir("/proc/self/fd/"))) {
98 while ((de
= readdir(d
))) {
102 if (de
->d_name
[0] == '.')
106 fd
= strtol(de
->d_name
, &e
, 10);
107 pa_assert(errno
== 0 && e
&& *e
== 0);
109 if (fd
>= 3 && dirfd(d
) != fd
)
120 #ifdef HAVE_SYS_RESOURCE_H
123 if (getrlimit(RLIMIT_NOFILE
, &r
) == 0)
128 for (i
= 3; i
< max_fd
; i
++)
135 #ifdef PR_SET_PDEATHSIG
136 /* On Linux we can use PR_SET_PDEATHSIG to have the helper
137 process killed when the daemon dies abnormally. On non-Linux
138 machines the client will die as soon as it writes data to
139 stdout again (SIGPIPE) */
141 prctl(PR_SET_PDEATHSIG
, SIGTERM
, 0, 0, 0);
145 /* Make sure that SIGPIPE kills the child process */
146 signal(SIGPIPE
, SIG_DFL
);
150 /* Make sure that SIGTERM kills the child process */
151 signal(SIGTERM
, SIG_DFL
);
154 execl(name
, name
, argv1
, NULL
);
159 pa_close_pipe(pipe_fds
);