Bug#451259: nvram-wakeup: vdr shutdown script calculates wrong regular wake-up time

Stefan Goetz debianbugs.5.nooneelse at spamgourmet.com
Wed Nov 14 15:32:38 UTC 2007


Package: nvram-wakeup
Version: 0.97-12
Severity: normal

The calculation of a regular wake-up time in /usr/share/vdr/shutdown-hooks/S90.nvram-wakeup is too simplistic and yields wake-up times too far ahead in the future potentially leading to missed recordings in VDR. The 
bug is triggered e.g. with REGULAR_TIME=08:00 and REGULAR_DAYS=1 when executed between 00:00 and 07:59, yielding a wake-up time at 08:00 the next day.

The following patch seems to fix this problem for me:

--- /tmp/S90.nvram-wakeup.org	2007-11-13 23:43:57.000000000 +0100
+++ /tmp/S90.nvram-wakeup.new	2007-11-13 23:43:12.000000000 +0100
@@ -43,8 +43,55 @@
 
 TIMER=$1
 
+# convert the time representation 'HH:MM' into seconds from midnight
+function hm2sec ()
+{
+	local HM=$1
+	# extract hours
+	local HOUR=${HM%:*}
+	# remove leading zero
+	HOUR=${HOUR#0}
+	# extract minutes
+	local MIN=${HM#*:}
+	# remove leading zero
+	MIN=${MIN#0}
+	if [ $HOUR -lt 0 ] || [ $HOUR -gt 23 ] || [ $MIN -lt 0 ] || [ $MIN -gt 59 ]; then
+		echo "Invalid input for hm2sec: $HM" >&2
+		return 2
+	else
+		echo $[ $HOUR * 3600 + $MIN * 60 ]
+	fi
+}
+
+# convert the local time zone into an offset in seconds
+function tz2sec ()
+{
+	local TZ=$(date +%z)
+	local TZHM=${TZ:1:2}:${TZ:3:2}
+	local SEC=$(hm2sec $TZHM)
+	local SIGN=${TZ:0:1}
+	[ $SIGN == '-' ] && SEC=$(( $SEC * -1 ))
+	echo $SEC
+}
+
 if [ $REGULAR_DAYS -gt 0 ]; then
-    REGULAR_TIMER=$((`date -d "$REGULAR_TIME" +%s` + $REGULAR_DAYS * 24 * 60 * 60))
+	# GMT epoch
+	NOW=$(date +%s)
+	# epoch offset by local TZ
+	TZNOW=$[ $NOW + `tz2sec` ]
+	# wake-up interval in seconds
+	STRIDE=$(($REGULAR_DAYS * 24 * 3600))
+	# rounddown (TZNOW, STRIDE) -> midnight of the most recent wake-up interval
+	INTERVAL_BASE=$((($TZNOW / $STRIDE) * $STRIDE))
+	# REGULAR_TIME configuration option in seconds: offset into each wake-up interval to match configured time of day
+	INTERVAL_OFFSET=`hm2sec $REGULAR_TIME`
+	# base + offset -> time to wake up at - due to the addition, this may lie in the past or the future
+	WAKEUP_TIME=$(($INTERVAL_BASE + $INTERVAL_OFFSET))
+	# convert wake-up time to GMT
+	WAKEUP_TIME=$(($WAKEUP_TIME - `tz2sec`))
+	# if in the past, this wake-up interval has truly expired and we need to wake up at the next one
+	[ $WAKEUP_TIME -lt $NOW ] && WAKEUP_TIME=$(($WAKEUP_TIME + $STRIDE))
+	REGULAR_TIMER=$WAKEUP_TIME
 
     # when no vdr timer is set or vdr timer starts later than regular timer:
     if [ $TIMER -eq 0 ] || [ $TIMER -gt 0 -a $REGULAR_TIMER -lt $TIMER ] ; then

-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.23.1
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

Versions of packages nvram-wakeup depends on:
ii  debconf [debconf-2.0]  1.5.11            Debian configuration management sy
ii  libc6                  2.3.6.ds1-13etch2 GNU C Library: Shared libraries
ii  makedev                2.3.1-83          creates device files in /dev

nvram-wakeup recommends no packages.

-- debconf information:
* nvram-wakeup/install_instruction:





More information about the pkg-vdr-dvb-devel mailing list