external: prevent a child process from killing a process on cleanup

This commit is contained in:
Simon Fels 2017-05-02 07:21:47 +02:00
commit bcdbdbac6a
2 changed files with 14 additions and 1 deletions

View file

@ -114,6 +114,12 @@ public:
*/
wait::Result wait_for(const wait::Flags& flags);
/**
* @brief Mark the child process to not to be killed when the ChildProcess
* instance goes away.
*/
void dont_kill_on_cleanup();
#ifndef ANDROID
/**
* @brief Access this process's stderr.

View file

@ -303,7 +303,7 @@ struct ChildProcess::Private
~Private()
{
// Check if we are in the original parent process.
if (original_parent_pid == getpid())
if (original_parent_pid == getpid() && !dont_kill_on_cleanup)
{
// If so, check if we are considering a valid pid here.
// If so, we kill the original child.
@ -333,6 +333,8 @@ struct ChildProcess::Private
// is called from the child process.
pid_t original_parent_pid;
pid_t original_child_pid;
bool dont_kill_on_cleanup = false;
};
ChildProcess ChildProcess::invalid()
@ -395,6 +397,11 @@ wait::Result ChildProcess::wait_for(const wait::Flags& flags)
return result;
}
void ChildProcess::dont_kill_on_cleanup()
{
d->dont_kill_on_cleanup = true;
}
#ifndef ANDROID
std::istream& ChildProcess::cerr()
{