From patchwork Mon Sep 26 12:36:36 2005 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Volkenandt X-Patchwork-Id: 12041 Received: from mailout05.sul.t-online.com ([194.25.134.82]) by www.linuxtv.org with esmtp (Exim 4.50) id 1EJsAj-0002V5-7a for vdr@linuxtv.org; Mon, 26 Sep 2005 14:33:29 +0200 Received: from fwd30.aul.t-online.de by mailout05.sul.t-online.com with smtp id 1EJsAi-0003Z0-01; Mon, 26 Sep 2005 14:33:28 +0200 Received: from transwarp (SrncswZD8eyWjZ-tQIpe6VaD7c4EJo4M+JzE0JCJrWL+kzH80oWoYS@[80.142.64.185]) by fwd30.sul.t-online.de with esmtp id 1EJsAD-1SiULo0; Mon, 26 Sep 2005 14:32:57 +0200 From: Sascha Volkenandt To: Klaus Schmidinger's VDR Date: Mon, 26 Sep 2005 14:36:36 +0200 User-Agent: KMail/1.8 MIME-Version: 1.0 Message-Id: <200509261436.37129.lists@magoa.net> X-ID: SrncswZD8eyWjZ-tQIpe6VaD7c4EJo4M+JzE0JCJrWL+kzH80oWoYS@t-dialin.net X-TOI-MSGID: ae1af917-f5a4-4df9-ad32-288f76670cf3 Subject: [vdr] Patch #1: Kill process before opening Devices X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: sascha@akv-soft.de, 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, 26 Sep 2005 12:33:29 -0000 Status: O X-Status: X-Keywords: X-UID: 5143 Hi list, I'll be releasing this and a few other patches for VDR 1.3.33, which have evolved during the last months while working on XeatreOS (a distribution based on LinVDR 0.7, which is used for the Xeatre boxes, http://www.xeatre.tv/). Some of their functionality may already be included in plugins or other patches. Nevertheless, I'd like to release them now, and let everybody decide whether they are useful or not. This first one adds a commandline parameter '-k' to VDR. Using this, you can specify an arbitrary PID which will be killed just before VDR opens the DVB devices. This way the gap between a possible boot-up screen/movie and Live-TV gets shorter. Greetings, Sascha Volkenandt diff -Nru vdr-1.3.33.origt/thread.c vdr-1.3.33/thread.c --- vdr-1.3.33.origt/thread.c Sun Aug 14 13:15:42 2005 +++ vdr-1.3.33/thread.c Mon Sep 26 14:19:23 2005 @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "tools.h" @@ -499,5 +500,20 @@ } _exit(0); } +} + +// --- KillProcess ----------------------------------------------------------- + +void KillProcess(int Pid, int TimeoutMs) +{ + kill(Pid, SIGTERM); + while (TimeoutMs > 0) { + if (waitpid(Pid, NULL, WNOHANG) == Pid) + return; + cCondWait::SleepMs(10); + TimeoutMs -= 10; + } + kill(Pid, SIGKILL); + waitpid(Pid, NULL, 0); } diff -Nru vdr-1.3.33.origt/thread.h vdr-1.3.33/thread.h --- vdr-1.3.33.origt/thread.h Sun Aug 14 13:21:48 2005 +++ vdr-1.3.33/thread.h Mon Sep 26 14:19:23 2005 @@ -167,5 +167,6 @@ // descriptors in the child process. int SystemExec(const char *Command); +void KillProcess(int Pid, int TimeoutMs = 0); #endif //__THREAD_H diff -Nru vdr-1.3.33.origt/vdr.c vdr-1.3.33/vdr.c --- vdr-1.3.33.origt/vdr.c Sat Sep 24 15:27:26 2005 +++ vdr-1.3.33/vdr.c Mon Sep 26 14:20:02 2005 @@ -137,7 +137,8 @@ cPluginManager PluginManager(DEFAULTPLUGINDIR); int ExitCode = 0; - + int PidToKill = 0; + static struct option long_options[] = { { "audio", required_argument, NULL, 'a' }, { "config", required_argument, NULL, 'c' }, @@ -145,6 +146,7 @@ { "device", required_argument, NULL, 'D' }, { "epgfile", required_argument, NULL, 'E' }, { "help", no_argument, NULL, 'h' }, + { "kill", required_argument, NULL, 'k' }, { "lib", required_argument, NULL, 'L' }, { "lirc", optional_argument, NULL, 'l' | 0x100 }, { "log", required_argument, NULL, 'l' }, @@ -164,7 +166,7 @@ }; int c; - while ((c = getopt_long(argc, argv, "a:c:dD:E:hl:L:mp:P:r:s:t:v:Vw:", long_options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "a:c:dD:E:hk:l:L:mp:P:r:s:t:v:Vw:", long_options, NULL)) != -1) { switch (c) { case 'a': AudioCommand = optarg; break; @@ -185,6 +187,8 @@ break; case 'h': DisplayHelp = true; break; + case 'k': PidToKill = atoi(optarg); + break; case 'l': { char *p = strchr(optarg, '.'); if (p) @@ -291,6 +295,7 @@ " if FILE is a directory, the default EPG file will be\n" " created in that directory\n" " -h, --help print this help and exit\n" + " -k PID, --kill=PID kill a process before initializing plugins and DVB\n" " -l LEVEL, --log=LEVEL set log level (default: 3)\n" " 0 = no logging, 1 = errors only,\n" " 2 = errors and info, 3 = errors, info and debug\n" @@ -458,6 +463,11 @@ cSchedules::Read(); } + // Kill a process: + + if (PidToKill != 0) + KillProcess(PidToKill, 1000); + // DVB interfaces: cDvbDevice::Initialize();