diff --git a/ext-src/swoole_runtime.cc b/ext-src/swoole_runtime.cc index 9c57d9e051..46b7612947 100644 --- a/ext-src/swoole_runtime.cc +++ b/ext-src/swoole_runtime.cc @@ -2033,8 +2033,10 @@ static void hook_func(const char *name, size_t l_name, zif_handler handler, zend rf->ori_handler = zf->internal_function.handler; rf->ori_arg_info = zf->internal_function.arg_info; - ori_func_handlers.set(fn_name, rf->ori_handler); - ori_func_arg_infos.set(fn_name, rf->ori_arg_info); + if (sw_is_main_thread()) { + ori_func_handlers.set(fn_name, rf->ori_handler); + ori_func_arg_infos.set(fn_name, rf->ori_arg_info); + } zf->internal_function.handler = handler; if (arg_info) { diff --git a/thirdparty/php/standard/proc_open.cc b/thirdparty/php/standard/proc_open.cc index c1d1521a3f..bae5a1a48c 100644 --- a/thirdparty/php/standard/proc_open.cc +++ b/thirdparty/php/standard/proc_open.cc @@ -53,6 +53,14 @@ extern int openpty(int *, int *, char *, struct termios *, struct winsize *); static int le_proc_open; static const char *le_proc_name = "process/coroutine"; +static pid_t _co_waitpid(__pid_t __pid, int *__stat_loc, int __options) { +#ifdef SW_THREAD + return System::waitpid_safe(__pid, __stat_loc, __options); +#else + return System::waitpid(__pid, __stat_loc, __options); +#endif +} + /* {{{ _php_array_to_envp * Process the `environment` argument to `proc_open` * Convert into data structures which can be passed to underlying OS APIs like `exec` on POSIX or @@ -170,7 +178,7 @@ static void proc_co_rsrc_dtor(zend_resource *rsrc) { } if (proc->running) { - System::waitpid_safe(proc->child, &wstatus, 0); + _co_waitpid(proc->child, &wstatus, 0); } if (proc->wstatus) { *proc->wstatus = wstatus; @@ -255,7 +263,7 @@ PHP_FUNCTION(swoole_proc_get_status) { add_assoc_long(return_value, "pid", (zend_long) proc->child); errno = 0; - wait_pid = System::waitpid_safe(proc->child, &wstatus, WNOHANG | WUNTRACED); + wait_pid = _co_waitpid(proc->child, &wstatus, WNOHANG | WUNTRACED); if (wait_pid == proc->child) { if (WIFEXITED(wstatus)) {