Ejemplo n.º 1
0
static pid_t CreatePipeAndFork(char *type, int *pd)
{
    pid_t pid = -1;

    if (((*type != 'r') && (*type != 'w')) || (type[1] != '\0'))
    {
        errno = EINVAL;
        return -1;
    }

    if (!InitChildrenFD())
    {
        return -1;
    }

    if (pipe(pd) < 0)           /* Create a pair of descriptors to this process */
    {
        return -1;
    }

    if ((pid = fork()) == -1)
    {
        close(pd[0]);
        close(pd[1]);
        return -1;
    }

    signal(SIGCHLD, SIG_DFL);

    ALARM_PID = (pid != 0 ? pid : -1);

    return pid;
}
Ejemplo n.º 2
0
static pid_t CreatePipeAndFork(const char *type, int *pd)
{
    pid_t pid = -1;

    if (!PipeTypeIsOk(type))
    {
        errno = EINVAL;
        return -1;
    }

    if (!InitChildrenFD())
    {
        return -1;
    }

    if (pipe(pd) < 0)           /* Create a pair of descriptors to this process */
    {
        return -1;
    }

    if ((pid = fork()) == -1)
    {
        close(pd[0]);
        close(pd[1]);
        return -1;
    }

    signal(SIGCHLD, SIG_DFL);

    // Redmine #2971: reset SIGPIPE signal handler to have a sane behavior of piped commands within child
    if (pid == 0)
    {
        signal(SIGPIPE, SIG_DFL);
    }

    ALARM_PID = (pid != 0 ? pid : -1);

    return pid;
}