From b4e22ead6ce9ed53660666a3ab715682872e319d Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 7 Jul 2022 12:40:55 +0200 Subject: indexamajig: Remove separate waitpid() calls when cleaning up last processes --- src/im-sandbox.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/im-sandbox.c') diff --git a/src/im-sandbox.c b/src/im-sandbox.c index a9722509..87a05d03 100644 --- a/src/im-sandbox.c +++ b/src/im-sandbox.c @@ -798,6 +798,16 @@ static void start_worker_process(struct sandbox *sb, int slot) } +static int any_running(struct sandbox *sb) +{ + int i; + for ( i=0; in_proc; i++ ) { + if ( sb->running[i] ) return 1; + } + return 0; +} + + static void handle_zombie(struct sandbox *sb, int respawn) { int i; @@ -811,7 +821,7 @@ static void handle_zombie(struct sandbox *sb, int respawn) p = waitpid(sb->pids[i], &status, WNOHANG); if ( p == -1 ) { - ERROR("waitpid() failed.\n"); + ERROR("waitpid(%i) failed: %s.\n", i, strerror(errno)); continue; } @@ -1301,17 +1311,11 @@ int create_sandbox(struct index_args *iargs, int n_proc, char *prefix, sem_post(sb->queue_sem); } for ( i=0; ipids[i], &status, WNOHANG) == 0 ) { - + while ( any_running(sb) ) { try_read(sb); - check_signals(sb, semname_q, 0); - check_hung_workers(sb); - try_status(sb, 0); - } /* If this worker died and got waited by the zombie handler, * waitpid() returns -1 and the loop still exits. */ -- cgit v1.2.3