aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2026-05-18 19:49:57 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2026-05-18 19:49:57 +0000
commit9306d0449ba6fffadf08d5ab61aea596369e03f4 (patch)
treea4811878bb5a36c1095d919a6b4c81eb070f3b4a
parentf1c5de5fab9d5cada11935418db11e19ebff7e34 (diff)
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
-rw-r--r--usr.sbin/ctld/ctld.cc25
1 files 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");