From ca482527634fd901c49c700d8273734a8bae05b6 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 21 Jul 2011 08:51:03 -0400 Subject: [PATCH] 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