Skip to content

Commit

Permalink
Forward verbosity flags to set-status (#279)
Browse files Browse the repository at this point in the history
This gives the set-status call its own function
in common.sh, improving readability.
  • Loading branch information
grembo committed Dec 18, 2023
1 parent 7a9e223 commit c5a8ec4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions share/pot/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions share/pot/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (???)"
Expand All @@ -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)"
Expand All @@ -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?)"
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions share/pot/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!"
Expand Down

0 comments on commit c5a8ec4

Please sign in to comment.