diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2007-02-25 10:56:29 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2007-02-25 10:56:29 +0100 |
commit | ddb7f335674d668af3dd06bd61a0853b3af60df0 (patch) | |
tree | 5d52ba7939f6aa0b18cc01f546ce5c82ae8d3b80 /thread.c | |
parent | 50b14be807e1d3002246f359de83a8a18a0e6008 (diff) | |
download | vdr-ddb7f335674d668af3dd06bd61a0853b3af60df0.tar.gz vdr-ddb7f335674d668af3dd06bd61a0853b3af60df0.tar.bz2 |
Rewrite of shutdown handling; implemented cPlugin::WakeupTime(); SIGHUP forces reload; cThread::EmergencyExit() replaced by ShutdownHandler.RequestEmergencyExit()
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 1.59 2007/01/07 14:44:22 kls Exp $ + * $Id: thread.c 1.60 2007/02/24 16:13:33 kls Exp $ */ #include "thread.h" @@ -200,7 +200,6 @@ void cMutex::Unlock(void) // --- cThread --------------------------------------------------------------- tThreadId cThread::mainThreadId = 0; -bool cThread::emergencyExitRequested = false; cThread::cThread(const char *Description) { @@ -320,14 +319,6 @@ void cThread::Cancel(int WaitSeconds) } } -bool cThread::EmergencyExit(bool Request) -{ - if (!Request) - return emergencyExitRequested; - esyslog("initiating emergency exit"); - return emergencyExitRequested = true; // yes, it's an assignment, not a comparison! -} - tThreadId cThread::ThreadId(void) { return syscall(__NR_gettid); @@ -505,7 +496,7 @@ int cPipe::Close(void) // --- SystemExec ------------------------------------------------------------ -int SystemExec(const char *Command) +int SystemExec(const char *Command, bool Detached) { pid_t pid; @@ -515,14 +506,24 @@ int SystemExec(const char *Command) } if (pid > 0) { // parent process - int status; - if (waitpid(pid, &status, 0) < 0) { + int status = 0; + if (!Detached && waitpid(pid, &status, 0) < 0) { LOG_ERROR; return -1; } return status; } else { // child process + if (Detached) { + // Start a new session + pid_t sid = setsid(); + if (sid < 0) + LOG_ERROR; + // close STDIN and re-open as /dev/null + int devnull = open("/dev/null", O_RDONLY); + if (devnull < 0 || dup2(devnull, 0) < 0) + LOG_ERROR; + } int MaxPossibleFileDescriptors = getdtablesize(); for (int i = STDERR_FILENO + 1; i < MaxPossibleFileDescriptors; i++) close(i); //close all dup'ed filedescriptors |