From ca482527634fd901c49c700d8273734a8bae05b6 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 21 Jul 2011 08:51:03 -0400 Subject: [PATCH 1/2] 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. --- usr/bin/byobu-statusd | 4 ++-- usr/lib/byobu/.shutil | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/usr/bin/byobu-statusd b/usr/bin/byobu-statusd index 12649dce..12c97663 100755 --- a/usr/bin/byobu-statusd +++ b/usr/bin/byobu-statusd @@ -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 diff --git a/usr/lib/byobu/.shutil b/usr/lib/byobu/.shutil index e0db59f2..5b47ef11 100755 --- a/usr/lib/byobu/.shutil +++ b/usr/lib/byobu/.shutil @@ -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 From 893c1f9ade5553f1813c84502ba1b7deae9b9cc0 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 21 Jul 2011 10:50:36 -0400 Subject: [PATCH 2/2] if time (or byobu's "now") ever goes backwards, invalidate last-run cache time could go backwards via a setting of system date backwards. It could also go backwards if byobu-statusd was running, and then was killed and started again, but that time it decided to use 'uptime' or SECONDS to get its 'now'. in the case of SECONDS, every byobu-statusd will end up on first run invalidating all cache (which isn't really so bad) --- usr/bin/byobu-statusd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/usr/bin/byobu-statusd b/usr/bin/byobu-statusd index 12c97663..2762c934 100755 --- a/usr/bin/byobu-statusd +++ b/usr/bin/byobu-statusd @@ -57,6 +57,11 @@ while true; do continue fi [ -r "$last" ] && read lastrun < "$last" || lastrun=0 + + # if, for any reason the lastrun has a value greater that + # current time, we should run again + [ $lastrun -le $now ] || lastrun=0 + status_freq "$i" expiry=$(($lastrun+$_RET)) find_script "$i" && path="$_RET" || path=/dev/null