The branch main has been updated by jhb:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=9306d0449ba6fffadf08d5ab61aea596369e03f4

commit 9306d0449ba6fffadf08d5ab61aea596369e03f4
Author:     John Baldwin <[email protected]>
AuthorDate: 2026-05-18 19:49:57 +0000
Commit:     John Baldwin <[email protected]>
CommitDate: 2026-05-18 19:49:57 +0000

    ctld: Simplify pidfile rename handling in conf::apply
    
    Explicitly copy the pidfile path from the initial configuration file
    to the kernel-derived configuration to avoid having to check if the
    old path is empty as a special case in conf::apply().
    
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D56533
---
 usr.sbin/ctld/ctld.cc | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/usr.sbin/ctld/ctld.cc b/usr.sbin/ctld/ctld.cc
index 24b02a936670..9bdf15976911 100644
--- a/usr.sbin/ctld/ctld.cc
+++ b/usr.sbin/ctld/ctld.cc
@@ -1973,22 +1973,14 @@ conf::apply(struct conf *oldconf)
                log_init(conf_debug);
        }
 
-       /*
-        * Rename the pidfile if the pathname changes.  On startup,
-        * oldconf created via conf_new_from_kernel will not contain a
-        * valid pidfile_path.
-        */
-       if (!oldconf->conf_pidfile_path.empty()) {
-               if (oldconf->conf_pidfile_path != conf_pidfile_path) {
-                       /* pidfile has changed.  rename it */
-                       log_debugx("moving pidfile to %s",
+       /* Rename the pidfile if the pathname changes. */
+       if (oldconf->conf_pidfile_path != conf_pidfile_path) {
+               log_debugx("moving pidfile to %s", conf_pidfile_path.c_str());
+               if (rename(oldconf->conf_pidfile_path.c_str(),
+                   conf_pidfile_path.c_str()) != 0) {
+                       log_err(1, "renaming pidfile %s -> %s",
+                           oldconf->conf_pidfile_path.c_str(),
                            conf_pidfile_path.c_str());
-                       if (rename(oldconf->conf_pidfile_path.c_str(),
-                               conf_pidfile_path.c_str()) != 0) {
-                               log_err(1, "renaming pidfile %s -> %s",
-                                   oldconf->conf_pidfile_path.c_str(),
-                                   conf_pidfile_path.c_str());
-                       }
                }
        }
 
@@ -2748,6 +2740,9 @@ main(int argc, char **argv)
                newconf->set_debug(debug);
        }
 
+       /* Reuse the pidfile path from the configuration file. */
+       oldconf->set_pidfile_path(newconf->pidfile_path());
+
        if (!newconf->add_pports(kports))
                log_errx(1, "Error associating physical ports; exiting");
 

Reply via email to