aboutsummaryrefslogtreecommitdiff
path: root/jim-exec.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2014-01-05 19:55:56 +1000
committerSteve Bennett <steveb@workware.net.au>2014-01-15 07:46:33 +1000
commita4c0bf120c291bfb69bd161cdc237a751e53f2c7 (patch)
tree2db9087c66dad3ec694f8bc7762703b82be26f5a /jim-exec.c
parent65820c9d0e90fb082e8399ad13bc654ac7c1a547 (diff)
downloadjimtcl-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.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/jim-exec.c b/jim-exec.c
index 7d41bc9..08f7985 100644
--- a/jim-exec.c
+++ b/jim-exec.c
@@ -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++;
}
}