From f7dd342f525a15209424ac41e5283775f633985e Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sat, 23 Oct 2004 15:17:03 +0200 Subject: [PATCH] Fixed missing cleanup at program exit in case there is a problem with a plugin --- CONTRIBUTORS | 4 ++++ HISTORY | 2 ++ vdr.c | 46 ++++++++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 9f4c201e..4e05f37c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1115,3 +1115,7 @@ Stefan Meyknecht Lucian Muresan for updating the Romanian language texts and the iso8859-2 fonts for making VDR actually use the iso8859-15 fonts + +Mattias Grönlund + for pointing out a missing cleanup at program exit in case there is a problem + with a plugin diff --git a/HISTORY b/HISTORY index cc42c3cd..557323c8 100644 --- a/HISTORY +++ b/HISTORY @@ -3057,3 +3057,5 @@ Video Disk Recorder Revision History - Updated Romanian language texts and the iso8859-2 fonts (thanks to Lucian Muresan). - Now actually using the iso8859-15 fonts (thanks to Lucian Muresan). - Some minor code cleanups (thanks to Prakash K. Cheemplavam). +- Fixed missing cleanup at program exit in case there is a problem with a plugin + (thanks to Mattias Grönlund for pointing this out). diff --git a/vdr.c b/vdr.c index 80f80f54..8ca7b5e6 100644 --- a/vdr.c +++ b/vdr.c @@ -22,7 +22,7 @@ * * The project's page is at http://www.cadsoft.de/vdr * - * $Id: vdr.c 1.188 2004/10/23 12:40:24 kls Exp $ + * $Id: vdr.c 1.189 2004/10/23 15:04:52 kls Exp $ */ #include @@ -64,6 +64,8 @@ #define MANUALSTART 600 // seconds the next timer must be in the future to assume manual start #define CHANNELSAVEDELTA 600 // seconds before saving channels.conf after automatic modifications +#define EXIT(v) { ExitCode = (v); goto Exit; } + static int Interrupted = 0; static void SignalHandler(int signum) @@ -122,6 +124,7 @@ int main(int argc, char *argv[]) const char *Terminal = NULL; const char *Shutdown = NULL; cPluginManager PluginManager(DEFAULTPLUGINDIR); + int ExitCode = 0; static struct option long_options[] = { { "audio", required_argument, NULL, 'a' }, @@ -347,7 +350,7 @@ int main(int argc, char *argv[]) // Load plugins: if (!PluginManager.LoadPlugins(true)) - return 2; + EXIT(2); // Configuration data: @@ -369,7 +372,7 @@ int main(int argc, char *argv[]) Keys.Load(AddDirectory(ConfigDirectory, "remote.conf")) && KeyMacros.Load(AddDirectory(ConfigDirectory, "keymacros.conf"), true) )) - return 2; + EXIT(2); cFont::SetCode(I18nCharSets()[Setup.OSDLanguage]); @@ -391,7 +394,7 @@ int main(int argc, char *argv[]) // Initialize plugins: if (!PluginManager.InitializePlugins()) - return 2; + EXIT(2); // Primary device: @@ -414,12 +417,12 @@ int main(int argc, char *argv[]) fprintf(stderr, "vdr: %s\n", msg); esyslog("ERROR: %s", msg); if (!cDevice::SetPrimaryDevice(1)) - return 2; + EXIT(2); if (!cDevice::PrimaryDevice()) { const char *msg = "no primary device found - giving up!"; fprintf(stderr, "vdr: %s\n", msg); esyslog("ERROR: %s", msg); - return 2; + EXIT(2); } } } @@ -431,7 +434,7 @@ int main(int argc, char *argv[]) // Start plugins: if (!PluginManager.StartPlugins()) - return 2; + EXIT(2); // Skins: @@ -487,18 +490,18 @@ int main(int argc, char *argv[]) // Main program loop: - cOsdObject *Menu = NULL; - cOsdObject *Temp = NULL; - int LastChannel = -1; - int LastTimerChannel = -1; - int PreviousChannel[2] = { 1, 1 }; - int PreviousChannelIndex = 0; - time_t LastChannelChanged = time(NULL); - time_t LastActivity = 0; - int MaxLatencyTime = 0; - bool ForceShutdown = false; - bool UserShutdown = false; - bool TimerInVpsMargin = false; + static cOsdObject *Menu = NULL; + static cOsdObject *Temp = NULL; + static int LastChannel = -1; + static int LastTimerChannel = -1; + static int PreviousChannel[2] = { 1, 1 }; + static int PreviousChannelIndex = 0; + static time_t LastChannelChanged = time(NULL); + static time_t LastActivity = 0; + static int MaxLatencyTime = 0; + static bool ForceShutdown = false; + static bool UserShutdown = false; + static bool TimerInVpsMargin = false; while (!Interrupted) { // Handle emergency exits: @@ -887,6 +890,9 @@ int main(int argc, char *argv[]) } if (Interrupted) isyslog("caught signal %d", Interrupted); + +Exit: + cRecordControls::Shutdown(); cCutter::Stop(); delete Menu; @@ -913,5 +919,5 @@ int main(int argc, char *argv[]) esyslog("emergency exit!"); return 1; } - return 0; + return ExitCode; }