From patchwork Mon Jun 20 19:41:36 2005 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ville_Skytt=C3=A4?= X-Patchwork-Id: 11921 Received: from smtp1.pp.htv.fi ([213.243.153.37]) by www.linuxtv.org with esmtp (Exim 4.34) id 1DkS9J-0002v1-IQ for vdr@linuxtv.org; Mon, 20 Jun 2005 21:41:37 +0200 Received: from cs78131082.pp.htv.fi (cs78131082.pp.htv.fi [62.78.131.82]) by smtp1.pp.htv.fi (Postfix) with ESMTP id 6DDF97FCC0; Mon, 20 Jun 2005 22:41:36 +0300 (EEST) Subject: Re: [vdr] 1.3.27 with NPTL: (wapd) always crashes at shutdown From: Ville =?ISO-8859-1?Q?Skytt=E4?= To: Klaus Schmidinger's VDR In-Reply-To: <42B6C8D7.707@gmx.de> References: <1119202079.28867.22.camel@bobcat.mine.nu> <20050619174953.GA9770@defiant.wachendorf.lan> <1119248381.28867.39.camel@bobcat.mine.nu> <42B6C8D7.707@gmx.de> Date: Mon, 20 Jun 2005 22:41:36 +0300 Message-Id: <1119296496.28867.74.camel@bobcat.mine.nu> Mime-Version: 1.0 X-Mailer: Evolution 2.2.2 (2.2.2-5) X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Klaus Schmidinger's VDR List-Id: Klaus Schmidinger's VDR List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jun 2005 19:41:37 -0000 Status: O X-Status: X-Keywords: X-UID: 3159 On Mon, 2005-06-20 at 15:47 +0200, Udo Richter wrote: > Ville Skyttä wrote: > > The culprit seems to be cWapServer::Action() in server.c, which I tried > > to convert to use cCondWait::SleepMs() instead of usleep(), and added an > > "active" boolean into the class that would control the while loop in > > Action() and that would be set to false in the destructor, but those > > changes did not help. > > (without taking any close look at the source code) > I assume this is a main while loop in a cThread. Stopping a thread from > within the destructor is quite risky, as the object is already partially > destructed, and if you dont explicitly wait for the thread to finish, > the object may be gone before the thread ends. > > The best way is to stop the thread before the object gets destroyed, > using some thread.Stop(). The right place for stopping threads is in > cPlugin::Stop(). Okay, I think I may have got it, thanks. The attached patch seems to fix the crash here. Dunno if the usleep changes were actually necessary but since I already had them available... diff -ru wapd-0.7a.orig/server.c wapd-0.7a/server.c --- wapd-0.7a.orig/server.c 2005-01-25 22:32:24.000000000 +0200 +++ wapd-0.7a/server.c 2005-06-20 21:50:45.000000000 +0300 @@ -86,7 +86,7 @@ cWapServer::~cWapServer() { - Cancel(0); + Cancel(3); free(buffer); } @@ -1169,11 +1169,21 @@ return false; } +void cWapServer::Shutdown(void) +{ + active = false; +} + void cWapServer::Action(void) { - usleep(5000000); //initial delay + active = true; +#if VDRVERSNUM >= 10313 + cCondWait::SleepMs(5000); +#else + usleep(5000000); +#endif dsyslog("WAPD: finished initial delay"); - while (1) { + while (active) { if (file.Open(socket.Accept())) { if (ProcessHeader()) { if (*authorization == 0 || !WapAccess.Acceptable(authorization)) @@ -1217,7 +1227,11 @@ } file.Close(); } +#if VDRVERSNUM >= 10313 + cCondWait::SleepMs(10); +#else usleep(10000); +#endif } } diff -ru wapd-0.7a.orig/server.h wapd-0.7a/server.h --- wapd-0.7a.orig/server.h 2005-01-24 18:13:35.000000000 +0200 +++ wapd-0.7a/server.h 2005-06-20 21:53:51.000000000 +0300 @@ -20,9 +20,12 @@ #define WMLBUFFER 3*MAXPARSEBUFFER class cWapServer : cThread { + friend class cPluginWapd; + private: enum eMethod { mUnknown, mGet, mPost }; + bool active; cWapSocket socket; cFile file; cRecordings Recordings; @@ -68,6 +71,9 @@ void PageLanguage(void); void PageMain(void); +protected: + void Shutdown(void); + public: cWapServer(int Port); ~cWapServer(); diff -ru wapd-0.7a.orig/wapd.c wapd-0.7a/wapd.c --- wapd-0.7a.orig/wapd.c 2005-01-25 22:26:04.000000000 +0200 +++ wapd-0.7a/wapd.c 2005-06-20 21:53:06.000000000 +0300 @@ -22,6 +22,8 @@ // Add any member variables or functions you may need here. cWapServer *server; int tcpport; +protected: + virtual void Stop(void); public: cPluginWapd(void); virtual ~cPluginWapd(); @@ -97,4 +99,10 @@ return false; } +void cPluginWapd::Stop(void) +{ + if (server) + server->Shutdown(); +} + VDRPLUGINCREATOR(cPluginWapd); // Don't touch this!