src/mca/odls/default/odls_default_module.c
/**
 *  Fork/exec the specified processes
 */
Fork/exec the specified processes
Fork / exec the specified processes
static int odls_default_fork_local_proc(void *cdptr)
{
    prte_odls_spawn_caddy_t *cd = (prte_odls_spawn_caddy_t *) cdptr;
    int p[2];
    pid_t pid;
    prte_proc_t *child = cd->child;
    if (pipe(p) < 0) {
        PRTE_ERROR_LOG(PRTE_ERR_SYS_LIMITS_PIPES);
        if (NULL != child) {
            child->state = PRTE_PROC_STATE_FAILED_TO_START;
            child->exit_code = PRTE_ERR_SYS_LIMITS_PIPES;
        }
        return PRTE_ERR_SYS_LIMITS_PIPES;
    }
    pid = fork();
    if (NULL != child) {
        child->pid = pid;
    }
    if (pid < 0) {
        PRTE_ERROR_LOG(PRTE_ERR_SYS_LIMITS_CHILDREN);
        if (NULL != child) {
            child->state = PRTE_PROC_STATE_FAILED_TO_START;
            child->exit_code = PRTE_ERR_SYS_LIMITS_CHILDREN;
        }
        return PRTE_ERR_SYS_LIMITS_CHILDREN;
    }
    if (pid == 0) {
        close(p[0]);
        do_child(cd, p[1]);
    }
    close(p[1]);
    return do_parent(cd, p[0]);
}
static int odls_default_fork_local_proc ( void * cdptr ) { prte_odls_spawn_caddy_t * cd = ( prte_odls_spawn_caddy_t * ) cdptr ; int p [ 2 ] ; pid_t pid ; prte_proc_t * child = cd -> child ; if ( pipe ( p ) < 0 ) { PRTE_ERROR_LOG ( PRTE_ERR_SYS_LIMITS_PIPES ) ; if ( NULL != child ) { child -> state = PRTE_PROC_STATE_FAILED_TO_START ; child -> exit_code = PRTE_ERR_SYS_LIMITS_PIPES ; } return PRTE_ERR_SYS_LIMITS_PIPES ; } pid = fork ( ) ; if ( NULL != child ) { child -> pid = pid ; } if ( pid < 0 ) { PRTE_ERROR_LOG ( PRTE_ERR_SYS_LIMITS_CHILDREN ) ; if ( NULL != child ) { child -> state = PRTE_PROC_STATE_FAILED_TO_START ; child -> exit_code = PRTE_ERR_SYS_LIMITS_CHILDREN ; } return PRTE_ERR_SYS_LIMITS_CHILDREN ; } if ( pid == 0 ) { close ( p [ 0 ] ) ; do_child ( cd , p [ 1 ] ) ; } close ( p [ 1 ] ) ; return do_parent ( cd , p [ 0 ] ) ; }
Fork/exec the specified processes
Fork / exec the specified processes
/* A pipe is used to communicate between the parent and child to
       indicate whether the exec ultimately succeeded or failed.  The
       child sets the pipe to be close-on-exec; the child only ever
       writes anything to the pipe if there is an error (e.g.,
       executable not found, exec() fails, etc.).  The parent does a
       blocking read on the pipe; if the pipe closed with no data,
       then the exec() succeeded.  If the parent reads something from
       the pipe, then the child was letting us know why it failed. */ /* Fork off the child */ /* Does not return */