* usr/bin/byobu-statusd, usr/lib/byobu/.shutil:

- avoid forks on the $(date) command
This commit is contained in:
Dustin Kirkland 2011-07-22 11:12:33 -05:00
commit 7024df42f3
3 changed files with 23 additions and 2 deletions

2
debian/changelog vendored
View file

@ -3,6 +3,8 @@ byobu (4.21) unreleased; urgency=low
[ Scott Moser ] [ Scott Moser ]
* usr/bin/byobu-ctrl-a: * usr/bin/byobu-ctrl-a:
- support taking an argument screen|emacs on the command line - support taking an argument screen|emacs on the command line
* usr/bin/byobu-statusd, usr/lib/byobu/.shutil:
- avoid forks on the $(date) command
-- Dustin Kirkland <kirkland@ubuntu.com> Wed, 20 Jul 2011 08:57:52 -0500 -- Dustin Kirkland <kirkland@ubuntu.com> Wed, 20 Jul 2011 08:57:52 -0500

View file

@ -38,7 +38,7 @@ while true; do
rm -f "$BYOBU_RUN_DIR/status"/* "$BYOBU_RUN_DIR/.last"/* rm -f "$BYOBU_RUN_DIR/status"/* "$BYOBU_RUN_DIR/.last"/*
exit 0 exit 0
fi fi
now=$(date +%s) getnow; now=${_RET}
# Re-source configuration, if changed since last run # 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 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" [ -r "$i" ] && [ "$i" -nt "$BYOBU_RUN_DIR/status" ] && . "$i"
@ -57,6 +57,11 @@ while true; do
continue continue
fi fi
[ -r "$last" ] && read lastrun < "$last" || lastrun=0 [ -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" status_freq "$i"
expiry=$(($lastrun+$_RET)) expiry=$(($lastrun+$_RET))
find_script "$i" && path="$_RET" || path=/dev/null find_script "$i" && path="$_RET" || path=/dev/null
@ -65,7 +70,7 @@ while true; do
if [ "$path" -nt "$last" ] || [ ! -e "$last" ]; then if [ "$path" -nt "$last" ] || [ ! -e "$last" ]; then
. "$path" . "$path"
fi fi
eval "__$i" > "$cache" "__$i" > "$cache"
echo "$now" > "$last" echo "$now" > "$last"
fi fi
done done

View file

@ -257,4 +257,18 @@ status_freq() {
esac 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 # vi: syntax=sh ts=4 noexpandtab