From: Andrew Ruthven Date: Thu, 22 Mar 2012 10:19:20 +0000 (+1300) Subject: Write out to our own tempfile, have more guards to make sure the files are what we... X-Git-Tag: debian-0.10.0-1~8 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3ede9c5ded93d3195b1d1faeafca50340bd9d5c;p=mythtv-status.git Write out to our own tempfile, have more guards to make sure the files are what we expect. This resolves an annoying race condition with update-motd which sometimes caused duplicated data in the MOTD. --- diff --git a/debian/init.d b/debian/init.d index e077a69..f7a083e 100644 --- a/debian/init.d +++ b/debian/init.d @@ -34,6 +34,7 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/bin/mythtv-status # Introduce the server's location here NAME=mythtv-status # Introduce the short server's name here DESC="MythTV Status" # Introduce a short description here +TEMPFILE=/var/run/motd.mythtv-status test -x $DAEMON || exit 0 @@ -62,12 +63,27 @@ case "$1" in [ -f /var/run/motd ] || touch /var/run/motd [ -f /var/run/motd.orig ] || cp /var/run/motd /var/run/motd.orig - cp /var/run/motd.orig /var/run/motd.new + 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 + fi + + cp /var/run/motd.orig $TEMPFILE ret=0 - $DAEMON $ARGS -h $HOST >> /var/run/motd.new 2> /dev/null || ret=$? + start=$(date) + $DAEMON $ARGS -h $HOST >> $TEMPFILE || ret=$? if [ $ret -eq 0 -o $ret -eq 1 ]; then - mv /var/run/motd.new /var/run/motd + 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 + else + mv $TEMPFILE /var/run/motd + fi log_end_msg 0 else log_failure_msg