⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proc.c

📁 apr-1.2.7.tar.gz源码 支持svn的需求
💻 C
📖 第 1 页 / 共 3 页
字号:
            i = 0;            pNext = (apr_wchar_t*)pEnvBlock;            while (env[i]) {                apr_size_t in = strlen(env[i]) + 1;                if ((rv = apr_conv_utf8_to_ucs2(env[i], &in,                                                 pNext, &iEnvBlockLen))                         != APR_SUCCESS) {                    if (attr->errfn) {                        attr->errfn(pool, rv,                                     apr_pstrcat(pool,                                                 "utf8 to ucs2 conversion failed"                                                 " on this string: ", env[i], NULL));                    }                    return rv;                }                pNext = wcschr(pNext, L'\0') + 1;                i++;            }	    if (!i)                *(pNext++) = L'\0';	    *pNext = L'\0';        }#endif /* APR_HAS_UNICODE_FS */#if APR_HAS_ANSI_FS        ELSE_WIN_OS_IS_ANSI        {            char *pNext;            pEnvBlock = (char *)apr_palloc(pool, iEnvBlockLen);                i = 0;            pNext = pEnvBlock;            while (env[i]) {                strcpy(pNext, env[i]);                pNext = strchr(pNext, '\0') + 1;                i++;            }	    if (!i)                *(pNext++) = '\0';	    *pNext = '\0';        }#endif /* APR_HAS_ANSI_FS */    }     new->invoked = cmdline;#if APR_HAS_UNICODE_FS    IF_WIN_OS_IS_UNICODE    {        STARTUPINFOW si;        apr_wchar_t *wprg = NULL;        apr_wchar_t *wcmd = NULL;        apr_wchar_t *wcwd = NULL;        if (progname) {            apr_size_t nprg = strlen(progname) + 1;            apr_size_t nwprg = nprg + 6;            wprg = apr_palloc(pool, nwprg * sizeof(wprg[0]));            if ((rv = apr_conv_utf8_to_ucs2(progname, &nprg, wprg, &nwprg))                   != APR_SUCCESS) {                if (attr->errfn) {                    attr->errfn(pool, rv,                                 apr_pstrcat(pool,                                             "utf8 to ucs2 conversion failed"                                             " on progname: ", progname, NULL));                }                return rv;            }        }        if (cmdline) {            apr_size_t ncmd = strlen(cmdline) + 1;            apr_size_t nwcmd = ncmd;            wcmd = apr_palloc(pool, nwcmd * sizeof(wcmd[0]));            if ((rv = apr_conv_utf8_to_ucs2(cmdline, &ncmd, wcmd, &nwcmd))                    != APR_SUCCESS) {                if (attr->errfn) {                    attr->errfn(pool, rv,                                 apr_pstrcat(pool,                                             "utf8 to ucs2 conversion failed"                                             " on cmdline: ", cmdline, NULL));                }                return rv;            }        }        if (attr->currdir)        {            apr_size_t ncwd = strlen(attr->currdir) + 1;            apr_size_t nwcwd = ncwd;            wcwd = apr_palloc(pool, ncwd * sizeof(wcwd[0]));            if ((rv = apr_conv_utf8_to_ucs2(attr->currdir, &ncwd,                                             wcwd, &nwcwd))                    != APR_SUCCESS) {                if (attr->errfn) {                    attr->errfn(pool, rv,                                 apr_pstrcat(pool,                                             "utf8 to ucs2 conversion failed"                                             " on currdir: ", attr->currdir, NULL));                }                return rv;            }        }        memset(&si, 0, sizeof(si));        si.cb = sizeof(si);        if (attr->detached) {            si.dwFlags |= STARTF_USESHOWWINDOW;            si.wShowWindow = SW_HIDE;        }#ifndef _WIN32_WCE        if ((attr->child_in && attr->child_in->filehand)            || (attr->child_out && attr->child_out->filehand)            || (attr->child_err && attr->child_err->filehand))        {            si.dwFlags |= STARTF_USESTDHANDLES;            si.hStdInput = (attr->child_in)                               ? attr->child_in->filehand                              : INVALID_HANDLE_VALUE;            si.hStdOutput = (attr->child_out)                              ? attr->child_out->filehand                              : INVALID_HANDLE_VALUE;            si.hStdError = (attr->child_err)                              ? attr->child_err->filehand                              : INVALID_HANDLE_VALUE;        }        if (attr->user_token) {            si.lpDesktop = L"Winsta0\\Default";            if (!ImpersonateLoggedOnUser(attr->user_token)) {            /* failed to impersonate the logged user */                rv = apr_get_os_error();                CloseHandle(attr->user_token);                attr->user_token = NULL;                return rv;            }            rv = CreateProcessAsUserW(attr->user_token,                                      wprg, wcmd,                                      attr->sa,                                      NULL,                                      TRUE,                                      dwCreationFlags,                                      pEnvBlock,                                      wcwd,                                      &si, &pi);            RevertToSelf();        }        else {            rv = CreateProcessW(wprg, wcmd,        /* Executable & Command line */                                NULL, NULL,        /* Proc & thread security attributes */                                TRUE,              /* Inherit handles */                                dwCreationFlags,   /* Creation flags */                                pEnvBlock,         /* Environment block */                                wcwd,              /* Current directory name */                                &si, &pi);        }#else        rv = CreateProcessW(wprg, wcmd,        /* Executable & Command line */                            NULL, NULL,        /* Proc & thread security attributes */                            FALSE,             /* must be 0 */                            dwCreationFlags,   /* Creation flags */                            NULL,              /* Environment block must be NULL */                            NULL,              /* Current directory name must be NULL*/                            NULL,              /* STARTUPINFO not supported */                            &pi);#endif    }#endif /* APR_HAS_UNICODE_FS */#if APR_HAS_ANSI_FS    ELSE_WIN_OS_IS_ANSI    {        STARTUPINFOA si;        memset(&si, 0, sizeof(si));        si.cb = sizeof(si);        if (attr->detached) {            si.dwFlags |= STARTF_USESHOWWINDOW;            si.wShowWindow = SW_HIDE;        }        if ((attr->child_in && attr->child_in->filehand)            || (attr->child_out && attr->child_out->filehand)            || (attr->child_err && attr->child_err->filehand))        {            si.dwFlags |= STARTF_USESTDHANDLES;            si.hStdInput = (attr->child_in)                               ? attr->child_in->filehand                              : INVALID_HANDLE_VALUE;            si.hStdOutput = (attr->child_out)                              ? attr->child_out->filehand                              : INVALID_HANDLE_VALUE;            si.hStdError = (attr->child_err)                              ? attr->child_err->filehand                              : INVALID_HANDLE_VALUE;        }        rv = CreateProcessA(progname, cmdline, /* Command line */                            NULL, NULL,        /* Proc & thread security attributes */                            TRUE,              /* Inherit handles */                            dwCreationFlags,   /* Creation flags */                            pEnvBlock,         /* Environment block */                            attr->currdir,     /* Current directory name */                            &si, &pi);    }#endif /* APR_HAS_ANSI_FS */    /* Check CreateProcess result      */    if (!rv)        return apr_get_os_error();    /* XXX Orphaned handle warning - no fix due to broken apr_proc_t api.     */    new->hproc = pi.hProcess;    new->pid = pi.dwProcessId;    if (attr->child_in) {        apr_file_close(attr->child_in);    }    if (attr->child_out) {        apr_file_close(attr->child_out);    }    if (attr->child_err) {        apr_file_close(attr->child_err);    }    CloseHandle(pi.hThread);    return APR_SUCCESS;}APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,                                                  int *exitcode,                                                  apr_exit_why_e *exitwhy,                                                  apr_wait_how_e waithow,                                                  apr_pool_t *p){    /* Unix does apr_proc_wait(proc(-1), exitcode, exitwhy, waithow)     * but Win32's apr_proc_wait won't work that way.  We can either     * register all APR created processes in some sort of AsyncWait     * thread, or simply walk from the global process pool for all      * apr_pool_note_subprocess()es registered with APR.     */    return APR_ENOTIMPL;}static apr_exit_why_e why_from_exit_code(DWORD exit) {    /* See WinNT.h STATUS_ACCESS_VIOLATION and family for how     * this class of failures was determined     */    if (((exit & 0xC0000000) == 0xC0000000)                     && !(exit & 0x3FFF0000))        return APR_PROC_SIGNAL;    else        return APR_PROC_EXIT;    /* ### No way to tell if Dr Watson grabbed a core, AFAICT. */}APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,                                        int *exitcode, apr_exit_why_e *exitwhy,                                        apr_wait_how_e waithow){    DWORD stat;    DWORD time;    if (waithow == APR_WAIT)        time = INFINITE;    else        time = 0;    if ((stat = WaitForSingleObject(proc->hproc, time)) == WAIT_OBJECT_0) {        if (GetExitCodeProcess(proc->hproc, &stat)) {            if (exitcode)                *exitcode = stat;            if (exitwhy)                *exitwhy = why_from_exit_code(stat);            CloseHandle(proc->hproc);            proc->hproc = NULL;            return APR_CHILD_DONE;        }    }    else if (stat == WAIT_TIMEOUT) {        return APR_CHILD_NOTDONE;    }    return apr_get_os_error();}APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize){    return APR_ENOTIMPL;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -