Date: Mon, 20 Apr 2026 17:20:26 +0000 From: John Baldwin <jhb@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 4b79ee8eb139 - main - ctld: Update nchildren directly in wait_for_children Message-ID: <69e6605a.3efa2.117819ab@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=4b79ee8eb139696c1fe845d25a56439d02ab4131 commit 4b79ee8eb139696c1fe845d25a56439d02ab4131 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2026-04-20 17:19:49 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2026-04-20 17:19:49 +0000 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 --- usr.sbin/ctld/ctld.cc | 28 ++++++++++++---------------- 1 file 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(); }home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69e6605a.3efa2.117819ab>
