diff options
author | Matthias Schwarzott <zzam@gentoo.org> | 2010-11-14 13:08:16 +0000 |
---|---|---|
committer | Matthias Schwarzott <zzam@gentoo.org> | 2010-11-14 13:08:16 +0000 |
commit | 1ae0824142ff13cd465057f4539bc636b0a74ed2 (patch) | |
tree | 146c551d8aabf89d8066ebfb382e3eded70419a4 /usr/share | |
parent | fixed syntax error (diff) | |
download | gentoo-vdr-scripts-1ae0824142ff13cd465057f4539bc636b0a74ed2.tar.gz gentoo-vdr-scripts-1ae0824142ff13cd465057f4539bc636b0a74ed2.tar.bz2 gentoo-vdr-scripts-1ae0824142ff13cd465057f4539bc636b0a74ed2.zip |
Improve error handling of reading files with timestamps.
svn path=/gentoo-vdr-scripts/trunk/; revision=670
Diffstat (limited to 'usr/share')
-rw-r--r-- | usr/share/vdr/bin/vdrshutdown-really.sh | 5 | ||||
-rw-r--r-- | usr/share/vdr/inc/functions.sh | 12 | ||||
-rw-r--r-- | usr/share/vdr/shutdown/pre-shutdown-99-periodic-thread.sh | 3 |
3 files changed, 14 insertions, 6 deletions
diff --git a/usr/share/vdr/bin/vdrshutdown-really.sh b/usr/share/vdr/bin/vdrshutdown-really.sh index 962f97c..87acbf6 100644 --- a/usr/share/vdr/bin/vdrshutdown-really.sh +++ b/usr/share/vdr/bin/vdrshutdown-really.sh @@ -135,10 +135,7 @@ init_forced_shutdown() { # detect if this could be a forced shutdown local shutdown_force_file=${shutdown_data_dir}/last-shutdown-abort - local LAST_SHUTDOWN_ABORT=0 - if [ -f "${shutdown_force_file}" ]; then - LAST_SHUTDOWN_ABORT=$(cat "${shutdown_force_file}") - fi + local LAST_SHUTDOWN_ABORT=$(read_int_from_file "${shutdown_force_file}") NOW=$(date +%s) local DISTANCE=$(($NOW-$LAST_SHUTDOWN_ABORT)) if [ "${DISTANCE}" -lt "${SHUTDOWN_FORCE_DETECT_INTERVALL:-60}" ]; then diff --git a/usr/share/vdr/inc/functions.sh b/usr/share/vdr/inc/functions.sh index 2289451..c37fafc 100644 --- a/usr/share/vdr/inc/functions.sh +++ b/usr/share/vdr/inc/functions.sh @@ -22,6 +22,18 @@ read_caps() [ -f "${capfile}" ] && . ${capfile} } +# read file containing just one integer value +# $1 filename to read +# returns read value on stdout if successfull, else returns 0 there +read_int_from_file() +{ + local fname="$1" value="0" + if [ -r "$fname" -a -s "$fname" ]; then + value="$(cat "$fname")" + fi + echo $(($value+0)) +} + if ! type yesno >/dev/null 2>&1; then yesno() diff --git a/usr/share/vdr/shutdown/pre-shutdown-99-periodic-thread.sh b/usr/share/vdr/shutdown/pre-shutdown-99-periodic-thread.sh index c20a5d8..5aa67f3 100644 --- a/usr/share/vdr/shutdown/pre-shutdown-99-periodic-thread.sh +++ b/usr/share/vdr/shutdown/pre-shutdown-99-periodic-thread.sh @@ -28,8 +28,7 @@ check_periodic_thread() local NOW=$(date +%s) local MINIMAL_THREAD_CALL_DELTA=$(( 3600*20 )) - local LAST_THREAD_END=0 - [ -f "${PERIODIC_THREAD_ENDTIME}" ] && LAST_THREAD_END=$(cat ${PERIODIC_THREAD_ENDTIME}) + local LAST_THREAD_END=$(read_int_from_file "${PERIODIC_THREAD_ENDTIME}") local DELTA=$(( $NOW-$LAST_THREAD_END )) |