From patchwork Tue Jul 25 14:59:59 2006 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Udo Richter X-Patchwork-Id: 12365 Received: from mail.gmx.de ([213.165.64.21] helo=mail.gmx.net) by www.linuxtv.org with smtp (Exim 4.50) id 1G5OOd-0002wY-Mf for vdr@linuxtv.org; Tue, 25 Jul 2006 17:00:31 +0200 Received: (qmail invoked by alias); 25 Jul 2006 15:00:01 -0000 Received: from p548A4439.dip0.t-ipconnect.de (EHLO [192.168.73.1]) [84.138.68.57] by mail.gmx.net (mp018) with SMTP; 25 Jul 2006 17:00:01 +0200 X-Authenticated: #1417946 Message-ID: <44C631EF.4010204@gmx.de> Date: Tue, 25 Jul 2006 16:59:59 +0200 From: Udo Richter User-Agent: Thunderbird 2.0a1 (Windows/20060723) MIME-Version: 1.0 To: VDR Mailing List Subject: Re: [vdr] [vdr bug]Shutdown during an active timer is broken References: <20060725082546.DF6A0115951@dd3532.kasserver.com> <44C60C0C.5010801@gmx.de> In-Reply-To: <44C60C0C.5010801@gmx.de> X-Y-GMX-Trusted: 0 X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: VDR Mailing List List-Id: VDR Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jul 2006 15:00:31 -0000 Status: O X-Status: X-Keywords: X-UID: 10221 Hi list, Based on a first patch by Helmut Auer, here's a patch to solve the shutdown on running timers issue. I did some simple tests and it seemed to work, however the patch is still experimental. The patch basically disables the offending timers up to MinEventPause minutes in the future. There's also some endless loop detection that imho should be impossible to trigger. Some issues: - If you decide to cancel the shutdown after confirming it first, timers will remain disabled. Thats probably not what the user expects. - Disabling pending timers up to MinEventPause may not what the user expects either. I have set MinEventPause to 11 minutes (5 for shutdown, 5 for wakeup, 1 to avoid race conditions). But if an user has set this to 120 minutes for example, then the question "Recording in 100 minutes, shut down anyway?" doesn't sound like VDR wont wake up for it. - A clean implementation should merge both loops into one function and move the code into cTimers (API change!). (the two loops are required to skip negative values for "Recording in xx minutes") Cheers, Udo --- vdr-1.4.1-orig/vdr.c 2006-07-25 15:48:14.000000000 +0200 +++ vdr-1.4.1/vdr.c 2006-07-25 16:39:38.943900248 +0200 @@ -1007,6 +1007,27 @@ if (cRecordControls::Active()) { if (!Interface->Confirm(tr("Recording - shut down anyway?"))) break; + // Stop all running timers + time_t Now = time(NULL); + cTimer *timer = Timers.GetNextActiveTimer(); + time_t Next = timer ? timer->StartTime() : 0; + while (timer && Next - Now < 0) { + if (timer->IsSingleEvent()) + timer->ClrFlags(tfActive); + else + timer->Skip(); + timer->Matches(); + + cTimer *nextTimer = Timers.GetNextActiveTimer(); + time_t nextNext = nextTimer ? nextTimer->StartTime() : 0; + if (nextNext < Next || (nextNext == Next && nextTimer == timer)) { + esyslog("Loop detected while disabling running timers"); + break; + } + Next=nextNext; + timer=nextTimer; + } + Timers.SetModified(); } if (cPluginManager::Active(tr("shut down anyway?"))) break; @@ -1020,6 +1041,27 @@ free(buf); if (!confirm) break; + // Stop all pending timers until MinEventTimeout + time_t Now = time(NULL); + cTimer *timer = Timers.GetNextActiveTimer(); + time_t Next = timer ? timer->StartTime() : 0; + while (timer && Next - Now <= Setup.MinEventTimeout * 60) { + if (timer->IsSingleEvent()) + timer->ClrFlags(tfActive); + else + timer->Skip(); + timer->Matches(); + + cTimer *nextTimer = Timers.GetNextActiveTimer(); + time_t nextNext = nextTimer ? nextTimer->StartTime() : 0; + if (nextNext < Next || (nextNext == Next && nextTimer == timer)) { + esyslog("Loop detected while disabling pending timers"); + break; + } + Next=nextNext; + timer=nextTimer; + } + Timers.SetModified(); } ForceShutdown = true; break;