mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-11 04:32:30 +00:00
Properly detach from background process.
This commit is contained in:
+17
-7
@@ -79,6 +79,23 @@ ExecFile::execute(const char* file, char* const* argv, int flags) {
|
||||
throw torrent::input_error("ExecFile::execute(...) Fork failed.");
|
||||
|
||||
if (childPid == 0) {
|
||||
if (flags & flag_background) {
|
||||
pid_t detached_pid = fork();
|
||||
|
||||
if (detached_pid == -1)
|
||||
_exit(-1);
|
||||
|
||||
if (detached_pid != 0) {
|
||||
if (m_logFd != -1)
|
||||
write(m_logFd, "\n--- Background task ---\n", sizeof("\n--- Background task ---\n"));
|
||||
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
m_logFd = -1;
|
||||
flags &= ~flag_capture;
|
||||
}
|
||||
|
||||
int devNull = open("/dev/null", O_RDWR);
|
||||
if (devNull != -1)
|
||||
dup2(devNull, 0);
|
||||
@@ -110,13 +127,6 @@ ExecFile::execute(const char* file, char* const* argv, int flags) {
|
||||
_exit(result);
|
||||
}
|
||||
|
||||
if (flags & flag_background) {
|
||||
if (m_logFd != -1)
|
||||
write(m_logFd, "\n--- Background task ---\n", sizeof("\n--- Background task ---\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We yield the global lock when waiting for the executed command to
|
||||
// finish so that XMLRPC and other threads can continue working.
|
||||
ThreadBase::release_global_lock();
|
||||
|
||||
Reference in New Issue
Block a user