aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2022-07-07 12:40:55 +0200
committerThomas White <taw@physics.org>2022-07-07 12:40:55 +0200
commitb4e22ead6ce9ed53660666a3ab715682872e319d (patch)
tree825c4264d9c4c4b4cf90ad25069161dd0155807e /src
parent8e8c8db322101331c11eebb5036d032e98f2d331 (diff)
indexamajig: Remove separate waitpid() calls when cleaning up last processes
Diffstat (limited to 'src')
-rw-r--r--src/im-sandbox.c20
1 files changed, 12 insertions, 8 deletions
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; i<sb->n_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; i<n_proc; i++ ) {
- int status;
- while ( waitpid(sb->pids[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. */