git: 23ad1f4bb737 - stable/14 - var_run: Clean up style
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 07 Mar 2025 00:33:54 UTC
The branch stable/14 has been updated by cy:
URL: https://cgit.FreeBSD.org/src/commit/?id=23ad1f4bb73778c1e01600be76a4a85edcc6c330
commit 23ad1f4bb73778c1e01600be76a4a85edcc6c330
Author: Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2024-11-26 15:16:22 +0000
Commit: Cy Schubert <cy@FreeBSD.org>
CommitDate: 2025-03-07 00:32:53 +0000
var_run: Clean up style
Clean up style and make more consistent.
Replace test with if-then-else to make the script more legible.
Replace the call to dirname with the shell %/* operator avoiding a
fork & exec.
Reorder the test for $var_run_autosave before the test for /var/run on
tmpfs. This avoids gratuitously scanning the mount table for a tmpfs
/var/run.
Initial concept by and in discussion with:
Harry Schmalzbauer <freebsd@omnilan.de>
No functional change intended.
Differnential revision: https://reviews.freebsd.org/D47773
(cherry picked from commit ed9712f8943573136fa92a0e61c8e7c10952eeb0)
---
libexec/rc/rc.d/var_run | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/libexec/rc/rc.d/var_run b/libexec/rc/rc.d/var_run
index 9f0f7fcf37fd..6d54aedd7421 100755
--- a/libexec/rc/rc.d/var_run
+++ b/libexec/rc/rc.d/var_run
@@ -18,26 +18,30 @@ stop_cmd="_var_run_stop"
load_rc_config $name
_var_run_load() {
- test -f ${var_run_mtree} &&
- mtree -U -i -q -f ${var_run_mtree} -p /var/run > /dev/null
+ if [ -f "${var_run_mtree}" ] ; then
+ mtree -U -i -q -f "${var_run_mtree}" -p /var/run > /dev/null
+ fi
}
_var_run_save() {
- if [ ! -d $(dirname ${var_run_mtree}) ]; then
- mkdir -p $(dirname ${var_run_mtree})
+ if ! [ -d "${var_run_mtree%/*}" ]; then
+ mkdir -p "${var_run_mtree%/*}"
fi
- mtree -dcbj -p /var/run > ${var_run_mtree}
+ mtree -dcbj -p /var/run > "${var_run_mtree}"
}
_var_run_start() {
- df -ttmpfs /var/run > /dev/null 2>&1 &&
+ if df -ttmpfs /var/run > /dev/null 2>&1; then
_var_run_load
+ fi
}
_var_run_stop() {
- df -ttmpfs /var/run > /dev/null 2>&1 &&
- checkyesno var_run_autosave &&
+ if checkyesno var_run_autosave; then
+ if df -ttmpfs /var/run > /dev/null 2>&1; then
_var_run_save
+ fi
+ fi
}
run_rc_command "$1"