@@ -14,6 +14,7 @@
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/wait.h>
+#include <signal.h>
#include <unistd.h>
#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);
}
@@ -167,5 +167,6 @@
// descriptors in the child process.
int SystemExec(const char *Command);
+void KillProcess(int Pid, int TimeoutMs = 0);
#endif //__THREAD_H
@@ -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();