diff options
author | Steve Bennett <steveb@workware.net.au> | 2022-05-08 15:18:17 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2022-05-08 15:45:27 +1000 |
commit | 7f75234e8e68394271ecb8b56a0a117a1d6066a7 (patch) | |
tree | c8df7ddccb3fb78b67c19c40e349173e571ba72e | |
parent | 8bcdb359a0c7217dfebc73c61037a005bb65717d (diff) | |
download | jimtcl-7f75234e8e68394271ecb8b56a0a117a1d6066a7.zip jimtcl-7f75234e8e68394271ecb8b56a0a117a1d6066a7.tar.gz jimtcl-7f75234e8e68394271ecb8b56a0a117a1d6066a7.tar.bz2 |
wait: fix support for wait -1
Only on unix systems. Does waitpid(-1, ...) to wait for any child
process to exit.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-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; |