diff options
| author | John Baldwin <jhb@FreeBSD.org> | 2026-04-20 17:19:49 +0000 |
|---|---|---|
| committer | John Baldwin <jhb@FreeBSD.org> | 2026-04-20 17:19:49 +0000 |
| commit | 4b79ee8eb139696c1fe845d25a56439d02ab4131 (patch) | |
| tree | 5678b782b6864f6ed1c49b2df300b532f294d20b | |
| parent | 7bb2b3801554a58039ed9d1fd05b65ce24c6c661 (diff) | |
ctld: Update nchildren directly in wait_for_children
This results in slightly less duplicated code.
Reviewed by: asomers
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D56526
| -rw-r--r-- | usr.sbin/ctld/ctld.cc | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/usr.sbin/ctld/ctld.cc b/usr.sbin/ctld/ctld.cc index 4ff8d30bb49f..b634debeafc8 100644 --- a/usr.sbin/ctld/ctld.cc +++ b/usr.sbin/ctld/ctld.cc @@ -2295,18 +2295,17 @@ start_timer(int timeout, bool fatal) log_err(1, "setitimer"); } -static int +static void wait_for_children(bool block) { pid_t pid; int status; - int num = 0; - for (;;) { - /* - * If "block" is true, wait for at least one process. - */ - if (block && num == 0) + /* + * If "block" is true, wait for at least one process. + */ + while (nchildren > 0) { + if (block) pid = wait4(-1, &status, 0, NULL); else pid = wait4(-1, &status, WNOHANG, NULL); @@ -2321,10 +2320,10 @@ wait_for_children(bool block) } else { log_debugx("child process %d terminated gracefully", pid); } - num++; - } + nchildren--; - return (num); + block = false; + } } static void @@ -2343,15 +2342,13 @@ handle_connection(struct portal *portal, freebsd::fd_up fd, if (dont_fork) { log_debugx("incoming connection; not forking due to -d flag"); } else { - nchildren -= wait_for_children(false); - assert(nchildren >= 0); + wait_for_children(false); while (conf->maxproc() > 0 && nchildren >= conf->maxproc()) { log_debugx("maxproc limit of %d child processes hit; " "waiting for child process to exit", conf->maxproc()); - nchildren -= wait_for_children(true); - assert(nchildren >= 0); + wait_for_children(true); } log_debugx("incoming connection; forking child process #%d", nchildren); @@ -2791,8 +2788,7 @@ main(int argc, char **argv) log_warnx("exiting on signal"); return (0); } else { - nchildren -= wait_for_children(false); - assert(nchildren >= 0); + wait_for_children(false); if (timed_out()) { newconf->isns_update(); } |
