From c5a8ec4ce369bcc1038efaa4faa62e3b461f5fb9 Mon Sep 17 00:00:00 2001 From: grembo Date: Mon, 18 Dec 2023 17:55:47 +0100 Subject: [PATCH] Forward verbosity flags to set-status (#279) This gives the set-status call its own function in common.sh, improving readability. --- CHANGELOG.md | 1 + share/pot/common.sh | 24 ++++++++++++++++++++++++ share/pot/start.sh | 12 +++++------- share/pot/stop.sh | 5 ++--- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e5f00a..2477836 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - tinirc: Overwrite tinirc on start instead of appending to an existing file (#277) - start: Fix setting of nullfs attribute - set-status: Ignore status files that predate system boot (#278) +- set-status: Forward verbosity flags (#279) ## [0.15.6] 2023-09-29 ### Added diff --git a/share/pot/common.sh b/share/pot/common.sh index b90e627..0748578 100644 --- a/share/pot/common.sh +++ b/share/pot/common.sh @@ -234,6 +234,30 @@ _is_pot_tmp_dir() fi } +# set status of pot, locks properly +# $1 pot name +# $2 status to set +# $3 interfaces for pot (epaira) +_set_pot_status() +{ + local _pname _status _interfaces _verbose _param + _pname=$1 + _status=$2 + _interfaces=$3 + _param=$(_save_params "-p" "$_pname" "-s" "$_status") + if [ -n "$_interfaces" ]; then + _param="$_param"$(_save_params "-i" "$_interfaces") + fi + if [ "$_POT_VERBOSITY" -gt 1 ]; then + _verbose=$(printf -- "-%$(( _POT_VERBOSITY - 1 ))s" |\ + tr " " "v") + _param="$_param"$(_save_params "$_verbose") + fi + eval "set -- $_param" + lockf "${POT_TMP:-/tmp}/pot-lock-$_pname" "${_POT_PATHNAME}"\ + set-status "$@" +} + # check if the dataset is a dataset name # $1 the dataset NAME # tested diff --git a/share/pot/start.sh b/share/pot/start.sh index 0a50fff..056b475 100644 --- a/share/pot/start.sh +++ b/share/pot/start.sh @@ -33,8 +33,7 @@ start-cleanup() return fi # doa state will only be set if pot is in state "starting" - lockf "${POT_TMP:-/tmp}/pot-lock-$_pname" "${_POT_PATHNAME}" \ - set-status -p "$_pname" -s doa + _set_pot_status "$_pname" doa if [ -n "$_epaira" ] && _is_valid_netif "$_epaira" ; then _ifaces="$_epaira" fi @@ -671,8 +670,7 @@ _js_start() echo "$_wait_pid" >"${POT_TMP:-/tmp}/pot_main_pid_${_pname}" fi # Here is where the pot is marked as started - lockf "${POT_TMP:-/tmp}/pot-lock-$_pname" "${_POT_PATHNAME}" set-status \ - -p "$_pname" -s started -i "$_ifaces" + _set_pot_status "$_pname" started "$_ifaces" rc=$? if [ $rc -eq 2 ]; then _info "pot $_pname is already started (???)" @@ -691,7 +689,7 @@ _js_start() rm -f "${POT_TMP:-/tmp}/pot_main_pid_${_pname}" # non-persistent jails always need to die # Here is where the pot is stopping - lockf "${POT_TMP:-/tmp}/pot-lock-$_pname" "${_POT_PATHNAME}" set-status -p "$_pname" -s stopping + _set_pot_status "$_pname" stopping rc=$? if [ $rc -eq 2 ]; then _debug "pot $_pname is already stopping (maybe by a pot stop)" @@ -709,7 +707,7 @@ _js_start() fi elif ! _is_pot_running "$_pname" ; then # persistent jail didn't come up, this is an error - lockf "${POT_TMP:-/tmp}/pot-lock-$_pname" "${_POT_PATHNAME}" set-status -p "$_pname" -s stopping + _set_pot_status "$_pname" stopping rc=$? if [ $rc -eq 2 ]; then _debug "pot $_pname is already stopping (maybe by a pot stop?)" @@ -805,7 +803,7 @@ pot-start() fi # Here is where the pot is starting - lockf "${POT_TMP:-/tmp}/pot-lock-$_pname" "${_POT_PATHNAME}" set-status -p "$_pname" -s starting + _set_pot_status "$_pname" starting rc=$? if [ $rc -eq 2 ]; then _error "pot $_pname is already starting" diff --git a/share/pot/stop.sh b/share/pot/stop.sh index 489159a..cdddc04 100644 --- a/share/pot/stop.sh +++ b/share/pot/stop.sh @@ -211,8 +211,7 @@ pot-stop() fi # Here is where the pot is stopping - _epaira_ifs="$(lockf "${POT_TMP:-/tmp}/pot-lock-$_pname" \ - "${_POT_PATHNAME}" set-status -p "$_pname" -s stopping)" + _epaira_ifs="$(_set_pot_status "$_pname" stopping)" rc=$? if [ $rc -eq 2 ]; then if [ $_from_start = "YES" ]; then @@ -236,7 +235,7 @@ pot-stop() fi _js_rm_resolv "$_pname" _pot_umount "$_pname" - lockf "${POT_TMP:-/tmp}/pot-lock-$_pname" "${_POT_PATHNAME}" set-status -p "$_pname" -s stopped + _set_pot_status "$_pname" stopped rc=$? if [ $rc -eq 2 ]; then _error "pot $_pname is already stopped!"