use /proc/uptime or SECONDS (bash) to get 'now' variable

Instead of using now=$(date +%s), use a function 'getnow'.
That function will be defined to either use variable SECONDS (if bash),
/proc/uptime if available, or fall back to bash.

TODO: need to expire existing status files on startup if they have 'now' 
data newer than the existing now.  That would cover:
 - system time change
 - new 'getnow' that used a different "now" (ie, if you moved from
   using date to uptime, it would go backwards.
This commit is contained in:
Scott Moser 2011-07-21 08:51:03 -04:00
commit ca48252763
2 changed files with 16 additions and 2 deletions

View file

@ -38,7 +38,7 @@ while true; do
rm -f "$BYOBU_RUN_DIR/status"/* "$BYOBU_RUN_DIR/.last"/*
exit 0
fi
now=$(date +%s)
getnow; now=${_RET}
# Re-source configuration, if changed since last run
for i in "${BYOBU_PREFIX}/share/$PKG/status/status" "${BYOBU_PREFIX}/share/$PKG/status/statusrc" "$BYOBU_CONFIG_DIR/status" "$BYOBU_CONFIG_DIR/statusrc"; do
[ -r "$i" ] && [ "$i" -nt "$BYOBU_RUN_DIR/status" ] && . "$i"
@ -65,7 +65,7 @@ while true; do
if [ "$path" -nt "$last" ] || [ ! -e "$last" ]; then
. "$path"
fi
eval "__$i" > "$cache"
"__$i" > "$cache"
echo "$now" > "$last"
fi
done

View file

@ -257,4 +257,18 @@ status_freq() {
esac
}
getnow() { _RET=$(date +%s); }
if [ -n "${BASH_VERSION}" -a -n "${SECONDS}" ]; then
getnow() {
_RET=${SECONDS}
}
elif [ -r /proc/cpuinfo ]; then
getnow() {
# return the integer part of the first item in /proc/uptime
local s c
read s c < /proc/uptime
_RET=${s%.*}
}
fi
# vi: syntax=sh ts=4 noexpandtab