📄 proc.c
字号:
return stat; } stat = make_inheritable_duplicate (child_out, attr->child_out); if (stat == APR_SUCCESS) stat = make_inheritable_duplicate (parent_out, attr->parent_out); return stat;}APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr, apr_file_t *child_err, apr_file_t *parent_err){ apr_status_t stat; if (attr->child_err == NULL && attr->parent_err == NULL) { stat = open_nt_process_pipe(&attr->child_err, &attr->parent_err, APR_FULL_BLOCK, attr->cntxt); if (stat == APR_SUCCESS) stat = make_handle_private(attr->parent_err); if (stat != APR_SUCCESS) return stat; } stat = make_inheritable_duplicate (child_err, attr->child_err); if (stat == APR_SUCCESS) stat = make_inheritable_duplicate (parent_err, attr->parent_err); return stat;}APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr, const char *dir) { char path[MAX_PATH]; int length; if (dir[0] != '\\' && dir[0] != '/' && dir[1] != ':') { length = GetCurrentDirectory(MAX_PATH, path); if (length == 0 || length + strlen(dir) + 1 >= MAX_PATH) return APR_ENOMEM; attr->currdir = apr_pstrcat(attr->cntxt, path, "\\", dir, NULL); } else { attr->currdir = apr_pstrdup(attr->cntxt, dir); } if (attr->currdir) { return APR_SUCCESS; } return APR_ENOMEM;}APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr, apr_cmdtype_e cmd) { attr->cmdtype = cmd; return APR_SUCCESS;}APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int32_t det) { attr->detached = det; return APR_SUCCESS;}/* TODO: * apr_proc_create with APR_SHELLCMD on Win9x won't work due to MS KB: * Q150956 */APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname, const char * const *args, const char * const *env, apr_procattr_t *attr, apr_pool_t *cont){ int i, iEnvBlockLen; char *cmdline; char ppid[20]; char *envstr; char *pEnvBlock, *pNext; PROCESS_INFORMATION pi; new->in = attr->parent_in; new->err = attr->parent_err; new->out = attr->parent_out; attr->si.cb = sizeof(attr->si); if (attr->detached) { /* If we are creating ourselves detached, Then we should hide the * window we are starting in. And we had better redfine our * handles for STDIN, STDOUT, and STDERR. */ attr->si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; attr->si.wShowWindow = SW_HIDE; if (attr->child_in) { attr->si.hStdInput = attr->child_in->filehand; } if (attr->child_out) { attr->si.hStdOutput = attr->child_out->filehand; } if (attr->child_err) { attr->si.hStdError = attr->child_err->filehand; } } if (attr->cmdtype == APR_PROGRAM) { const char *ptr = progname; if (*ptr =='"') { ptr++; } if (*ptr == '\\' || *ptr == '/' || *++ptr == ':') { cmdline = apr_pstrdup(cont, progname); } else if (attr->currdir == NULL) { cmdline = apr_pstrdup(cont, progname); } else { char lastchar = attr->currdir[strlen(attr->currdir)-1]; if ( lastchar == '\\' || lastchar == '/') { cmdline = apr_pstrcat(cont, attr->currdir, progname, NULL); } else { cmdline = apr_pstrcat(cont, attr->currdir, "\\", progname, NULL); } } } else { char * shell_cmd = getenv("COMSPEC"); if (!shell_cmd) shell_cmd = SHELL_PATH; shell_cmd = apr_pstrdup(cont, shell_cmd); cmdline = apr_pstrcat(cont, shell_cmd, " /C ", progname, NULL); } i = 1; while (args && args[i]) { cmdline = apr_pstrcat(cont, cmdline, " ", args[i], NULL); i++; } _itoa(_getpid(), ppid, 10); if (env) { envstr = apr_pstrcat(cont, "parentpid=", ppid, NULL); /* * Win32's CreateProcess call requires that the environment * be passed in an environment block, a null terminated block of * null terminated strings. */ i = 0; iEnvBlockLen = 1; while (env[i]) { iEnvBlockLen += strlen(env[i]) + 1; i++; } pEnvBlock = (char *)apr_pcalloc(cont, iEnvBlockLen + strlen(envstr)); i = 0; pNext = pEnvBlock; while (env[i]) { strcpy(pNext, env[i]); pNext = pNext + strlen(pNext) + 1; i++; } strcpy(pNext, envstr); pNext = pNext + strlen(pNext) + 1; *pNext = '\0'; } else { SetEnvironmentVariable("parentpid", ppid); pEnvBlock = NULL; } if (CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, pEnvBlock, attr->currdir, &attr->si, &pi)) { // TODO: THIS IS BADNESS // The completion of the apr_proc_t type leaves us ill equiped to track both // the pid (Process ID) and handle to the process, which are entirely // different things and each useful in their own rights. // // Signals are broken since the hProcess varies from process to process, // while the true process ID would not. new->pid = (pid_t) pi.hProcess; 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; } return apr_get_os_error();}APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc, apr_wait_how_e wait){ DWORD stat; if (!proc) return APR_ENOPROC; if (wait == APR_WAIT) { if ((stat = WaitForSingleObject((HANDLE)proc->pid, INFINITE)) == WAIT_OBJECT_0) { return APR_CHILD_DONE; } else if (stat == WAIT_TIMEOUT) { return APR_CHILD_NOTDONE; } return GetLastError(); } if ((stat = WaitForSingleObject((HANDLE)proc->pid, 0)) == WAIT_OBJECT_0) { return APR_CHILD_DONE; } else if (stat == WAIT_TIMEOUT) { return APR_CHILD_NOTDONE; } return GetLastError();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -