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
static void do_exec(const char* pgmname, const char* argv[], int fd_in,
                    int fd_out, int fd_err, int* except, void (*preexec)(void))
{
    char** arg_list;
    int i, j;
    int fds[3];

    fds[0] = fd_in;
    fds[1] = fd_out;
    fds[2] = fd_err;

    /* Create the command line argument array.  */
    i = 0;
    if (argv)
        while (argv[i])
            i++;
    arg_list = xtrycalloc(i + 2, sizeof *arg_list);
    if (!arg_list)
        out_of_core(__LINE__);
    arg_list[0] = strrchr(pgmname, '/');
    if (arg_list[0])
        arg_list[0]++;
    else
    {
        arg_list[0] = xtrystrdup(pgmname);
        if (!arg_list[0])
            out_of_core(__LINE__);
    }
    if (argv)
        for (i = 0, j = 1; argv[i]; i++, j++)
            arg_list[j] = (char*)argv[i];

    /* Assign /dev/null to unused FDs. */
    for (i = 0; i <= 2; i++)
    {
        if (fds[i] == -1)
        {
            fds[i] = open("/dev/null", i ? O_WRONLY : O_RDONLY);
            if (fds[i] == -1)
                _gpgrt_log_fatal("failed to open '%s': %s\n", "/dev/null",
                                 strerror(errno));
        }
    }

    /* Connect the standard files.  */
    for (i = 0; i <= 2; i++)
    {
        if (fds[i] != i && dup2(fds[i], i) == -1)
            _gpgrt_log_fatal("dup2 std%s failed: %s\n",
                             i == 0 ? "in" : i == 1 ? "out" : "err",
                             strerror(errno));
    }

    /* Close all other files. */
    close_all_fds(3, except);

    if (preexec)
        preexec();
    execv(pgmname, arg_list);
    /* No way to print anything, as we have may have closed all streams. */
    _exit(127);
}
/* The exec core used right after the fork.  This will never return.  */
The exec core used right after the fork.  This will never return.
The exec core used right after the fork . This will never return .
static void do_exec(const char* pgmname, const char* argv[], int fd_in,
                    int fd_out, int fd_err, int* except, void (*preexec)(void))
{
    char** arg_list;
    int i, j;
    int fds[3];
    fds[0] = fd_in;
    fds[1] = fd_out;
    fds[2] = fd_err;
    i = 0;
    if (argv)
        while (argv[i])
            i++;
    arg_list = xtrycalloc(i + 2, sizeof *arg_list);
    if (!arg_list)
        out_of_core(__LINE__);
    arg_list[0] = strrchr(pgmname, '/');
    if (arg_list[0])
        arg_list[0]++;
    else
    {
        arg_list[0] = xtrystrdup(pgmname);
        if (!arg_list[0])
            out_of_core(__LINE__);
    }
    if (argv)
        for (i = 0, j = 1; argv[i]; i++, j++)
            arg_list[j] = (char*)argv[i];
    for (i = 0; i <= 2; i++)
    {
        if (fds[i] == -1)
        {
            fds[i] = open("/dev/null", i ? O_WRONLY : O_RDONLY);
            if (fds[i] == -1)
                _gpgrt_log_fatal("failed to open '%s': %s\n", "/dev/null",
                                 strerror(errno));
        }
    }
    for (i = 0; i <= 2; i++)
    {
        if (fds[i] != i && dup2(fds[i], i) == -1)
            _gpgrt_log_fatal("dup2 std%s failed: %s\n",
                             i == 0 ? "in" : i == 1 ? "out" : "err",
                             strerror(errno));
    }
    close_all_fds(3, except);
    if (preexec)
        preexec();
    execv(pgmname, arg_list);
    _exit(127);
}
static void do_exec ( const char * pgmname , const char * argv [ ] , int fd_in , int fd_out , int fd_err , int * except , void ( * preexec ) ( void ) ) { char * * arg_list ; int i , j ; int fds [ 3 ] ; fds [ 0 ] = fd_in ; fds [ 1 ] = fd_out ; fds [ 2 ] = fd_err ; i = 0 ; if ( argv ) while ( argv [ i ] ) i ++ ; arg_list = xtrycalloc ( i + 2 , sizeof * arg_list ) ; if ( ! arg_list ) out_of_core ( __LINE__ ) ; arg_list [ 0 ] = strrchr ( pgmname , ' ' ) ; if ( arg_list [ 0 ] ) arg_list [ 0 ] ++ ; else { arg_list [ 0 ] = xtrystrdup ( pgmname ) ; if ( ! arg_list [ 0 ] ) out_of_core ( __LINE__ ) ; } if ( argv ) for ( i = 0 , j = 1 ; argv [ i ] ; i ++ , j ++ ) arg_list [ j ] = ( char * ) argv [ i ] ; for ( i = 0 ; i <= 2 ; i ++ ) { if ( fds [ i ] == -1 ) { fds [ i ] = open ( " " , i ? O_WRONLY : O_RDONLY ) ; if ( fds [ i ] == -1 ) _gpgrt_log_fatal ( " \n " , " " , strerror ( errno ) ) ; } } for ( i = 0 ; i <= 2 ; i ++ ) { if ( fds [ i ] != i && dup2 ( fds [ i ] , i ) == -1 ) _gpgrt_log_fatal ( " \n " , i == 0 ? " " : i == 1 ? " " : " " , strerror ( errno ) ) ; } close_all_fds ( 3 , except ) ; if ( preexec ) preexec ( ) ; execv ( pgmname , arg_list ) ; _exit ( 127 ) ; }
The exec core used right after the fork.
The exec core used right after the fork .
/* Create the command line argument array.  */ /* Assign /dev/null to unused FDs. */ /* Connect the standard files.  */ /* Close all other files. */ /* No way to print anything, as we have may have closed all streams. */