openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/libgpg-error/1.36-r0/libgpg-error-1.36/src/spawn-posix.c
gpg_err_code_t _gpgrt_spawn_process(const char* pgmname, const char* argv[],
                                    int* except, void (*preexec)(void),
                                    unsigned int flags, estream_t* r_infp,
                                    estream_t* r_outfp, estream_t* r_errfp,
                                    pid_t* pid)
{
    gpg_error_t err;
    int inpipe[2] = {-1, -1};
    int outpipe[2] = {-1, -1};
    int errpipe[2] = {-1, -1};
    estream_t infp = NULL;
    estream_t outfp = NULL;
    estream_t errfp = NULL;
    int nonblock = !!(flags & GPGRT_SPAWN_NONBLOCK);

    if (r_infp)
        *r_infp = NULL;
    if (r_outfp)
        *r_outfp = NULL;
    if (r_errfp)
        *r_errfp = NULL;
    *pid = (pid_t)(-1); /* Always required.  */

    if (r_infp)
    {
        err = _gpgrt_create_outbound_pipe(inpipe, &infp, nonblock);
        if (err)
            return err;
    }

    if (r_outfp)
    {
        err = _gpgrt_create_inbound_pipe(outpipe, &outfp, nonblock);
        if (err)
        {
            if (infp)
                _gpgrt_fclose(infp);
            else if (inpipe[1] != -1)
                close(inpipe[1]);
            if (inpipe[0] != -1)
                close(inpipe[0]);

            return err;
        }
    }

    if (r_errfp)
    {
        err = _gpgrt_create_inbound_pipe(errpipe, &errfp, nonblock);
        if (err)
        {
            if (infp)
                _gpgrt_fclose(infp);
            else if (inpipe[1] != -1)
                close(inpipe[1]);
            if (inpipe[0] != -1)
                close(inpipe[0]);

            if (outfp)
                _gpgrt_fclose(outfp);
            else if (outpipe[0] != -1)
                close(outpipe[0]);
            if (outpipe[1] != -1)
                close(outpipe[1]);

            return err;
        }
    }

    _gpgrt_pre_syscall();
    *pid = fork();
    _gpgrt_post_syscall();
    if (*pid == (pid_t)(-1))
    {
        err = _gpg_err_code_from_syserror();
        _gpgrt_log_error(_("error forking process: %s\n"), _gpg_strerror(err));

        if (infp)
            _gpgrt_fclose(infp);
        else if (inpipe[1] != -1)
            close(inpipe[1]);
        if (inpipe[0] != -1)
            close(inpipe[0]);

        if (outfp)
            _gpgrt_fclose(outfp);
        else if (outpipe[0] != -1)
            close(outpipe[0]);
        if (outpipe[1] != -1)
            close(outpipe[1]);

        if (errfp)
            _gpgrt_fclose(errfp);
        else if (errpipe[0] != -1)
            close(errpipe[0]);
        if (errpipe[1] != -1)
            close(errpipe[1]);
        return err;
    }

    if (!*pid)
    {
        /* This is the child. */
        /* FIXME: Needs to be done by preexec:
           gcry_control (GCRYCTL_TERM_SECMEM); */
        _gpgrt_fclose(infp);
        _gpgrt_fclose(outfp);
        _gpgrt_fclose(errfp);
        do_exec(pgmname, argv, inpipe[0], outpipe[1], errpipe[1], except,
                preexec);
        /*NOTREACHED*/
    }

    /* This is the parent. */
    if (inpipe[0] != -1)
        close(inpipe[0]);
    if (outpipe[1] != -1)
        close(outpipe[1]);
    if (errpipe[1] != -1)
        close(errpipe[1]);

    if (r_infp)
        *r_infp = infp;
    if (r_outfp)
        *r_outfp = outfp;
    if (r_errfp)
        *r_errfp = errfp;

    return 0;
}
/* Fork and exec the PGMNAME, see gpgrt-int.h for details.  */
Fork and exec the PGMNAME, see gpgrt-int.h for details.
Fork and exec the PGMNAME see gpgrt - int . h for details .
gpg_err_code_t _gpgrt_spawn_process(const char* pgmname, const char* argv[],
                                    int* except, void (*preexec)(void),
                                    unsigned int flags, estream_t* r_infp,
                                    estream_t* r_outfp, estream_t* r_errfp,
                                    pid_t* pid)
{
    gpg_error_t err;
    int inpipe[2] = {-1, -1};
    int outpipe[2] = {-1, -1};
    int errpipe[2] = {-1, -1};
    estream_t infp = NULL;
    estream_t outfp = NULL;
    estream_t errfp = NULL;
    int nonblock = !!(flags & GPGRT_SPAWN_NONBLOCK);
    if (r_infp)
        *r_infp = NULL;
    if (r_outfp)
        *r_outfp = NULL;
    if (r_errfp)
        *r_errfp = NULL;
    *pid = (pid_t)(-1); 
    if (r_infp)
    {
        err = _gpgrt_create_outbound_pipe(inpipe, &infp, nonblock);
        if (err)
            return err;
    }
    if (r_outfp)
    {
        err = _gpgrt_create_inbound_pipe(outpipe, &outfp, nonblock);
        if (err)
        {
            if (infp)
                _gpgrt_fclose(infp);
            else if (inpipe[1] != -1)
                close(inpipe[1]);
            if (inpipe[0] != -1)
                close(inpipe[0]);
            return err;
        }
    }
    if (r_errfp)
    {
        err = _gpgrt_create_inbound_pipe(errpipe, &errfp, nonblock);
        if (err)
        {
            if (infp)
                _gpgrt_fclose(infp);
            else if (inpipe[1] != -1)
                close(inpipe[1]);
            if (inpipe[0] != -1)
                close(inpipe[0]);
            if (outfp)
                _gpgrt_fclose(outfp);
            else if (outpipe[0] != -1)
                close(outpipe[0]);
            if (outpipe[1] != -1)
                close(outpipe[1]);
            return err;
        }
    }
    _gpgrt_pre_syscall();
    *pid = fork();
    _gpgrt_post_syscall();
    if (*pid == (pid_t)(-1))
    {
        err = _gpg_err_code_from_syserror();
        _gpgrt_log_error(_("error forking process: %s\n"), _gpg_strerror(err));
        if (infp)
            _gpgrt_fclose(infp);
        else if (inpipe[1] != -1)
            close(inpipe[1]);
        if (inpipe[0] != -1)
            close(inpipe[0]);
        if (outfp)
            _gpgrt_fclose(outfp);
        else if (outpipe[0] != -1)
            close(outpipe[0]);
        if (outpipe[1] != -1)
            close(outpipe[1]);
        if (errfp)
            _gpgrt_fclose(errfp);
        else if (errpipe[0] != -1)
            close(errpipe[0]);
        if (errpipe[1] != -1)
            close(errpipe[1]);
        return err;
    }
    if (!*pid)
    {
        _gpgrt_fclose(infp);
        _gpgrt_fclose(outfp);
        _gpgrt_fclose(errfp);
        do_exec(pgmname, argv, inpipe[0], outpipe[1], errpipe[1], except,
                preexec);
    }
    if (inpipe[0] != -1)
        close(inpipe[0]);
    if (outpipe[1] != -1)
        close(outpipe[1]);
    if (errpipe[1] != -1)
        close(errpipe[1]);
    if (r_infp)
        *r_infp = infp;
    if (r_outfp)
        *r_outfp = outfp;
    if (r_errfp)
        *r_errfp = errfp;
    return 0;
}
gpg_err_code_t _gpgrt_spawn_process ( const char * pgmname , const char * argv [ ] , int * except , void ( * preexec ) ( void ) , unsigned int flags , estream_t * r_infp , estream_t * r_outfp , estream_t * r_errfp , pid_t * pid ) { gpg_error_t err ; int inpipe [ 2 ] = { -1 , -1 } ; int outpipe [ 2 ] = { -1 , -1 } ; int errpipe [ 2 ] = { -1 , -1 } ; estream_t infp = NULL ; estream_t outfp = NULL ; estream_t errfp = NULL ; int nonblock = ! ! ( flags & GPGRT_SPAWN_NONBLOCK ) ; if ( r_infp ) * r_infp = NULL ; if ( r_outfp ) * r_outfp = NULL ; if ( r_errfp ) * r_errfp = NULL ; * pid = ( pid_t ) ( -1 ) ; if ( r_infp ) { err = _gpgrt_create_outbound_pipe ( inpipe , & infp , nonblock ) ; if ( err ) return err ; } if ( r_outfp ) { err = _gpgrt_create_inbound_pipe ( outpipe , & outfp , nonblock ) ; if ( err ) { if ( infp ) _gpgrt_fclose ( infp ) ; else if ( inpipe [ 1 ] != -1 ) close ( inpipe [ 1 ] ) ; if ( inpipe [ 0 ] != -1 ) close ( inpipe [ 0 ] ) ; return err ; } } if ( r_errfp ) { err = _gpgrt_create_inbound_pipe ( errpipe , & errfp , nonblock ) ; if ( err ) { if ( infp ) _gpgrt_fclose ( infp ) ; else if ( inpipe [ 1 ] != -1 ) close ( inpipe [ 1 ] ) ; if ( inpipe [ 0 ] != -1 ) close ( inpipe [ 0 ] ) ; if ( outfp ) _gpgrt_fclose ( outfp ) ; else if ( outpipe [ 0 ] != -1 ) close ( outpipe [ 0 ] ) ; if ( outpipe [ 1 ] != -1 ) close ( outpipe [ 1 ] ) ; return err ; } } _gpgrt_pre_syscall ( ) ; * pid = fork ( ) ; _gpgrt_post_syscall ( ) ; if ( * pid == ( pid_t ) ( -1 ) ) { err = _gpg_err_code_from_syserror ( ) ; _gpgrt_log_error ( _ ( " \n " ) , _gpg_strerror ( err ) ) ; if ( infp ) _gpgrt_fclose ( infp ) ; else if ( inpipe [ 1 ] != -1 ) close ( inpipe [ 1 ] ) ; if ( inpipe [ 0 ] != -1 ) close ( inpipe [ 0 ] ) ; if ( outfp ) _gpgrt_fclose ( outfp ) ; else if ( outpipe [ 0 ] != -1 ) close ( outpipe [ 0 ] ) ; if ( outpipe [ 1 ] != -1 ) close ( outpipe [ 1 ] ) ; if ( errfp ) _gpgrt_fclose ( errfp ) ; else if ( errpipe [ 0 ] != -1 ) close ( errpipe [ 0 ] ) ; if ( errpipe [ 1 ] != -1 ) close ( errpipe [ 1 ] ) ; return err ; } if ( ! * pid ) { _gpgrt_fclose ( infp ) ; _gpgrt_fclose ( outfp ) ; _gpgrt_fclose ( errfp ) ; do_exec ( pgmname , argv , inpipe [ 0 ] , outpipe [ 1 ] , errpipe [ 1 ] , except , preexec ) ; } if ( inpipe [ 0 ] != -1 ) close ( inpipe [ 0 ] ) ; if ( outpipe [ 1 ] != -1 ) close ( outpipe [ 1 ] ) ; if ( errpipe [ 1 ] != -1 ) close ( errpipe [ 1 ] ) ; if ( r_infp ) * r_infp = infp ; if ( r_outfp ) * r_outfp = outfp ; if ( r_errfp ) * r_errfp = errfp ; return 0 ; }
Fork and exec the PGMNAME, see gpgrt-int.h for details.
Fork and exec the PGMNAME see gpgrt - int . h for details .
/* Always required.  */ /* This is the child. */ /* FIXME: Needs to be done by preexec:
           gcry_control (GCRYCTL_TERM_SECMEM); */ /*NOTREACHED*/ /* This is the parent. */