LCOV - code coverage report
Current view: top level - pulsecore - start-child.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 0 33 0.0 %
Date: 2012-07-17 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 22 0.0 %

           Branch data     Line data    Source code
       1                 :            : /***
       2                 :            :   This file is part of PulseAudio.
       3                 :            : 
       4                 :            :   Copyright 2007 Lennart Poettering
       5                 :            : 
       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.
      10                 :            : 
      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.
      15                 :            : 
      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
      19                 :            :   USA.
      20                 :            : ***/
      21                 :            : 
      22                 :            : #ifdef HAVE_CONFIG_H
      23                 :            : #include <config.h>
      24                 :            : #endif
      25                 :            : 
      26                 :            : #include <errno.h>
      27                 :            : #include <stdio.h>
      28                 :            : #include <sys/types.h>
      29                 :            : #include <dirent.h>
      30                 :            : #include <unistd.h>
      31                 :            : #include <fcntl.h>
      32                 :            : #include <signal.h>
      33                 :            : 
      34                 :            : #ifdef HAVE_SYS_PRCTL_H
      35                 :            : #include <sys/prctl.h>
      36                 :            : #endif
      37                 :            : #ifdef HAVE_SYS_RESOURCE_H
      38                 :            : #include <sys/resource.h>
      39                 :            : #endif
      40                 :            : 
      41                 :            : #include <pulsecore/core-util.h>
      42                 :            : #include <pulsecore/core-error.h>
      43                 :            : #include <pulsecore/pipe.h>
      44                 :            : 
      45                 :            : #include "start-child.h"
      46                 :            : 
      47                 :          0 : int pa_start_child_for_read(const char *name, const char *argv1, pid_t *pid) {
      48                 :            : #ifdef HAVE_FORK
      49                 :            :     pid_t child;
      50                 :          0 :     int pipe_fds[2] = { -1, -1 };
      51                 :            : 
      52         [ #  # ]:          0 :     if (pipe(pipe_fds) < 0) {
      53                 :          0 :         pa_log("pipe() failed: %s", pa_cstrerror(errno));
      54                 :          0 :         goto fail;
      55                 :            :     }
      56                 :            : 
      57         [ #  # ]:          0 :     if ((child = fork()) == (pid_t) -1) {
      58                 :          0 :         pa_log("fork() failed: %s", pa_cstrerror(errno));
      59                 :          0 :         goto fail;
      60                 :            : 
      61         [ #  # ]:          0 :     } else if (child != 0) {
      62                 :            : 
      63                 :            :         /* Parent */
      64         [ #  # ]:          0 :         pa_assert_se(pa_close(pipe_fds[1]) == 0);
      65                 :            : 
      66         [ #  # ]:          0 :         if (pid)
      67                 :          0 :             *pid = child;
      68                 :            : 
      69                 :          0 :         return pipe_fds[0];
      70                 :            :     } else {
      71                 :            :         /* child */
      72                 :            : 
      73                 :          0 :         pa_reset_personality();
      74                 :            : 
      75         [ #  # ]:          0 :         pa_assert_se(pa_close(pipe_fds[0]) == 0);
      76         [ #  # ]:          0 :         pa_assert_se(dup2(pipe_fds[1], STDOUT_FILENO) == STDOUT_FILENO);
      77                 :            : 
      78         [ #  # ]:          0 :         if (pipe_fds[1] != STDOUT_FILENO)
      79         [ #  # ]:          0 :             pa_assert_se(pa_close(pipe_fds[1]) == 0);
      80                 :            : 
      81                 :          0 :         pa_close(STDIN_FILENO);
      82         [ #  # ]:          0 :         pa_assert_se(open("/dev/null", O_RDONLY) == STDIN_FILENO);
      83                 :            : 
      84                 :          0 :         pa_close(STDERR_FILENO);
      85         [ #  # ]:          0 :         pa_assert_se(open("/dev/null", O_WRONLY) == STDERR_FILENO);
      86                 :            : 
      87                 :          0 :         pa_close_all(-1);
      88                 :          0 :         pa_reset_sigs(-1);
      89                 :          0 :         pa_unblock_sigs(-1);
      90                 :          0 :         pa_reset_priority();
      91                 :          0 :         pa_unset_env_recorded();
      92                 :            : 
      93                 :            :         /* Make sure our children are not influenced by the
      94                 :            :          * LD_BIND_NOW we set for ourselves. */
      95                 :          0 :         unsetenv("LD_BIND_NOW");
      96                 :            : 
      97                 :            : #ifdef PR_SET_PDEATHSIG
      98                 :            :         /* On Linux we can use PR_SET_PDEATHSIG to have the helper
      99                 :            :         process killed when the daemon dies abnormally. On non-Linux
     100                 :            :         machines the client will die as soon as it writes data to
     101                 :            :         stdout again (SIGPIPE) */
     102                 :            : 
     103                 :          0 :         prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
     104                 :            : #endif
     105                 :            : 
     106                 :          0 :         execl(name, name, argv1, NULL);
     107                 :          0 :         _exit(1);
     108                 :            :     }
     109                 :            : 
     110                 :            : fail:
     111                 :          0 :     pa_close_pipe(pipe_fds);
     112                 :            : #endif /* HAVE_FORK */
     113                 :            : 
     114                 :          0 :     return -1;
     115                 :            : }

Generated by: LCOV version 1.9