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_detached(const char* pgmname,
                                             const char* argv[],
                                             const char* envp[])
{
    gpg_err_code_t ec;
    pid_t pid;
    int i;

    /* FIXME: Is this GnuPG specific or should we keep it.  */
    if (getuid() != geteuid())
        return GPG_ERR_BUG;

    if (access(pgmname, X_OK))
        return _gpg_err_code_from_syserror();

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

    if (!pid)
    {
        pid_t pid2;

        /* gcry_control (GCRYCTL_TERM_SECMEM); */
        if (setsid() == -1 || chdir("/"))
            _exit(1);

        pid2 = fork(); /* Double fork to let init take over the new child. */
        if (pid2 == (pid_t)(-1))
            _exit(1);
        if (pid2)
            _exit(0); /* Let the parent exit immediately. */

        for (i = 0; envp && envp[i]; i++)
        {
            char* p = xtrystrdup(envp[i]);
            if (!p)
                out_of_core(__LINE__);
            putenv(p);
        }

        do_exec(pgmname, argv, -1, -1, -1, NULL, NULL);
        /*NOTREACHED*/
    }

    _gpgrt_pre_syscall();
    if (waitpid(pid, NULL, 0) == -1)
    {
        _gpgrt_post_syscall();
        ec = _gpg_err_code_from_syserror();
        _gpgrt_log_error("waitpid failed in gpgrt_spawn_process_detached: %s",
                         _gpg_strerror(ec));
        return ec;
    }
    else
        _gpgrt_post_syscall();

    return 0;
}
/* See gpgrt-int.h for a description.  FIXME: We should add a prexec
 * callback. */
See gpgrt-int.h for a description.  FIXME: We should add a prexec
callback.
See gpgrt - int . h for a description . FIXME : We should add a prexec callback .
gpg_err_code_t _gpgrt_spawn_process_detached(const char* pgmname,
                                             const char* argv[],
                                             const char* envp[])
{
    gpg_err_code_t ec;
    pid_t pid;
    int i;
    if (getuid() != geteuid())
        return GPG_ERR_BUG;
    if (access(pgmname, X_OK))
        return _gpg_err_code_from_syserror();
    _gpgrt_pre_syscall();
    pid = fork();
    _gpgrt_post_syscall();
    if (pid == (pid_t)(-1))
    {
        ec = _gpg_err_code_from_syserror();
        _gpgrt_log_error(_("error forking process: %s\n"), _gpg_strerror(ec));
        return ec;
    }
    if (!pid)
    {
        pid_t pid2;
        if (setsid() == -1 || chdir("/"))
            _exit(1);
        pid2 = fork(); 
        if (pid2 == (pid_t)(-1))
            _exit(1);
        if (pid2)
            _exit(0); 
        for (i = 0; envp && envp[i]; i++)
        {
            char* p = xtrystrdup(envp[i]);
            if (!p)
                out_of_core(__LINE__);
            putenv(p);
        }
        do_exec(pgmname, argv, -1, -1, -1, NULL, NULL);
    }
    _gpgrt_pre_syscall();
    if (waitpid(pid, NULL, 0) == -1)
    {
        _gpgrt_post_syscall();
        ec = _gpg_err_code_from_syserror();
        _gpgrt_log_error("waitpid failed in gpgrt_spawn_process_detached: %s",
                         _gpg_strerror(ec));
        return ec;
    }
    else
        _gpgrt_post_syscall();
    return 0;
}
gpg_err_code_t _gpgrt_spawn_process_detached ( const char * pgmname , const char * argv [ ] , const char * envp [ ] ) { gpg_err_code_t ec ; pid_t pid ; int i ; if ( getuid ( ) != geteuid ( ) ) return GPG_ERR_BUG ; if ( access ( pgmname , X_OK ) ) return _gpg_err_code_from_syserror ( ) ; _gpgrt_pre_syscall ( ) ; pid = fork ( ) ; _gpgrt_post_syscall ( ) ; if ( pid == ( pid_t ) ( -1 ) ) { ec = _gpg_err_code_from_syserror ( ) ; _gpgrt_log_error ( _ ( " \n " ) , _gpg_strerror ( ec ) ) ; return ec ; } if ( ! pid ) { pid_t pid2 ; if ( setsid ( ) == -1 || chdir ( " " ) ) _exit ( 1 ) ; pid2 = fork ( ) ; if ( pid2 == ( pid_t ) ( -1 ) ) _exit ( 1 ) ; if ( pid2 ) _exit ( 0 ) ; for ( i = 0 ; envp && envp [ i ] ; i ++ ) { char * p = xtrystrdup ( envp [ i ] ) ; if ( ! p ) out_of_core ( __LINE__ ) ; putenv ( p ) ; } do_exec ( pgmname , argv , -1 , -1 , -1 , NULL , NULL ) ; } _gpgrt_pre_syscall ( ) ; if ( waitpid ( pid , NULL , 0 ) == -1 ) { _gpgrt_post_syscall ( ) ; ec = _gpg_err_code_from_syserror ( ) ; _gpgrt_log_error ( " " , _gpg_strerror ( ec ) ) ; return ec ; } else _gpgrt_post_syscall ( ) ; return 0 ; }
See gpgrt-int.h for a description.
See gpgrt - int . h for a description .
/* FIXME: Is this GnuPG specific or should we keep it.  */ /* gcry_control (GCRYCTL_TERM_SECMEM); */ /* Double fork to let init take over the new child. */ /* Let the parent exit immediately. */ /*NOTREACHED*/