Change parent behaviour when calling waitpid().

Wait for any process in our process group only instead of WAIT_ANY.

This allows the parent process to start subprocesses that end up
in different process groups which are handled in user code instead
completely (using signalfd for example).
This commit is contained in:
Joris Vink 2022-02-01 10:34:12 +01:00
parent 833ca646e7
commit b3f54e290a
1 changed files with 18 additions and 15 deletions

View File

@ -61,10 +61,6 @@
#include "seccomp.h"
#endif
#if !defined(WAIT_ANY)
#define WAIT_ANY (-1)
#endif
#define WORKER_SOLO_COUNT 3
#define WORKER(id) \
@ -92,6 +88,7 @@ static void worker_accept_avail(struct kore_msg *, const void *);
static void worker_entropy_recv(struct kore_msg *, const void *);
static void worker_keymgr_response(struct kore_msg *, const void *);
static pid_t worker_pgrp;
static int accept_avail;
static struct kore_worker *kore_workers;
static int worker_no_lock;
@ -153,6 +150,9 @@ kore_worker_init(void)
if (!kore_quiet)
kore_log(LOG_INFO, "starting worker processes");
if ((worker_pgrp = getpgrp()) == -1)
fatal("%s: getpgrp(): %s", __func__, errno_s);
/* Now start all the workers. */
id = 1;
cpu = 1;
@ -647,19 +647,22 @@ kore_worker_reap(void)
pid_t pid;
int status;
pid = waitpid(WAIT_ANY, &status, WNOHANG);
for (;;) {
pid = waitpid(-worker_pgrp, &status, WNOHANG);
if (pid == -1) {
if (errno == ECHILD || errno == EINTR)
return;
kore_log(LOG_ERR, "%s: waitpid(): %s", __func__, errno_s);
return;
if (pid == -1) {
if (errno != ECHILD && errno != EINTR) {
kore_log(LOG_ERR,
"%s: waitpid(): %s", __func__, errno_s);
}
break;
}
if (pid == 0)
break;
worker_reaper(pid, status);
}
if (pid == 0)
return;
worker_reaper(pid, status);
}
void