From nobody Tue Jun 23 16:28:14 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gl9V71VbXz6hhPB for ; Tue, 23 Jun 2026 16:28:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gl9V66lx3z3MmB for ; Tue, 23 Jun 2026 16:28:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782232095; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4k0sEbAfkWaVnJKvVFUpv7bYGH1WoQ/gyUY6IKBt1TA=; b=pn9sVa9cyc10kK9+nMR43dSeKIO267P43ZL3pGKCBnRzRr5fRedxMNyTRx9yxCUQ4x3DWi lyo064iQluEWM8nEhyGcxk2RF1PynX0OXEnbHXIJcbU4j3S/tYPCh6xgF1pNX0sHG+Pw1I mr/gOBpoVnWpNv5jqAmaplvEEkOCLBDU9ZkfAncnG5AmcMKuVXaNf2nA4kGpctM0RhgMsK HyilHF+DF9+1dIYUaJotUSj1b4W/SLY87wM7z54ovdWm7ZyooVPJJ9ApFzr14B+labX6PM qcOXYEfDTdOpb86+nH7l8O3losmb8Eh+BOc+bUqI5rbTpBtCfqzzSrtU7khGHA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782232094; a=rsa-sha256; cv=none; b=BxldUD4EHyHgydq8BSysjynPVbksloOxUa5jt+ArzrGszM5M5tFlPuJgwJF2ojNynYmvQ4 M8IfO1T31nNqruWOsHtstUTJq/P8YQ4Dodmcc2CL62ONjL4M9VlZx7yh3EKVWaPrR68G+m IQ/mE4bP5Tm/tbyvT6LEilbXNo7gfABQtORDWADMCeyyEI57lLuaVk2WMo2HQrawSYhzTK d3W6E93ltVYD8OD/1L16xcARz7KGfwtkxYWbn8FYkG352BoaMjUKL+/YxJ10xI6HQQ3bgJ hzUz8MjktOTg7hYQllukVl3OWhnJj7xIHrHNrzaZThyWo9L4PRvEwf73v88J6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782232094; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4k0sEbAfkWaVnJKvVFUpv7bYGH1WoQ/gyUY6IKBt1TA=; b=le0kaG7bAT7j7COpx/NE41lHbewYt6OVhkP9LUCM2oOHCLebP0jikZKjzt5BRydTBBt+Eu YZMhNICFfgnmoIJg8lRYoM+KCayxmlSp/Ve6WOlbqSClWCK3BF5YKTydTyQ0cbW/Ybw8tg nkwQ69j4sNUF3/U1P85xQkmKK2J5ZlnjLysf1YD5f0XNyXJiWKaRnDfSc07LX8N18P5nbt tN/oD/6Jq4dtWYcvXHa6ZdwRJMkLr3ak0kovMH12aeegOUFxMHmfJzJ35ojDkgablW4J/b dqtn83DarkvJjZD2lRY3E/RgUZTkbvKhmD80qGLTOwSSyy9p+kUbzZ91okThIQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gl9V654dwzhHs for ; Tue, 23 Jun 2026 16:28:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 26f9c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 23 Jun 2026 16:28:14 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 0885d8fdd607 - stable/15 - ctld: Move the pidfile handle out to a global variable List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 0885d8fdd607f469a55dd192bc13751a8094a64e Auto-Submitted: auto-generated Date: Tue, 23 Jun 2026 16:28:14 +0000 Message-Id: <6a3ab41e.26f9c.e5a95f6@gitrepo.freebsd.org> The branch stable/15 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=0885d8fdd607f469a55dd192bc13751a8094a64e commit 0885d8fdd607f469a55dd192bc13751a8094a64e Author: John Baldwin AuthorDate: 2026-04-23 19:17:05 +0000 Commit: John Baldwin CommitDate: 2026-06-23 16:06:05 +0000 ctld: Move the pidfile handle out to a global variable This ensures it will be destroyed (removing the associated pidfile) anytime the process exits, including from exit(3) calls. This fixes a few places that would "leak" the pidfile on certain errors. This also removes the need for some convoluted logic where configuration objects would hand-off ownership of the pidfile handle from the old configuration to the new configuration. Reviewed by: asomers Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D56527 (cherry picked from commit aad4fec5d7e260a789456a8cc82b293064fab5f3) --- usr.sbin/ctld/ctld.cc | 42 +++++++++++++----------------------------- usr.sbin/ctld/ctld.hh | 7 +------ 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/usr.sbin/ctld/ctld.cc b/usr.sbin/ctld/ctld.cc index 6cb4599a6ca8..8aaec41e8487 100644 --- a/usr.sbin/ctld/ctld.cc +++ b/usr.sbin/ctld/ctld.cc @@ -59,6 +59,8 @@ #include "ctld.hh" #include "isns.hh" +static freebsd::pidfile pidfile; + bool proxy_mode = false; static volatile bool sighup_received = false; @@ -125,17 +127,14 @@ conf::set_pidfile_path(std::string_view path) return (true); } -void -conf::open_pidfile() +static void +open_pidfile(const char *path) { - const char *path; pid_t otherpid; - assert(!conf_pidfile_path.empty()); - path = conf_pidfile_path.c_str(); log_debugx("opening pidfile %s", path); - conf_pidfile = pidfile_open(path, 0600, &otherpid); - if (!conf_pidfile) { + pidfile = pidfile_open(path, 0600, &otherpid); + if (!pidfile) { if (errno == EEXIST) log_errx(1, "daemon already running, pid: %jd.", (intmax_t)otherpid); @@ -143,18 +142,6 @@ conf::open_pidfile() } } -void -conf::write_pidfile() -{ - conf_pidfile.write(); -} - -void -conf::close_pidfile() -{ - conf_pidfile.close(); -} - #ifdef ICL_KERNEL_PROXY int conf::add_proxy_portal(portal *portal) @@ -1987,12 +1974,10 @@ conf::apply(struct conf *oldconf) } /* - * On startup, oldconf created via conf_new_from_kernel will - * not contain a valid pidfile_path, and the current - * conf_pidfile will already own the pidfile. On shutdown, - * the temporary newconf will not contain a valid - * pidfile_path, and the pidfile will be cleaned up when the - * oldconf is deleted. + * Rename the pidfile if the pathname changes. On startup, + * oldconf created via conf_new_from_kernel will not contain a + * valid pidfile_path. On shutdown, the temporary newconf + * will not contain a valid pidfile_path. */ if (!oldconf->conf_pidfile_path.empty() && !conf_pidfile_path.empty()) { @@ -2007,7 +1992,6 @@ conf::apply(struct conf *oldconf) conf_pidfile_path.c_str()); } } - conf_pidfile = std::move(oldconf->conf_pidfile); } /* @@ -2373,7 +2357,7 @@ handle_connection(struct portal *portal, freebsd::fd_up fd, log_err(1, "fork"); if (pid > 0) return; - conf->close_pidfile(); + pidfile.close(); } error = getnameinfo(client_sa, client_sa->sa_len, @@ -2720,7 +2704,7 @@ main(int argc, char **argv) if (test_config) return (0); - newconf->open_pidfile(); + open_pidfile(newconf->pidfile_path()); register_signals(); @@ -2754,7 +2738,7 @@ main(int argc, char **argv) oldconf.reset(); - newconf->write_pidfile(); + pidfile.write(); newconf->isns_schedule_update(); diff --git a/usr.sbin/ctld/ctld.hh b/usr.sbin/ctld/ctld.hh index fdd70a37c514..45590ada4111 100644 --- a/usr.sbin/ctld/ctld.hh +++ b/usr.sbin/ctld/ctld.hh @@ -461,6 +461,7 @@ struct conf { int maxproc() const { return conf_maxproc; } int timeout() const { return conf_timeout; } uint32_t genctr() const { return conf_genctr; } + const char *pidfile_path() const { return conf_pidfile_path.c_str(); } bool default_auth_group_defined() const { return conf_default_ag_defined; } @@ -506,10 +507,6 @@ struct conf { bool set_pidfile_path(std::string_view path); void set_timeout(int timeout); - void open_pidfile(); - void write_pidfile(); - void close_pidfile(); - bool add_isns(const char *addr); void isns_register_targets(struct isns *isns, struct conf *oldconf); void isns_deregister_targets(struct isns *isns); @@ -544,8 +541,6 @@ private: int conf_maxproc = 30; uint32_t conf_genctr = 0; - freebsd::pidfile conf_pidfile; - bool conf_default_pg_defined = false; bool conf_default_tg_defined = false; bool conf_default_ag_defined = false;