diff options
author | Steve Bennett <steveb@workware.net.au> | 2014-01-05 19:55:56 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2014-01-15 07:46:33 +1000 |
commit | a4c0bf120c291bfb69bd161cdc237a751e53f2c7 (patch) | |
tree | 2db9087c66dad3ec694f8bc7762703b82be26f5a /jim-exec.c | |
parent | 65820c9d0e90fb082e8399ad13bc654ac7c1a547 (diff) | |
download | jimtcl-a4c0bf120c291bfb69bd161cdc237a751e53f2c7.zip jimtcl-a4c0bf120c291bfb69bd161cdc237a751e53f2c7.tar.gz jimtcl-a4c0bf120c291bfb69bd161cdc237a751e53f2c7.tar.bz2 |
exec: fix reaping of detached processes
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-exec.c')
-rw-r--r-- | jim-exec.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -452,22 +452,28 @@ static void JimReapDetachedPids(struct WaitInfoTable *table) { struct WaitInfo *waitPtr; int count; + int dest; if (!table) { return; } - for (waitPtr = table->info, count = table->used; count > 0; waitPtr++, count--) { + waitPtr = table->info; + dest = 0; + for (count = table->used; count > 0; waitPtr++, count--) { if (waitPtr->flags & WI_DETACHED) { int status; pidtype pid = JimWaitPid(waitPtr->pid, &status, WNOHANG); - if (pid != JIM_BAD_PID) { - if (waitPtr != &table->info[table->used - 1]) { - *waitPtr = table->info[table->used - 1]; - } + if (pid == waitPtr->pid) { + /* Process has exited, so remove it from the table */ table->used--; + continue; } } + if (waitPtr != &table->info[dest]) { + table->info[dest] = *waitPtr; + } + dest++; } } |