Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ignore pot status files that predate boot #278

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed
- start: Fix setting of nullfs attribute
- set-status: Ignore status files that predate system boot (#278)

## [0.15.6] 2023-09-29
### Added
Expand Down
5 changes: 5 additions & 0 deletions share/pot/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ _save_params () {
echo " "
}

# get system boot time in seconds since the epoch
_get_system_uptime() {
sysctl -n kern.boottime | sed -e 's/.*[^u]sec = \([0-9]*\).*$/\1/'
}

# validate some values of the configuration files
# $1 quiet / no _error messages are emitted
_conf_check()
Expand Down
11 changes: 10 additions & 1 deletion share/pot/set-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ set-status-help()
# $1 pot name
_get_status()
{
local _pname _status_file
local _pname _status_file _uptime _mod_time
_pname="$1"
_status_file="${POT_TMP:-/tmp}/pot_status_${_pname}"

if [ ! -e "$_status_file" ]; then
return
fi

_mod_time=$(stat -f "%m" "$_status_file")
_uptime=$(_get_system_uptime)

if [ "$_uptime" -gt "$_mod_time" ]; then
>&2 _debug "Ignoring oudated status file $_status_file of pot $_pname"
return
fi

_value="$(grep "^pot.status=" "$_status_file" | tail -n 1 \
|tr -d ' \t"' | cut -f2 -d'=' )"
echo "$_value"
Expand Down