git: 2fae556f6a8b - stable/13 - var_run: Clean up style
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 07 Mar 2025 00:34:03 UTC
The branch stable/13 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=2fae556f6a8b10bdef22eba0d83b0880e3669496 commit 2fae556f6a8b10bdef22eba0d83b0880e3669496 Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2024-11-26 15:16:22 +0000 Commit: Cy Schubert <cy@FreeBSD.org> CommitDate: 2025-03-05 04:46:14 +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. MFC after: 2 weeks 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 eb9cdbd59305..71f84d23cb3d 100755 --- a/libexec/rc/rc.d/var_run +++ b/libexec/rc/rc.d/var_run @@ -23,26 +23,30 @@ load_rc_config $name : ${var_run_autosave:="YES"} _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"