From nobody Thu Apr 23 19:17:49 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 4g1m7x4yR5z6bMdL for ; Thu, 23 Apr 2026 19:17:49 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g1m7x3N4Vz3jhN for ; Thu, 23 Apr 2026 19:17:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776971869; 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=5PQ73nUXYB+fjY6LExbTIOo7u8S+y0tg569p5xqF07A=; b=SQCuaVS3DBg96/rUnHSC9HquFncUTnlC+pZ6uoLGQ29LxCEafVr3L2hPn5U4yadB7eo0yd Ae8tCIpQnRjq6QDcKqnywMn/lYdggb1a3uyayvEeBTPDczQTfp+QV//29bPXwdb/WNNK4Z kwTiYiLoF7L0pf5gzeZWtVQiZ32Ivg85VM/MKBRkCPWNvPbOoyv+WqiTqL9FvqLgMkLyaE +vGTidPUIvFpGP0rnIoTsm6gvZu/Pqa7myFEdfbxYC0PxlQwPGtYFR6Ivc1VNr7Vyh+uhp IZZrFQnbtrmizXi3ZiK+EnmZ+WFN4gbe96HmOKcpKtyiBsv/qch7E6KYGxV+Ag== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776971869; a=rsa-sha256; cv=none; b=lgn7sFFJpIUluVPn+5NpW+Tq0r5rJ2EH6CHs27D97BrvoUASzyZSJFRFvV/3m5BoFC89VV ek9kiVO1sJk4z5Rtw3dNgEcufIDgwYJa7zPyhZ74OxORRlpFXBPGMCRMwzACgIyBUqKy9M Ns4vD4HPxzOkQd0BDoIDLX0kLbF3h6juW9n3LX4TYgvyWpu2eGjPhfQyu0XUOiBXGmG2FW NFeCUVp3+3feTxhhcvdy6i1Wf0+xQTVyAOeLOcKZz3DVHVp1mSKane9E98tiFl85LWVy2F W3+OdHvdspG5dWm/D8WlPsBQE/6+kztRdz2xaqOEGr8TbzERKuvCdddAiwHcUA== 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=1776971869; 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=5PQ73nUXYB+fjY6LExbTIOo7u8S+y0tg569p5xqF07A=; b=i3uszqiKq3qoJ80QGZrYPR3noH/m98TeqhRub9nsyrAzhhtENvLEDVpE79B2+yIqRviVP/ 2lcqFJWpuV+YdxKfkV/L+MtVrlSSB1yirKErhy6wawU0VufYBxVbpnB60GE+MOqIjxrZAq bQuqBuod7AF7H9AWMB3AW2NFnFqVcekGYsvv3aNoskSBcydtyzqiwu4orYHNnPFziK9cae 54ocxoyziEipOmPeFNOzNejitKouGo5/ZnhvlxFdZS7JQS3TuSvHOjSJtpxrYF73LfGJ7n XCcOV1FqXbvStvt7GFCC+VHXQQT8an7KWQXKPY7+jzlyhj6UiuCzw0/RMz4ryA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g1m7x2rDlzVFQ for ; Thu, 23 Apr 2026 19:17:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 19eb9 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 23 Apr 2026 19:17:49 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: aad4fec5d7e2 - main - 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 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/main X-Git-Reftype: branch X-Git-Commit: aad4fec5d7e260a789456a8cc82b293064fab5f3 Auto-Submitted: auto-generated Date: Thu, 23 Apr 2026 19:17:49 +0000 Message-Id: <69ea705d.19eb9.341feb7f@gitrepo.freebsd.org> The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=aad4fec5d7e260a789456a8cc82b293064fab5f3 commit aad4fec5d7e260a789456a8cc82b293064fab5f3 Author: John Baldwin AuthorDate: 2026-04-23 19:17:05 +0000 Commit: John Baldwin CommitDate: 2026-04-23 19:17: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 --- 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 e3050974dd35..cf1dde93b86d 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) @@ -1972,12 +1959,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()) { @@ -1992,7 +1977,6 @@ conf::apply(struct conf *oldconf) conf_pidfile_path.c_str()); } } - conf_pidfile = std::move(oldconf->conf_pidfile); } /* @@ -2358,7 +2342,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, @@ -2705,7 +2689,7 @@ main(int argc, char **argv) if (test_config) return (0); - newconf->open_pidfile(); + open_pidfile(newconf->pidfile_path()); register_signals(); @@ -2739,7 +2723,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 a1bd5a62cf3b..61213119f911 100644 --- a/usr.sbin/ctld/ctld.hh +++ b/usr.sbin/ctld/ctld.hh @@ -459,6 +459,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; } @@ -504,10 +505,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); @@ -542,8 +539,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;