From 625fe61185947db5a651f3bb708c94002d79040e Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Tue, 2 Oct 2012 21:39:29 +1300 Subject: [PATCH] Be a lot less verbose if their is a stale file, and potentially remove it. Close Debian bug #681684. --- debian/changelog | 6 ++++++ debian/init.d | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/debian/changelog b/debian/changelog index 3857d7e..e21aa32 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +mythtv-status (0.10.2-2) unstable; urgency=low + + * Handle a stale temp file more gracefully (Closes: #681684) + + -- Andrew Ruthven Tue, 02 Oct 2012 21:48:01 +1300 + mythtv-status (0.10.2-1) unstable; urgency=low * New upstream release. (Closes: #680358) diff --git a/debian/init.d b/debian/init.d index f7a083e..61826bb 100644 --- a/debian/init.d +++ b/debian/init.d @@ -63,11 +63,15 @@ case "$1" in [ -f /var/run/motd ] || touch /var/run/motd [ -f /var/run/motd.orig ] || cp /var/run/motd /var/run/motd.orig + # If the tempfile is less than 15 minutes old, object, otherwise + # we'll assume that something went wrong and remove it. if [ -f $TEMPFILE ]; then - echo "Hey, $TEMPFILE already exists" 1>&2 - ls -l /var/run/motd* 1>&2 - ps -ef | grep mythtv-status 1>&2 - cat /var/run/motd.new 1>&2 + AGE=$(stat -c "%Z" $TEMPFILE); + if expr $AGE \> $(date +'%s') - 900 + then + log_warning_msg "I think another $NAME is running." + exit 1 + fi fi cp /var/run/motd.orig $TEMPFILE @@ -77,10 +81,8 @@ case "$1" in $DAEMON $ARGS -h $HOST >> $TEMPFILE || ret=$? if [ $ret -eq 0 -o $ret -eq 1 ]; then if [ ! -f $TEMPFILE ]; then - # My file has gone away. WTF?! Spit out some debugging. - echo "Odd, $TEMPFILE has gone away. Start: $date, End: $(date)" 1>&2 - ls -l /var/run/motd* 1>&2 - ps -ef | grep mythtv-status 1>&2 + log_failure_msg "My temporary file has gone away, failed." + exit 1 else mv $TEMPFILE /var/run/motd fi -- 2.30.2