diff options
-rw-r--r-- | jim-exec.c | 6 | ||||
-rw-r--r-- | jimiocompat.c | 17 |
2 files changed, 17 insertions, 6 deletions
@@ -614,6 +614,12 @@ static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (phandle == JIM_BAD_PHANDLE) { pid = -1; } + else if (pid < 0) { + /* This catches the case where pid=-1. It is only supported on unix where + * the returned phandle is a pid, so can simply assign here + */ + pid = phandle; + } errCodeObj = JimMakeErrorCode(interp, pid, status, NULL); diff --git a/jimiocompat.c b/jimiocompat.c index 665a65a..8e7f3f2 100644 --- a/jimiocompat.c +++ b/jimiocompat.c @@ -102,15 +102,20 @@ long JimProcessPid(phandle_t pid) * Returns the phandle of the process identified by 'pid' or JIM_BAD_PHANDLE on error. * Note that on success, the handle will no longer be valid. * It can only be used as a token (e.g. to look up the wait table) + * + * Note that Windows doesn't support waitpid(-1, ...) to wait for any child process + * so just always return JIM_BAD_PHANDLE in that case. */ phandle_t JimWaitPid(long pid, int *status, int nohang) { - HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid); - if (h) { - long pid = waitpid(h, status, nohang); - CloseHandle(h); - if (pid > 0) { - return h; + if (pid > 0) { + HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid); + if (h) { + long pid = waitpid(h, status, nohang); + CloseHandle(h); + if (pid > 0) { + return h; + } } } return JIM_BAD_PHANDLE; |