]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/start-child.c
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / start-child.c
index 1661383d0768651effe9b36ef387f511569743b5..7f55d4e297efa7a3c40e662dbe3b6e0ecb9be9e9 100644 (file)
 
 #include <pulsecore/core-util.h>
 #include <pulsecore/core-error.h>
+#include <pulsecore/pipe.h>
 
 #include "start-child.h"
 
 int pa_start_child_for_read(const char *name, const char *argv1, pid_t *pid) {
+#ifdef HAVE_FORK
     pid_t child;
     int pipe_fds[2] = { -1, -1 };
 
@@ -66,69 +68,31 @@ int pa_start_child_for_read(const char *name, const char *argv1, pid_t *pid) {
 
         return pipe_fds[0];
     } else {
-#ifdef __linux__
-        DIR* d;
-#endif
-        int max_fd, i;
-
         /* child */
 
-        pa_reset_priority();
+        pa_reset_personality();
 
         pa_assert_se(pa_close(pipe_fds[0]) == 0);
-        pa_assert_se(dup2(pipe_fds[1], 1) == 1);
+        pa_assert_se(dup2(pipe_fds[1], STDOUT_FILENO) == STDOUT_FILENO);
 
-        if (pipe_fds[1] != 1)
+        if (pipe_fds[1] != STDOUT_FILENO)
             pa_assert_se(pa_close(pipe_fds[1]) == 0);
 
-        pa_close(0);
-        pa_assert_se(open("/dev/null", O_RDONLY) == 0);
-
-        pa_close(2);
-        pa_assert_se(open("/dev/null", O_WRONLY) == 2);
-
-#ifdef __linux__
-
-        if ((d = opendir("/proc/self/fd/"))) {
+        pa_close(STDIN_FILENO);
+        pa_assert_se(open("/dev/null", O_RDONLY) == STDIN_FILENO);
 
-            struct dirent *de;
+        pa_close(STDERR_FILENO);
+        pa_assert_se(open("/dev/null", O_WRONLY) == STDERR_FILENO);
 
-            while ((de = readdir(d))) {
-                char *e = NULL;
-                int fd;
-
-                if (de->d_name[0] == '.')
-                    continue;
-
-                errno = 0;
-                fd = strtol(de->d_name, &e, 10);
-                pa_assert(errno == 0 && e && *e == 0);
-
-                if (fd >= 3 && dirfd(d) != fd)
-                    pa_close(fd);
-            }
-
-            closedir(d);
-        } else {
-
-#endif
-
-            max_fd = 1024;
-
-#ifdef HAVE_SYS_RESOURCE_H
-            {
-                struct rlimit r;
-                if (getrlimit(RLIMIT_NOFILE, &r) == 0)
-                    max_fd = r.rlim_max;
-            }
-#endif
+        pa_close_all(-1);
+        pa_reset_sigs(-1);
+        pa_unblock_sigs(-1);
+        pa_reset_priority();
+        pa_unset_env_recorded();
 
-            for (i = 3; i < max_fd; i++)
-                pa_close(i);
-
-#ifdef __linux__
-        }
-#endif
+        /* Make sure our children are not influenced by the
+         * LD_BIND_NOW we set for ourselves. */
+        unsetenv("LD_BIND_NOW");
 
 #ifdef PR_SET_PDEATHSIG
         /* On Linux we can use PR_SET_PDEATHSIG to have the helper
@@ -139,22 +103,13 @@ int pa_start_child_for_read(const char *name, const char *argv1, pid_t *pid) {
         prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
 #endif
 
-#ifdef SIGPIPE
-        /* Make sure that SIGPIPE kills the child process */
-        signal(SIGPIPE, SIG_DFL);
-#endif
-
-#ifdef SIGTERM
-        /* Make sure that SIGTERM kills the child process */
-        signal(SIGTERM, SIG_DFL);
-#endif
-
         execl(name, name, argv1, NULL);
         _exit(1);
     }
 
 fail:
     pa_close_pipe(pipe_fds);
+#endif /* HAVE_FORK */
 
     return -1;
 }